| 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), plotType(type)
 | 
|---|
| 28 | {
 | 
|---|
| 29 |     //create GUI elements
 | 
|---|
| 30 |     QHBoxLayout *layout = new QHBoxLayout(this);
 | 
|---|
| 31 |     curveList = new QListWidget(this);
 | 
|---|
| 32 |     curveList->setMaximumWidth(250);
 | 
|---|
| 33 |     plot = new QSeisPlot(this,type);
 | 
|---|
| 34 |     layout->addWidget(curveList);
 | 
|---|
| 35 |     layout->addWidget(plot);
 | 
|---|
| 36 |     setLayout(layout);
 | 
|---|
| 37 | 
 | 
|---|
| 38 |     connect(curveList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(listItemChanged(QListWidgetItem*)));
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | QSeisPlotPage::~QSeisPlotPage()
 | 
|---|
| 42 | {
 | 
|---|
| 43 | 
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | std::string QSeisPlotPage::getName()
 | 
|---|
| 47 | {
 | 
|---|
| 48 |     return plotType.toStdString();
 | 
|---|
| 49 | }
 | 
|---|
| 50 | 
 | 
|---|
| 51 | void QSeisPlotPage::resetPlot()
 | 
|---|
| 52 | {
 | 
|---|
| 53 |     plot->resetPlot();
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | void QSeisPlotPage::addCurve(std::string name)
 | 
|---|
| 57 | {
 | 
|---|
| 58 |     QSeisPlotCurve *curve;
 | 
|---|
| 59 |     QListWidgetCurveItem *item;
 | 
|---|
| 60 |     curve = QSeisCurveRegistry::getInstance().getByName(name);
 | 
|---|
| 61 | 
 | 
|---|
| 62 |     item = new QListWidgetCurveItem();
 | 
|---|
| 63 |     item->curveName = curve->getName();
 | 
|---|
| 64 |     item->setText(curve->getDisplayName());
 | 
|---|
| 65 | 
 | 
|---|
| 66 |     if (curve->plot() != NULL)
 | 
|---|
| 67 |         item->setCheckState(Qt::Checked);
 | 
|---|
| 68 |     else
 | 
|---|
| 69 |         item->setCheckState(Qt::Unchecked);
 | 
|---|
| 70 | 
 | 
|---|
| 71 |     curveList->addItem((QListWidgetItem *)item);
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | void QSeisPlotPage::updateCurve(std::string name)
 | 
|---|
| 75 | {
 | 
|---|
| 76 |     QSeisPlotCurve *curve;
 | 
|---|
| 77 |     curve = QSeisCurveRegistry::getInstance().getByName(name);
 | 
|---|
| 78 |     if (curve->plot() != NULL)
 | 
|---|
| 79 |         curve->plot()->replot();
 | 
|---|
| 80 | }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | void QSeisPlotPage::removeCurve(std::string name)
 | 
|---|
| 83 | {
 | 
|---|
| 84 |     QSeisPlotCurve *curve;
 | 
|---|
| 85 |     QListWidgetCurveItem *item;
 | 
|---|
| 86 |     curve = QSeisCurveRegistry::getInstance().getByName(name);
 | 
|---|
| 87 | 
 | 
|---|
| 88 |     for (int i = 0; i < curveList->count(); i++)
 | 
|---|
| 89 |     {
 | 
|---|
| 90 |         item = (QListWidgetCurveItem *)curveList->item(i);
 | 
|---|
| 91 |         if (item->curveName == name)
 | 
|---|
| 92 |         {
 | 
|---|
| 93 |             curveList->takeItem(i);
 | 
|---|
| 94 |             delete item;
 | 
|---|
| 95 |             return;
 | 
|---|
| 96 |         }
 | 
|---|
| 97 |     }
 | 
|---|
| 98 | }
 | 
|---|
| 99 | 
 | 
|---|
| 100 | void QSeisPlotPage::listItemChanged(QListWidgetItem *item)
 | 
|---|
| 101 | {
 | 
|---|
| 102 |     QListWidgetCurveItem *curveItem = (QListWidgetCurveItem *)item;
 | 
|---|
| 103 |     QSeisPlotCurve *curve;
 | 
|---|
| 104 |     curve = QSeisCurveRegistry::getInstance().getByName(curveItem->curveName);
 | 
|---|
| 105 | 
 | 
|---|
| 106 |     if (curveItem->checkState() == Qt::Unchecked)
 | 
|---|
| 107 |     {
 | 
|---|
| 108 |         if (curve->plot() != NULL)
 | 
|---|
| 109 |         {
 | 
|---|
| 110 |             curve->detach();
 | 
|---|
| 111 |             //be carefull - changing the text color triggers this slot!
 | 
|---|
| 112 |             curveItem->setTextColor(QColor(Qt::black));
 | 
|---|
| 113 |         }
 | 
|---|
| 114 |     }
 | 
|---|
| 115 |     else if (curveItem->checkState() == Qt::Checked)
 | 
|---|
| 116 |     {
 | 
|---|
| 117 |         if (curve->plot() == NULL)
 | 
|---|
| 118 |         {
 | 
|---|
| 119 |             curve->attach(plot);
 | 
|---|
| 120 |             //be carefull - changing the text color triggers this slot!
 | 
|---|
| 121 |             curveItem->setTextColor(curve->pen().color());
 | 
|---|
| 122 |         }
 | 
|---|
| 123 |     }
 | 
|---|
| 124 | 
 | 
|---|
| 125 |     plot->replot();
 | 
|---|
| 126 |     plot->resetZoomer();
 | 
|---|
| 127 | }
 | 
|---|