Sort markers on graph display

This commit is contained in:
Jan Käberich 2022-07-09 15:02:36 +02:00
parent f73a1e93d0
commit 17882c9d51
6 changed files with 69 additions and 33 deletions

View File

@ -15,6 +15,7 @@
#include <QMenu> #include <QMenu>
#include <QActionGroup> #include <QActionGroup>
#include <QApplication> #include <QApplication>
#include <QDateTime>
using namespace std; using namespace std;
@ -37,6 +38,7 @@ Marker::Marker(MarkerModel *model, int number, Marker *parent, QString descr)
formatTable(Format::dBAngle), formatTable(Format::dBAngle),
group(nullptr) group(nullptr)
{ {
creationTimestamp = QDateTime::currentSecsSinceEpoch();
connect(this, &Marker::traceChanged, this, &Marker::updateContextmenu); connect(this, &Marker::traceChanged, this, &Marker::updateContextmenu);
connect(this, &Marker::typeChanged, this, &Marker::updateContextmenu); connect(this, &Marker::typeChanged, this, &Marker::updateContextmenu);
updateContextmenu(); updateContextmenu();
@ -1120,6 +1122,7 @@ nlohmann::json Marker::toJSON()
{ {
nlohmann::json j; nlohmann::json j;
j["trace"] = parentTrace->toHash(); j["trace"] = parentTrace->toHash();
j["creationTimestamp"] = creationTimestamp;
j["visible"] = visible; j["visible"] = visible;
j["type"] = typeToString(type).toStdString(); j["type"] = typeToString(type).toStdString();
j["number"] = number; j["number"] = number;
@ -1160,6 +1163,7 @@ void Marker::fromJSON(nlohmann::json j)
if(!j.contains("trace")) { if(!j.contains("trace")) {
throw runtime_error("Marker has no trace assigned"); throw runtime_error("Marker has no trace assigned");
} }
creationTimestamp = j.value("creationTimestamp", QDateTime::currentSecsSinceEpoch());
number = j.value("number", 1); number = j.value("number", 1);
position = j.value("position", 0.0); position = j.value("position", 0.0);
visible = j.value("visible", true); visible = j.value("visible", true);
@ -1702,6 +1706,11 @@ QPixmap &Marker::getSymbol()
return symbol; return symbol;
} }
unsigned long Marker::getCreationTimestamp() const
{
return creationTimestamp;
}
double Marker::getPosition() const double Marker::getPosition() const
{ {
return position; return position;

View File

@ -69,6 +69,8 @@ public:
QPixmap& getSymbol(); QPixmap& getSymbol();
unsigned long getCreationTimestamp() const;
int getNumber() const; int getNumber() const;
void setNumber(int value); void setNumber(int value);
@ -179,6 +181,7 @@ private:
MarkerModel *model; MarkerModel *model;
Trace *parentTrace; Trace *parentTrace;
unsigned long creationTimestamp;
double position; double position;
int number; int number;
bool visible; bool visible;

View File

@ -196,7 +196,19 @@ void TracePlot::paintEvent(QPaintEvent *event)
x += usedLabelArea.width()+labelMarginRight; x += usedLabelArea.width()+labelMarginRight;
auto tmarkers = t.first->getMarkers(); auto tmarkers = t.first->getMarkers();
for(auto m : tmarkers) { std::vector<Marker*> vmarkers(tmarkers.begin(), tmarkers.end());
sort(vmarkers.begin(), vmarkers.end(), [](Marker *l, Marker *r) -> bool {
switch(Preferences::getInstance().Marker.sortOrder) {
case PrefMarkerSortXCoord:
return l->getPosition() < r->getPosition();
case PrefMarkerSortNumber:
return l->getNumber() < r->getNumber();
case PrefMarkerSortTimestamp:
return l->getCreationTimestamp() < r->getCreationTimestamp();
}
return false;
});
for(auto m : vmarkers) {
if(!m->isVisible()) { if(!m->isVisible()) {
continue; continue;
} }

View File

@ -258,6 +258,7 @@ void PreferencesDialog::setInitialGUIState()
ui->MarkerShowMarkerData->setChecked(p->Marker.defaultBehavior.showDataOnGraphs); ui->MarkerShowMarkerData->setChecked(p->Marker.defaultBehavior.showDataOnGraphs);
ui->MarkerShowAllMarkerData->setChecked(p->Marker.defaultBehavior.showAllData); ui->MarkerShowAllMarkerData->setChecked(p->Marker.defaultBehavior.showAllData);
ui->MarkerInterpolate->setCurrentIndex(p->Marker.interpolatePoints ? 1 : 0); ui->MarkerInterpolate->setCurrentIndex(p->Marker.interpolatePoints ? 1 : 0);
ui->MarkerSortOrder->setCurrentIndex((int) p->Marker.sortOrder);
ui->SCPIServerEnabled->setChecked(p->SCPIServer.enabled); ui->SCPIServerEnabled->setChecked(p->SCPIServer.enabled);
ui->SCPIServerPort->setValue(p->SCPIServer.port); ui->SCPIServerPort->setValue(p->SCPIServer.port);
@ -323,6 +324,7 @@ void PreferencesDialog::updateFromGUI()
p->Marker.defaultBehavior.showDataOnGraphs = ui->MarkerShowMarkerData->isChecked(); p->Marker.defaultBehavior.showDataOnGraphs = ui->MarkerShowMarkerData->isChecked();
p->Marker.defaultBehavior.showAllData = ui->MarkerShowAllMarkerData->isChecked(); p->Marker.defaultBehavior.showAllData = ui->MarkerShowAllMarkerData->isChecked();
p->Marker.interpolatePoints = ui->MarkerInterpolate->currentIndex() == 1; p->Marker.interpolatePoints = ui->MarkerInterpolate->currentIndex() == 1;
p->Marker.sortOrder = (MarkerSortOrder) ui->MarkerSortOrder->currentIndex();
p->SCPIServer.enabled = ui->SCPIServerEnabled->isChecked(); p->SCPIServer.enabled = ui->SCPIServerEnabled->isChecked();
p->SCPIServer.port = ui->SCPIServerPort->value(); p->SCPIServer.port = ui->SCPIServerPort->value();

View File

@ -24,6 +24,14 @@ enum GraphLimitIndication {
Q_DECLARE_METATYPE(GraphLimitIndication); Q_DECLARE_METATYPE(GraphLimitIndication);
enum MarkerSortOrder {
PrefMarkerSortXCoord = 0,
PrefMarkerSortNumber = 1,
PrefMarkerSortTimestamp = 2,
};
Q_DECLARE_METATYPE(MarkerSortOrder);
class Preferences : public Savable { class Preferences : public Savable {
public: public:
@ -115,6 +123,7 @@ public:
bool showAllData; bool showAllData;
} defaultBehavior; } defaultBehavior;
bool interpolatePoints; bool interpolatePoints;
MarkerSortOrder sortOrder;
} Marker; } Marker;
struct { struct {
bool enabled; bool enabled;
@ -184,6 +193,7 @@ private:
{&Marker.defaultBehavior.showDataOnGraphs, "Marker.defaultBehavior.ShowDataOnGraphs", true}, {&Marker.defaultBehavior.showDataOnGraphs, "Marker.defaultBehavior.ShowDataOnGraphs", true},
{&Marker.defaultBehavior.showAllData, "Marker.defaultBehavior.ShowAllData", false}, {&Marker.defaultBehavior.showAllData, "Marker.defaultBehavior.ShowAllData", false},
{&Marker.interpolatePoints, "Marker.interpolatePoints", false}, {&Marker.interpolatePoints, "Marker.interpolatePoints", false},
{&Marker.sortOrder, "Marker.sortOrder", MarkerSortOrder::PrefMarkerSortXCoord},
{&SCPIServer.enabled, "SCPIServer.enabled", true}, {&SCPIServer.enabled, "SCPIServer.enabled", true},
{&SCPIServer.port, "SCPIServer.port", 19542}, {&SCPIServer.port, "SCPIServer.port", 19542},
}}; }};

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>876</width> <width>909</width>
<height>587</height> <height>657</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -77,9 +77,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-319</y> <y>0</y>
<width>651</width> <width>687</width>
<height>854</height> <height>938</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_12"> <layout class="QHBoxLayout" name="horizontalLayout_12">
@ -98,7 +98,7 @@
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="Startup"> <widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -1200,19 +1200,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="Marker"> <widget class="QWidget" name="Marker">
@ -1268,6 +1255,32 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label_44">
<property name="text">
<string>Sort order on graphs:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="MarkerSortOrder">
<item>
<property name="text">
<string>X-Coordinate (Frequency/Time/Power)</string>
</property>
</item>
<item>
<property name="text">
<string>Number</string>
</property>
</item>
<item>
<property name="text">
<string>Creation timestamp</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -1285,19 +1298,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>300</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="SCPIServer"> <widget class="QWidget" name="SCPIServer">