| [35302b] | 1 | /*
|
|---|
| 2 | * QSeisPlot.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 "UIElements/Views/Qt4/Plotting/QSeisPlot.hpp"
|
|---|
| 14 | #include "UIElements/Views/Qt4/Plotting/XMLParser/QSeisXMLParser.hpp"
|
|---|
| 15 | #include "UIElements/Views/Qt4/Plotting/XMLParser/QSeisXMLParser_plottype.hpp"
|
|---|
| 16 |
|
|---|
| 17 | #include <iostream>
|
|---|
| 18 | #include <qwt_plot_marker.h>
|
|---|
| 19 |
|
|---|
| 20 | // have this after(!) all Qt includes
|
|---|
| 21 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 22 |
|
|---|
| 23 | QSeisPlot::QSeisPlot(QWidget *parent,QString type) : QwtPlot(parent)
|
|---|
| 24 | {
|
|---|
| 25 | //no title as there are already the different tabs
|
|---|
| 26 | setTitle("");
|
|---|
| 27 | //display legend on the right hand side
|
|---|
| 28 | //no legend displayed - list names are colored instead
|
|---|
| 29 | //insertLegend(new QwtLegend(), QwtPlot::RightLegend);
|
|---|
| 30 |
|
|---|
| 31 | plottype* tmp = QSeisXMLParser::getInstance().return_plottype_by_name(type.toStdString());
|
|---|
| 32 | ASSERT(tmp != NULL,
|
|---|
| 33 | "QSeisPlot::QSeisPlot() - could not find desired plottype by name "+type.toStdString()+".");
|
|---|
| 34 | std::cout << "Type is " << type.toStdString() << ", " << tmp << std::endl;
|
|---|
| 35 |
|
|---|
| 36 | //label axes
|
|---|
| 37 | const std::string xlabel = tmp->get_label(plottype::X);
|
|---|
| 38 | const std::string ylabel = tmp->get_label(plottype::Y);
|
|---|
| 39 | const std::string xunits = tmp->get_units(plottype::X);
|
|---|
| 40 | const std::string yunits = tmp->get_units(plottype::Y);
|
|---|
| 41 | setAxisTitle(xBottom, (xlabel+std::string(" [")+xunits+std::string("]")).c_str());
|
|---|
| 42 | setAxisTitle(yLeft, (ylabel+std::string(" [")+yunits+std::string("]")).c_str());
|
|---|
| 43 |
|
|---|
| 44 | //add zero line
|
|---|
| 45 | QwtPlotMarker *zeroLine = new QwtPlotMarker();
|
|---|
| 46 | zeroLine->setLineStyle(QwtPlotMarker::HLine);
|
|---|
| 47 | zeroLine->setYValue(0.0);
|
|---|
| 48 | zeroLine->attach(this);
|
|---|
| 49 |
|
|---|
| 50 | zoomer = new ScrollZoomer(canvas());
|
|---|
| 51 |
|
|---|
| 52 | #ifdef QWTPANNER
|
|---|
| 53 | panner = new QwtPlotPanner(canvas());
|
|---|
| 54 | panner->setMouseButton(Qt::MidButton);
|
|---|
| 55 | #else
|
|---|
| 56 | panning = false;
|
|---|
| 57 | startPan = QPointF(0.0f, 0.0f);
|
|---|
| 58 | #endif
|
|---|
| 59 |
|
|---|
| 60 | //init colors
|
|---|
| 61 | availableColors.append(QColor(Qt::darkYellow));
|
|---|
| 62 | availableColors.append(QColor(Qt::darkMagenta));
|
|---|
| 63 | availableColors.append(QColor(Qt::darkCyan));
|
|---|
| 64 | availableColors.append(QColor(Qt::darkGreen));
|
|---|
| 65 | availableColors.append(QColor(Qt::darkRed));
|
|---|
| 66 | availableColors.append(QColor(Qt::yellow));
|
|---|
| 67 | availableColors.append(QColor(Qt::magenta));
|
|---|
| 68 | availableColors.append(QColor(Qt::cyan));
|
|---|
| 69 | availableColors.append(QColor(Qt::green));
|
|---|
| 70 | availableColors.append(QColor(Qt::red));
|
|---|
| 71 | availableColors.append(QColor(Qt::blue));
|
|---|
| 72 | availableColors.append(QColor(Qt::black));
|
|---|
| 73 |
|
|---|
| 74 | color_map.insert(std::make_pair("black",QColor(Qt::black)));
|
|---|
| 75 | color_map.insert(std::make_pair("red",QColor(Qt::red)));
|
|---|
| 76 | color_map.insert(std::make_pair("blue",QColor(Qt::blue)));
|
|---|
| 77 | color_map.insert(std::make_pair("green",QColor(Qt::green)));
|
|---|
| 78 | color_map.insert(std::make_pair("cyan",QColor(Qt::cyan)));
|
|---|
| 79 | color_map.insert(std::make_pair("yellow",QColor(Qt::yellow)));
|
|---|
| 80 | color_map.insert(std::make_pair("magenta",QColor(Qt::magenta)));
|
|---|
| 81 | color_map.insert(std::make_pair("darkYellow",QColor(Qt::darkYellow)));
|
|---|
| 82 | color_map.insert(std::make_pair("darkMagenta",QColor(Qt::darkMagenta)));
|
|---|
| 83 | color_map.insert(std::make_pair("darkCyan",QColor(Qt::darkCyan)));
|
|---|
| 84 | color_map.insert(std::make_pair("darkGreen",QColor(Qt::darkGreen)));
|
|---|
| 85 | color_map.insert(std::make_pair("darkRed",QColor(Qt::darkRed)));
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | QSeisPlot::~QSeisPlot()
|
|---|
| 89 | {
|
|---|
| 90 |
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void QSeisPlot::loadSettingsFromXML(QString fileName)
|
|---|
| 94 | {
|
|---|
| 95 | //load settings from XML file sometime in the future
|
|---|
| 96 | qDebug("loadSettingsFromXML %s", fileName.toAscii().constData());
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void QSeisPlot::resetZoomer()
|
|---|
| 100 | {
|
|---|
| 101 | if (axisAutoScale(xBottom) && axisAutoScale(yLeft))
|
|---|
| 102 | zoomer->setZoomBase(0);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | #ifndef QWTPANNER
|
|---|
| 106 | void QSeisPlot::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 107 | {
|
|---|
| 108 | if ((event->buttons() == Qt::MidButton) && (panning))
|
|---|
| 109 | {
|
|---|
| 110 | double xPos = invTransform(xBottom, event->pos().x() - canvas()->pos().x());
|
|---|
| 111 | double yPos = invTransform(yLeft, event->pos().y() - canvas()->pos().y());
|
|---|
| 112 | zoomer->moveBy(xPos-startPan.x(), yPos-startPan.y());
|
|---|
| 113 | startPan = QPointF(xPos, yPos);
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | void QSeisPlot::mousePressEvent(QMouseEvent *event)
|
|---|
| 118 | {
|
|---|
| 119 | //start panning only above the plot canvas
|
|---|
| 120 | if ((event->button() == Qt::MidButton)
|
|---|
| 121 | && (event->pos().x() >= canvas()->pos().x())
|
|---|
| 122 | && (event->pos().x() <= (canvas()->pos().x() + canvas()->width()))
|
|---|
| 123 | && (event->pos().y() >= canvas()->pos().y())
|
|---|
| 124 | && (event->pos().y() <= (canvas()->pos().y() + canvas()->height())))
|
|---|
| 125 | {
|
|---|
| 126 | panning = true;
|
|---|
| 127 | startPan = QPointF(invTransform(xBottom, event->pos().x() - canvas()->pos().x()),
|
|---|
| 128 | invTransform(yLeft, event->pos().y() - canvas()->pos().y()));
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void QSeisPlot::mouseReleaseEvent(QMouseEvent *event)
|
|---|
| 133 | {
|
|---|
| 134 | if (event->button() == Qt::MidButton)
|
|---|
| 135 | {
|
|---|
| 136 | panning = false;
|
|---|
| 137 | startPan = QPointF(0.0f, 0.0f);
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 | #endif
|
|---|
| 141 |
|
|---|
| 142 | QColor QSeisPlot::getCurveColor(std::string curve_color)
|
|---|
| 143 | {
|
|---|
| 144 | if(color_map.count(curve_color)!=0) {
|
|---|
| 145 | if(availableColors.count(color_map[curve_color])!=0) {
|
|---|
| 146 | return color_map[curve_color];
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 | QColor retColor = QColor(Qt::black);
|
|---|
| 150 | if (!availableColors.isEmpty())
|
|---|
| 151 | {
|
|---|
| 152 | retColor = availableColors.last();
|
|---|
| 153 | availableColors.removeLast();
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | return retColor;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | void QSeisPlot::freeCurveColor(QColor color)
|
|---|
| 160 | {
|
|---|
| 161 | if (color != QColor(Qt::black) && (!availableColors.contains(color)))
|
|---|
| 162 | {
|
|---|
| 163 | availableColors.append(color);
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | void QSeisPlot::resetPlot()
|
|---|
| 168 | {
|
|---|
| 169 | setAxisAutoScale(QwtPlot::xBottom);
|
|---|
| 170 | setAxisAutoScale(QwtPlot::yLeft);
|
|---|
| 171 | replot();
|
|---|
| 172 | zoomer->setZoomBase(0);
|
|---|
| 173 | }
|
|---|