1 | /*
|
---|
2 | * QSeisPlotPage.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 30, 2011
|
---|
5 | * Author: landvogt
|
---|
6 | */
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include <QtGui/QHBoxLayout>
|
---|
14 | #include <QtGui/QListView>
|
---|
15 | #include <QtGui/QListWidgetItem>
|
---|
16 |
|
---|
17 | #include "UIElements/Views/Qt4/Plotting/QSeisPlotPage.hpp"
|
---|
18 | #include "UIElements/Views/Qt4/Plotting/QSeisPlot.hpp"
|
---|
19 | #include "UIElements/Views/Qt4/Plotting/QListWidgetCurveItem.hpp"
|
---|
20 | #include "UIElements/Views/Qt4/Plotting/QSeisPlotCurve.hpp"
|
---|
21 | #include "UIElements/Views/Qt4/Plotting/QSeisCurveRegistry.hpp"
|
---|
22 |
|
---|
23 | // have this after(!) all Qt includes
|
---|
24 | #include "CodePatterns/MemDebug.hpp"
|
---|
25 |
|
---|
26 | QSeisPlotPage::QSeisPlotPage(QString type, QWidget *parent) :
|
---|
27 | QWidget(parent),
|
---|
28 | plotType(type),
|
---|
29 | curveList(NULL),
|
---|
30 | plot (NULL),
|
---|
31 | layoutInitialized(false)
|
---|
32 | {
|
---|
33 | //create GUI elements
|
---|
34 | layout = new QHBoxLayout(this);
|
---|
35 | setLayout(layout);
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | QSeisPlotPage::~QSeisPlotPage()
|
---|
40 | {
|
---|
41 | if (layoutInitialized)
|
---|
42 | deinitializeLayout();
|
---|
43 | }
|
---|
44 |
|
---|
45 | void QSeisPlotPage::initializeLayout()
|
---|
46 | {
|
---|
47 | curveList = new QListWidget(this);
|
---|
48 | curveList->setMaximumWidth(250);
|
---|
49 | connect(curveList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(listItemChanged(QListWidgetItem*)));
|
---|
50 | plot = new QSeisPlot(this,plotType);
|
---|
51 | plot->setMinimumHeight(10);
|
---|
52 | layout->addWidget(curveList);
|
---|
53 | layout->addWidget(plot);
|
---|
54 | layoutInitialized = true;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void QSeisPlotPage::deinitializeLayout()
|
---|
58 | {
|
---|
59 | disconnect(curveList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(listItemChanged(QListWidgetItem*)));
|
---|
60 | layout->removeWidget(curveList);
|
---|
61 | layout->removeWidget(plot);
|
---|
62 | delete curveList;
|
---|
63 | delete plot;
|
---|
64 | layoutInitialized = false;
|
---|
65 | }
|
---|
66 |
|
---|
67 | std::string QSeisPlotPage::getName()
|
---|
68 | {
|
---|
69 | return plotType.toStdString();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void QSeisPlotPage::resetPlot()
|
---|
73 | {
|
---|
74 | plot->resetPlot();
|
---|
75 | }
|
---|
76 |
|
---|
77 | void QSeisPlotPage::addCurve(std::string name)
|
---|
78 | {
|
---|
79 | if (!layoutInitialized)
|
---|
80 | initializeLayout();
|
---|
81 |
|
---|
82 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
83 | QListWidgetCurveItem *item = new QListWidgetCurveItem();
|
---|
84 | item->curveName = curve->getName();
|
---|
85 | item->setText(curve->getDisplayName());
|
---|
86 |
|
---|
87 | if (curve->plot() != NULL)
|
---|
88 | item->setCheckState(Qt::Checked);
|
---|
89 | else
|
---|
90 | item->setCheckState(Qt::Unchecked);
|
---|
91 |
|
---|
92 | curveList->addItem((QListWidgetItem *)item);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void QSeisPlotPage::updateCurve(std::string name)
|
---|
96 | {
|
---|
97 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
98 | if (curve->plot() != NULL)
|
---|
99 | curve->plot()->replot();
|
---|
100 | }
|
---|
101 |
|
---|
102 | void QSeisPlotPage::removeCurve(std::string name)
|
---|
103 | {
|
---|
104 | // QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
105 |
|
---|
106 | for (int i = 0; i < curveList->count(); i++)
|
---|
107 | {
|
---|
108 | QListWidgetCurveItem *item = (QListWidgetCurveItem *)curveList->item(i);
|
---|
109 | if (item->curveName == name)
|
---|
110 | {
|
---|
111 | curveList->takeItem(i);
|
---|
112 | delete item;
|
---|
113 | return;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (curveList->count() == 0)
|
---|
118 | deinitializeLayout();
|
---|
119 | }
|
---|
120 |
|
---|
121 | void QSeisPlotPage::listItemChanged(QListWidgetItem *item)
|
---|
122 | {
|
---|
123 | QListWidgetCurveItem *curveItem = (QListWidgetCurveItem *)item;
|
---|
124 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(curveItem->curveName);
|
---|
125 |
|
---|
126 | if (curveItem->checkState() == Qt::Unchecked)
|
---|
127 | {
|
---|
128 | if (curve->plot() != NULL)
|
---|
129 | {
|
---|
130 | curve->detach();
|
---|
131 | //be carefull - changing the text color triggers this slot!
|
---|
132 | curveItem->setTextColor(QColor(Qt::black));
|
---|
133 | }
|
---|
134 | }
|
---|
135 | else if (curveItem->checkState() == Qt::Checked)
|
---|
136 | {
|
---|
137 | if (curve->plot() == NULL)
|
---|
138 | {
|
---|
139 | curve->attach(plot);
|
---|
140 | //be carefull - changing the text color triggers this slot!
|
---|
141 | curveItem->setTextColor(curve->pen().color());
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | plot->replot();
|
---|
146 | plot->resetZoomer();
|
---|
147 | }
|
---|