Added Min/Max YAxis editor to Context menu

This commit is contained in:
Mark Watkins 2014-08-27 01:05:59 +10:00
parent 514d88c68a
commit 0e8972358a
3 changed files with 95 additions and 10 deletions

View File

@ -15,7 +15,6 @@
#include <QTimer>
#include <QFontMetrics>
#include <QWidgetAction>
#include <QCheckBox>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QWindow>
@ -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<gLineChart *>(findLayer(graph,LT_LineChart));
if (lc) {

View File

@ -19,6 +19,8 @@
#include <QRect>
#include <QPixmapCache>
#include <QMenu>
#include <QCheckBox>
#include <QDoubleSpinBox>
#ifndef BROKEN_OPENGL_BUILD
#include <QGLWidget>
@ -28,6 +30,39 @@
#include <Graphs/glcommon.h>
#include <SleepLib/day.h>
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;

View File

@ -1911,8 +1911,8 @@ border: 2px solid #56789a; border-radius: 30px;
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>180</width>
<height>700</height>
</rect>
</property>
<property name="palette">
@ -3059,8 +3059,8 @@ border-radius: 10px;
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>180</width>
<height>700</height>
</rect>
</property>
<property name="mouseTracking">
@ -3491,11 +3491,6 @@ border-radius: 10px;
<string>Ctrl+L</string>
</property>
</action>
<action name="actionFoo">
<property name="text">
<string>Foo</string>
</property>
</action>
<action name="action">
<property name="text">
<string/>