From 0e8972358a24c1acbaff0e0818e15d117c30d8a5 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Wed, 27 Aug 2014 01:05:59 +1000 Subject: [PATCH] Added Min/Max YAxis editor to Context menu --- sleepyhead/Graphs/gGraphView.cpp | 56 +++++++++++++++++++++++++++++++- sleepyhead/Graphs/gGraphView.h | 36 ++++++++++++++++++++ sleepyhead/mainwindow.ui | 13 +++----- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index cb5bda6c..2705bc53 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) # include @@ -357,6 +356,7 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared) context_menu->addAction(tr("Reset Graph Layout"), this, SLOT(resetLayout())); context_menu->addSeparator(); + limits_menu = context_menu->addMenu(tr("Graph Limits")); plots_menu = context_menu->addMenu(tr("Plots")); connect(plots_menu, SIGNAL(triggered(QAction*)), this, SLOT(onPlotsClicked(QAction*))); @@ -370,6 +370,7 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared) lines_menu = context_menu->addMenu(tr("Dotted Lines")); connect(lines_menu, SIGNAL(triggered(QAction*)), this, SLOT(onLinesClicked(QAction*))); + } void gGraphView::togglePin() @@ -1662,6 +1663,46 @@ protected: }; +MinMaxWidget::MinMaxWidget(gGraph * graph, QWidget *parent): QWidget(parent), graph(graph) +{ + + // setWindowFlags(windowFlags() | Qt::Popup); + createLayout(); +} + +void MinMaxWidget::onMinChanged(double d) +{ + graph->rec_miny = d; + graph->timedRedraw(0); +} +void MinMaxWidget::onMaxChanged(double d) +{ + graph->rec_maxy = d; + graph->timedRedraw(0); +} + +void MinMaxWidget::createLayout() +{ + QHBoxLayout *layout = new QHBoxLayout; + layout->setMargin(4); + layout->setSpacing(4); + checkbox = new QCheckBox(" ",this); + checkbox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); + minbox = new QDoubleSpinBox(this); + maxbox = new QDoubleSpinBox(this); + minbox->setMinimum(-99999.9); + maxbox->setMinimum(-99999.9); + minbox->setMaximum(99999.9); + maxbox->setMaximum(99999.9); + graph->graphView()->connect(minbox, SIGNAL(valueChanged(double)), this, SLOT(onMinChanged(double))); + graph->graphView()->connect(maxbox, SIGNAL(valueChanged(double)), this, SLOT(onMaxChanged(double))); + layout->addWidget(checkbox); + layout->addWidget(new QLabel(STR_TR_Min)); + layout->addWidget(minbox); + layout->addWidget(new QLabel(STR_TR_Max)); + layout->addWidget(maxbox); + this->setLayout(layout); +} void gGraphView::populateMenu(gGraph * graph) { @@ -1672,6 +1713,19 @@ void gGraphView::populateMenu(gGraph * graph) font.setBold(true); font.setPointSize(font.pointSize() + 3); + limits_menu->clear(); + QWidgetAction * widget = new QWidgetAction(this); + MinMaxWidget * minmax = new MinMaxWidget(graph, this); + + widget->setDefaultWidget(minmax); + + minmax->setMax(graph->rec_maxy); + minmax->setMin(graph->rec_miny); + minmax->setChecked(true); + + limits_menu->addAction(widget); + + // First check for any linechart for this graph.. gLineChart * lc = dynamic_cast(findLayer(graph,LT_LineChart)); if (lc) { diff --git a/sleepyhead/Graphs/gGraphView.h b/sleepyhead/Graphs/gGraphView.h index 2cd26034..3837bc3c 100644 --- a/sleepyhead/Graphs/gGraphView.h +++ b/sleepyhead/Graphs/gGraphView.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #ifndef BROKEN_OPENGL_BUILD #include @@ -28,6 +30,39 @@ #include #include + +class MinMaxWidget:public QWidget +{ + Q_OBJECT +public: + explicit MinMaxWidget(gGraph * graph, QWidget *parent); + ~MinMaxWidget() {} + + void createLayout(); + + void setMin(double d) { + minbox->setValue(d); + } + void setMax(double d) { + maxbox->setValue(d); + } + double min() { return minbox->value(); } + double max() { return maxbox->value(); } + + void setChecked(bool b) { checkbox->setChecked(b); } + bool checked() { return checkbox->isChecked(); } + +public slots: + void onMinChanged(double d); + void onMaxChanged(double d); + +protected: + gGraph * graph; + QCheckBox *checkbox; + QDoubleSpinBox *minbox; + QDoubleSpinBox *maxbox; +}; + enum FlagType { FT_Bar, FT_Dot, FT_Span }; @@ -441,6 +476,7 @@ class gGraphView Layer * findLayer(gGraph * graph, LayerType type); void populateMenu(gGraph *); + QMenu * limits_menu; QMenu * lines_menu; QMenu * plots_menu; diff --git a/sleepyhead/mainwindow.ui b/sleepyhead/mainwindow.ui index 26e301c8..1d007e91 100644 --- a/sleepyhead/mainwindow.ui +++ b/sleepyhead/mainwindow.ui @@ -1911,8 +1911,8 @@ border: 2px solid #56789a; border-radius: 30px; 0 0 - 100 - 30 + 180 + 700 @@ -3059,8 +3059,8 @@ border-radius: 10px; 0 0 - 100 - 30 + 180 + 700 @@ -3491,11 +3491,6 @@ border-radius: 10px; Ctrl+L - - - Foo - -