#ifndef CDGRAPHICS_H
#define CDGRAPHICS_H

#include <QWidget>
#include <QDockWidget>
#include <QMenu>
#include "ui_cdgraphics.h"
#include "qcd_graphic.h"
#include <pistring.h>

namespace CDUtils {
	class CDType;
	class CDSection;
	QStringList getList(const PIVector<PIDeque<int> > & x_list);
	PIVector<PIDeque<int> > setList(const QStringList & l);
}

class QMainWindow;
class Graphic;




class GDockWidget: public QDockWidget {
	Q_OBJECT
public:
	GDockWidget(QString title = QString(), QMainWindow * p = 0);

	void addX(const CDUtils::CDType & t);
	void drawX(const PIMap<PIString, PIVector<double> > & data);
	QByteArray save() const;
	void load(QByteArray ba);
	void changedGlobal();

	CDGraphicWidget * graphic;

private:
	bool eventFilter(QObject * o, QEvent * e);
	void contextMenuEvent(QContextMenuEvent * e);
	CDGraphicWidget * viewportGraphic(QObject * o) const;

	QMenu * menu, * menu_x;
	QList<QAction*> dactions;
	QMainWindow * da;
	PIVector<PIDeque<int> > x_list;

private slots:
	void rename();
	void removeX();

signals:
	void removeRequest();

};




class CDGraphics : public QWidget, public Ui::CDGraphics
{
	Q_OBJECT
public:
	explicit CDGraphics(QWidget *parent = 0);
	~CDGraphics();

	void reset();
	QByteArray save() const;
	void load(QByteArray ba);

private:
	GDockWidget * graphicDock(Graphic * o) const;
	void addXToGraphic(const QString & xp, Graphic * g);
	void addGraphic();

	QList<GDockWidget * > docks;
	QMainWindow * da;

public slots:
	void receivedX();
	void changedGlobal();

private slots:
	void removeGraphic();
	void on_buttonAdd_clicked();
	void on_buttonClear_clicked();
	void on_buttonRemoveAll_clicked();

signals:

};

#endif // CDGRAPHICS_H
