[35302b] | 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
|
---|
[9eb71b3] | 24 | //#include "CodePatterns/MemDebug.hpp"
|
---|
[35302b] | 25 |
|
---|
| 26 | QSeisPlotPage::QSeisPlotPage(QString type, QWidget *parent) :
|
---|
[3b1798] | 27 | QWidget(parent),
|
---|
| 28 | plotType(type),
|
---|
| 29 | curveList(NULL),
|
---|
| 30 | plot (NULL),
|
---|
| 31 | layoutInitialized(false)
|
---|
[35302b] | 32 | {
|
---|
| 33 | //create GUI elements
|
---|
[3b1798] | 34 | layout = new QHBoxLayout(this);
|
---|
[35302b] | 35 | setLayout(layout);
|
---|
| 36 |
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | QSeisPlotPage::~QSeisPlotPage()
|
---|
| 40 | {
|
---|
[1b6cec] | 41 | if (layoutInitialized)
|
---|
[3b1798] | 42 | deinitializeLayout();
|
---|
| 43 | }
|
---|
[35302b] | 44 |
|
---|
[3b1798] | 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 | {
|
---|
[50246c] | 59 | if (curveList != NULL) {
|
---|
[3b1798] | 60 | disconnect(curveList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(listItemChanged(QListWidgetItem*)));
|
---|
| 61 | layout->removeWidget(curveList);
|
---|
[50246c] | 62 | }
|
---|
| 63 | layout->removeWidget(plot);
|
---|
| 64 | delete curveList;
|
---|
| 65 | delete plot;
|
---|
| 66 | layoutInitialized = false;
|
---|
[35302b] | 67 | }
|
---|
| 68 |
|
---|
| 69 | std::string QSeisPlotPage::getName()
|
---|
| 70 | {
|
---|
| 71 | return plotType.toStdString();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void QSeisPlotPage::resetPlot()
|
---|
| 75 | {
|
---|
| 76 | plot->resetPlot();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void QSeisPlotPage::addCurve(std::string name)
|
---|
| 80 | {
|
---|
[3b1798] | 81 | if (!layoutInitialized)
|
---|
| 82 | initializeLayout();
|
---|
| 83 |
|
---|
[a2a2f7] | 84 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
| 85 | QListWidgetCurveItem *item = new QListWidgetCurveItem();
|
---|
[35302b] | 86 | item->curveName = curve->getName();
|
---|
| 87 | item->setText(curve->getDisplayName());
|
---|
| 88 |
|
---|
| 89 | if (curve->plot() != NULL)
|
---|
| 90 | item->setCheckState(Qt::Checked);
|
---|
| 91 | else
|
---|
| 92 | item->setCheckState(Qt::Unchecked);
|
---|
| 93 |
|
---|
| 94 | curveList->addItem((QListWidgetItem *)item);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void QSeisPlotPage::updateCurve(std::string name)
|
---|
| 98 | {
|
---|
[a2a2f7] | 99 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
[35302b] | 100 | if (curve->plot() != NULL)
|
---|
| 101 | curve->plot()->replot();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | void QSeisPlotPage::removeCurve(std::string name)
|
---|
| 105 | {
|
---|
[a2a2f7] | 106 | // QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(name);
|
---|
[35302b] | 107 |
|
---|
| 108 | for (int i = 0; i < curveList->count(); i++)
|
---|
| 109 | {
|
---|
[a2a2f7] | 110 | QListWidgetCurveItem *item = (QListWidgetCurveItem *)curveList->item(i);
|
---|
[35302b] | 111 | if (item->curveName == name)
|
---|
| 112 | {
|
---|
| 113 | curveList->takeItem(i);
|
---|
| 114 | delete item;
|
---|
| 115 | return;
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
[3b1798] | 118 |
|
---|
| 119 | if (curveList->count() == 0)
|
---|
| 120 | deinitializeLayout();
|
---|
[35302b] | 121 | }
|
---|
| 122 |
|
---|
| 123 | void QSeisPlotPage::listItemChanged(QListWidgetItem *item)
|
---|
| 124 | {
|
---|
| 125 | QListWidgetCurveItem *curveItem = (QListWidgetCurveItem *)item;
|
---|
[a2a2f7] | 126 | QSeisPlotCurve *curve = QSeisCurveRegistry::getInstance().getByName(curveItem->curveName);
|
---|
[35302b] | 127 |
|
---|
| 128 | if (curveItem->checkState() == Qt::Unchecked)
|
---|
| 129 | {
|
---|
| 130 | if (curve->plot() != NULL)
|
---|
| 131 | {
|
---|
| 132 | curve->detach();
|
---|
| 133 | //be carefull - changing the text color triggers this slot!
|
---|
| 134 | curveItem->setTextColor(QColor(Qt::black));
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | else if (curveItem->checkState() == Qt::Checked)
|
---|
| 138 | {
|
---|
| 139 | if (curve->plot() == NULL)
|
---|
| 140 | {
|
---|
| 141 | curve->attach(plot);
|
---|
| 142 | //be carefull - changing the text color triggers this slot!
|
---|
| 143 | curveItem->setTextColor(curve->pen().color());
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | plot->replot();
|
---|
| 148 | plot->resetZoomer();
|
---|
| 149 | }
|
---|