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

View File

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

View File

@ -196,7 +196,19 @@ void TracePlot::paintEvent(QPaintEvent *event)
x += usedLabelArea.width()+labelMarginRight;
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()) {
continue;
}

View File

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

View File

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

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>876</width>
<height>587</height>
<width>909</width>
<height>657</height>
</rect>
</property>
<property name="windowTitle">
@ -77,9 +77,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-319</y>
<width>651</width>
<height>854</height>
<y>0</y>
<width>687</width>
<height>938</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_12">
@ -98,7 +98,7 @@
</size>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -1200,19 +1200,6 @@
</item>
</layout>
</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>
</widget>
<widget class="QWidget" name="Marker">
@ -1268,6 +1255,32 @@
</item>
</widget>
</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>
</item>
<item>
@ -1285,19 +1298,6 @@
</item>
</layout>
</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>
</widget>
<widget class="QWidget" name="SCPIServer">