#include "pch.h"
#include "GraphViewSettingDialog.h"
#include <QListWidgetItem>
#include <QPushButton>
#include "GraphViewSettingItem.h"
#include <QScrollArea>



GraphViewSettingDialog::GraphViewSettingDialog(GraphView* view, QString title ,QWidget *parent)
	: QDialog(parent), view(view)
{
	ui.setupUi(this);
	setWindowTitle(title);
	this->graphVec = &view->graphSeriesVec;
	vecsize = graphVec->size();
	QWidget* toScroll = new QWidget(this);
	layout = new QVBoxLayout(this);
	layout->setContentsMargins(3, 0, 3, 0);
	toScroll->setLayout(layout);
	QVBoxLayout* myLayout = new QVBoxLayout(this);
	myLayout->setContentsMargins(0, 0, 0, 0);
	QScrollArea* scrollArea = new QScrollArea;
	scrollArea->setWidgetResizable(true);
	scrollArea->setWidget(toScroll);
	myLayout->addWidget(scrollArea);
	this->setLayout(myLayout);
}

GraphViewSettingDialog::~GraphViewSettingDialog()
{
}

void GraphViewSettingDialog::openDialog()
{
	//Generate Buttons;

	if (vecsize == graphVec->size()) {
		this->activateWindow();
		this->show();
		return;
	}
	else {
		vecsize = graphVec->size();
	}

	for (auto iter = graphVec->begin(); iter != graphVec->end(); iter++) {
		GraphViewSettingItem* handle = new GraphViewSettingItem(view, &*iter, this);
		layout->addWidget(handle);
	}
	this->show();
}

