Additional work on the graphing view, addition of the new graph dialog.
This commit is contained in:
+6
-3
@@ -18,7 +18,8 @@ SOURCES += main.cpp\
|
||||
utility.cpp \
|
||||
qcustomplot.cpp \
|
||||
graphingwindow.cpp \
|
||||
frameinfowindow.cpp
|
||||
frameinfowindow.cpp \
|
||||
newgraphdialog.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
can_structs.h \
|
||||
@@ -26,8 +27,10 @@ HEADERS += mainwindow.h \
|
||||
utility.h \
|
||||
qcustomplot.h \
|
||||
graphingwindow.h \
|
||||
frameinfowindow.h
|
||||
frameinfowindow.h \
|
||||
newgraphdialog.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
graphingwindow.ui \
|
||||
frameinfowindow.ui
|
||||
frameinfowindow.ui \
|
||||
newgraphdialog.ui
|
||||
|
||||
@@ -1,14 +1,210 @@
|
||||
#include "graphingwindow.h"
|
||||
#include "ui_graphingwindow.h"
|
||||
#include "newgraphdialog.h"
|
||||
|
||||
GraphingWindow::GraphingWindow(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GraphingWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->graphingView->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
|
||||
QCP::iSelectLegend | QCP::iSelectPlottables);
|
||||
|
||||
connect(ui->graphingView, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
|
||||
connect(ui->graphingView, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
|
||||
|
||||
// make bottom and left axes transfer their ranges to top and right axes:
|
||||
connect(ui->graphingView->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->graphingView->xAxis2, SLOT(setRange(QCPRange)));
|
||||
connect(ui->graphingView->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->graphingView->yAxis2, SLOT(setRange(QCPRange)));
|
||||
|
||||
connect(ui->graphingView, SIGNAL(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)));
|
||||
connect(ui->graphingView, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
|
||||
connect(ui->graphingView, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));
|
||||
|
||||
// setup policy and connect slot for context menu popup:
|
||||
ui->graphingView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->graphingView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
GraphingWindow::~GraphingWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void GraphingWindow::titleDoubleClick(QMouseEvent* event, QCPPlotTitle* title)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
// Set the plot title by double clicking on it
|
||||
bool ok;
|
||||
QString newTitle = QInputDialog::getText(this, "SavvyCAN Graphing", "New plot title:", QLineEdit::Normal, title->text(), &ok);
|
||||
if (ok)
|
||||
{
|
||||
title->setText(newTitle);
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingWindow::axisLabelDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part)
|
||||
{
|
||||
// Set an axis label by double clicking on it
|
||||
if (part == QCPAxis::spAxisLabel) // only react when the actual axis label is clicked, not tick label or axis backbone
|
||||
{
|
||||
bool ok;
|
||||
QString newLabel = QInputDialog::getText(this, "SavvyCAN Graphing", "New axis label:", QLineEdit::Normal, axis->label(), &ok);
|
||||
if (ok)
|
||||
{
|
||||
axis->setLabel(newLabel);
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingWindow::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item)
|
||||
{
|
||||
// Rename a graph by double clicking on its legend item
|
||||
Q_UNUSED(legend)
|
||||
if (item) // only react if item was clicked (user could have clicked on border padding of legend where there is no item, then item is 0)
|
||||
{
|
||||
QCPPlottableLegendItem *plItem = qobject_cast<QCPPlottableLegendItem*>(item);
|
||||
bool ok;
|
||||
QString newName = QInputDialog::getText(this, "SavvyCAN Graphing", "New graph name:", QLineEdit::Normal, plItem->plottable()->name(), &ok);
|
||||
if (ok)
|
||||
{
|
||||
plItem->plottable()->setName(newName);
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingWindow::selectionChanged()
|
||||
{
|
||||
/*
|
||||
normally, axis base line, axis tick labels and axis labels are selectable separately, but we want
|
||||
the user only to be able to select the axis as a whole, so we tie the selected states of the tick labels
|
||||
and the axis base line together. However, the axis label shall be selectable individually.
|
||||
|
||||
The selection state of the left and right axes shall be synchronized as well as the state of the
|
||||
bottom and top axes.
|
||||
|
||||
Further, we want to synchronize the selection of the graphs with the selection state of the respective
|
||||
legend item belonging to that graph. So the user can select a graph by either clicking on the graph itself
|
||||
or on its legend item.
|
||||
*/
|
||||
|
||||
// make top and bottom axes be selected synchronously, and handle axis and tick labels as one selectable object:
|
||||
if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
|
||||
ui->graphingView->xAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->graphingView->xAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
|
||||
{
|
||||
ui->graphingView->xAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
|
||||
ui->graphingView->xAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
|
||||
}
|
||||
// make left and right axes be selected synchronously, and handle axis and tick labels as one selectable object:
|
||||
if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
|
||||
ui->graphingView->yAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->graphingView->yAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
|
||||
{
|
||||
ui->graphingView->yAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
|
||||
ui->graphingView->yAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
|
||||
}
|
||||
|
||||
// synchronize selection of graphs with selection of corresponding legend items:
|
||||
for (int i=0; i<ui->graphingView->graphCount(); ++i)
|
||||
{
|
||||
QCPGraph *graph = ui->graphingView->graph(i);
|
||||
QCPPlottableLegendItem *item = ui->graphingView->legend->itemWithPlottable(graph);
|
||||
if (item->selected() || graph->selected())
|
||||
{
|
||||
item->setSelected(true);
|
||||
graph->setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingWindow::mousePress()
|
||||
{
|
||||
// if an axis is selected, only allow the direction of that axis to be dragged
|
||||
// if no axis is selected, both directions may be dragged
|
||||
|
||||
if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
|
||||
ui->graphingView->axisRect()->setRangeDrag(ui->graphingView->xAxis->orientation());
|
||||
else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
|
||||
ui->graphingView->axisRect()->setRangeDrag(ui->graphingView->yAxis->orientation());
|
||||
else
|
||||
ui->graphingView->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
|
||||
}
|
||||
|
||||
void GraphingWindow::mouseWheel()
|
||||
{
|
||||
// if an axis is selected, only allow the direction of that axis to be zoomed
|
||||
// if no axis is selected, both directions may be zoomed
|
||||
|
||||
if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
|
||||
ui->graphingView->axisRect()->setRangeZoom(ui->graphingView->xAxis->orientation());
|
||||
else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
|
||||
ui->graphingView->axisRect()->setRangeZoom(ui->graphingView->yAxis->orientation());
|
||||
else
|
||||
ui->graphingView->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
|
||||
}
|
||||
|
||||
void GraphingWindow::removeSelectedGraph()
|
||||
{
|
||||
if (ui->graphingView->selectedGraphs().size() > 0)
|
||||
{
|
||||
ui->graphingView->removeGraph(ui->graphingView->selectedGraphs().first());
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingWindow::removeAllGraphs()
|
||||
{
|
||||
ui->graphingView->clearGraphs();
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
|
||||
void GraphingWindow::contextMenuRequest(QPoint pos)
|
||||
{
|
||||
QMenu *menu = new QMenu(this);
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
if (ui->graphingView->legend->selectTest(pos, false) >= 0) // context menu on legend requested
|
||||
{
|
||||
menu->addAction("Move to top left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignLeft));
|
||||
menu->addAction("Move to top center", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignHCenter));
|
||||
menu->addAction("Move to top right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight));
|
||||
menu->addAction("Move to bottom right", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight));
|
||||
menu->addAction("Move to bottom left", this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft));
|
||||
} else // general context menu on graphs requested
|
||||
{
|
||||
menu->addAction("Add new graph", this, SLOT(addNewGraph()));
|
||||
if (ui->graphingView->selectedGraphs().size() > 0)
|
||||
menu->addAction("Remove selected graph", this, SLOT(removeSelectedGraph()));
|
||||
if (ui->graphingView->graphCount() > 0)
|
||||
menu->addAction("Remove all graphs", this, SLOT(removeAllGraphs()));
|
||||
}
|
||||
|
||||
menu->popup(ui->graphingView->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void GraphingWindow::addNewGraph()
|
||||
{
|
||||
NewGraphDialog *thisDialog = new NewGraphDialog();
|
||||
thisDialog->show();
|
||||
}
|
||||
|
||||
void GraphingWindow::moveLegend()
|
||||
{
|
||||
if (QAction* contextAction = qobject_cast<QAction*>(sender())) // make sure this slot is really called by a context menu action, so it carries the data we need
|
||||
{
|
||||
bool ok;
|
||||
int dataInt = contextAction->data().toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
ui->graphingView->axisRect()->insetLayout()->setInsetAlignment(0, (Qt::Alignment)dataInt);
|
||||
ui->graphingView->replot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef GRAPHINGWINDOW_H
|
||||
#define GRAPHINGWINDOW_H
|
||||
|
||||
#include "qcustomplot.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
@@ -15,6 +17,19 @@ public:
|
||||
explicit GraphingWindow(QWidget *parent = 0);
|
||||
~GraphingWindow();
|
||||
|
||||
private slots:
|
||||
void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
|
||||
void axisLabelDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part);
|
||||
void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item);
|
||||
void selectionChanged();
|
||||
void mousePress();
|
||||
void mouseWheel();
|
||||
void removeSelectedGraph();
|
||||
void removeAllGraphs();
|
||||
void contextMenuRequest(QPoint pos);
|
||||
void moveLegend();
|
||||
void addNewGraph();
|
||||
|
||||
private:
|
||||
Ui::GraphingWindow *ui;
|
||||
};
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>Data Graphing</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
@@ -32,7 +32,7 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCustomPlot" name="widget" native="true"/>
|
||||
<widget class="QCustomPlot" name="graphingView" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "newgraphdialog.h"
|
||||
#include "ui_newgraphdialog.h"
|
||||
|
||||
NewGraphDialog::NewGraphDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NewGraphDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
NewGraphDialog::~NewGraphDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef NEWGRAPHDIALOG_H
|
||||
#define NEWGRAPHDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class NewGraphDialog;
|
||||
}
|
||||
|
||||
class NewGraphDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NewGraphDialog(QWidget *parent = 0);
|
||||
~NewGraphDialog();
|
||||
|
||||
private:
|
||||
Ui::NewGraphDialog *ui;
|
||||
};
|
||||
|
||||
#endif // NEWGRAPHDIALOG_H
|
||||
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NewGraphDialog</class>
|
||||
<widget class="QDialog" name="NewGraphDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>273</width>
|
||||
<height>309</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>ID:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Data:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Signed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Mask:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Bias:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Stride</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_2"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_3"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_4"/>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_5"/>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_6"/>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QGraphicsView" name="graphicsView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add this graph</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user