From ac2102cd6fbf5a3f9a50d966e7c0844c239e4daf Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 28 Oct 2022 14:40:34 +0100 Subject: [PATCH] Save column sort as a setting. Fix deserialize of target satellite. For #1474 --- .../satellitetracker/satellitetrackergui.cpp | 15 ++++++++++++--- .../satellitetracker/satellitetrackergui.h | 1 + .../satellitetracker/satellitetrackersettings.cpp | 7 ++++++- .../satellitetracker/satellitetrackersettings.h | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/feature/satellitetracker/satellitetrackergui.cpp b/plugins/feature/satellitetracker/satellitetrackergui.cpp index 9e91cbfcf..fe390b1e8 100644 --- a/plugins/feature/satellitetracker/satellitetrackergui.cpp +++ b/plugins/feature/satellitetracker/satellitetrackergui.cpp @@ -76,7 +76,6 @@ bool SatelliteTrackerGUI::deserialize(const QByteArray& data) m_feature->setWorkspaceIndex(m_settings.m_workspaceIndex); updateSelectedSats(); displaySettings(); - qDebug() << " deserialize " << m_settings.m_satellites; applySettings(true); return true; } @@ -348,18 +347,21 @@ void SatelliteTrackerGUI::displaySettings() blockApplySettings(true); ui->latitude->setValue(m_settings.m_latitude); ui->longitude->setValue(m_settings.m_longitude); - ui->target->clear(); + ui->target->blockSignals(true); + ui->target->clear(); for (const QString& s : m_settings.m_satellites) { ui->target->addItem(s); } - + ui->target->blockSignals(false); ui->target->setCurrentIndex(ui->target->findText(m_settings.m_target)); + ui->dateTimeSelect->setCurrentIndex((int)m_settings.m_dateTimeSelect); ui->dateTime->setVisible(m_settings.m_dateTimeSelect == SatelliteTrackerSettings::CUSTOM); ui->dateTime->setDateTime(QDateTime::fromString(m_settings.m_dateTime, Qt::ISODateWithMs)); ui->autoTarget->setChecked(m_settings.m_autoTarget); ui->darkTheme->setChecked(m_settings.m_chartsDarkTheme); + ui->satTable->horizontalHeader()->setSortIndicator(m_settings.m_columnSort, m_settings.m_columnSortOrder); getRollupContents()->restoreState(m_rollupState); plotChart(); blockApplySettings(false); @@ -1204,7 +1206,13 @@ void SatelliteTrackerGUI::on_satTable_cellDoubleClicked(int row, int column) QString sat = ui->satTable->item(row, SAT_COL_NAME)->text(); FeatureWebAPIUtils::mapFind(sat); +} +void SatelliteTrackerGUI::on_satTableHeader_sortIndicatorChanged(int logicalIndex, Qt::SortOrder order) +{ + m_settings.m_columnSort = logicalIndex; + m_settings.m_columnSortOrder = order; + applySettings(); } // Columns in table reordered @@ -1347,5 +1355,6 @@ void SatelliteTrackerGUI::makeUIConnections() QObject::connect(ui->prevPass, &QToolButton::clicked, this, &SatelliteTrackerGUI::on_prevPass_clicked); QObject::connect(ui->darkTheme, &QToolButton::clicked, this, &SatelliteTrackerGUI::on_darkTheme_clicked); QObject::connect(ui->satTable, &QTableWidget::cellDoubleClicked, this, &SatelliteTrackerGUI::on_satTable_cellDoubleClicked); + QObject::connect(ui->satTable->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &SatelliteTrackerGUI::on_satTableHeader_sortIndicatorChanged); QObject::connect(ui->deviceFeatureSelect, qOverload(&QComboBox::currentIndexChanged), this, &SatelliteTrackerGUI::on_deviceFeatureSelect_currentIndexChanged); } diff --git a/plugins/feature/satellitetracker/satellitetrackergui.h b/plugins/feature/satellitetracker/satellitetrackergui.h index 54ac11df8..63f5830ae 100644 --- a/plugins/feature/satellitetracker/satellitetrackergui.h +++ b/plugins/feature/satellitetracker/satellitetrackergui.h @@ -161,6 +161,7 @@ private slots: void on_satTable_cellDoubleClicked(int row, int column); void satTable_sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex); void satTable_sectionResized(int logicalIndex, int oldSize, int newSize); + void on_satTableHeader_sortIndicatorChanged(int logicalIndex, Qt::SortOrder order); void columnSelectMenu(QPoint pos); void columnSelectMenuChecked(bool checked = false); void on_deviceFeatureSelect_currentIndexChanged(int index); diff --git a/plugins/feature/satellitetracker/satellitetrackersettings.cpp b/plugins/feature/satellitetracker/satellitetrackersettings.cpp index fda792e80..195781958 100644 --- a/plugins/feature/satellitetracker/satellitetrackersettings.cpp +++ b/plugins/feature/satellitetracker/satellitetrackersettings.cpp @@ -79,7 +79,8 @@ void SatelliteTrackerSettings::resetToDefaults() m_mapFeature = ""; m_fileInputDevice = ""; m_workspaceIndex = 0; - + m_columnSort = -1; + m_columnSortOrder = Qt::AscendingOrder; for (int i = 0; i < SAT_COL_COLUMNS; i++) { m_columnIndexes[i] = i; @@ -138,6 +139,8 @@ QByteArray SatelliteTrackerSettings::serialize() const s.writeString(44, m_fileInputDevice); s.writeS32(45, m_workspaceIndex); s.writeBlob(46, m_geometryBytes); + s.writeS32(47, m_columnSort); + s.writeS32(48, (int)m_columnSortOrder); for (int i = 0; i < SAT_COL_COLUMNS; i++) { s.writeS32(100 + i, m_columnIndexes[i]); @@ -231,6 +234,8 @@ bool SatelliteTrackerSettings::deserialize(const QByteArray& data) d.readString(44, &m_fileInputDevice, ""); d.readS32(45, &m_workspaceIndex, 0); d.readBlob(46, &m_geometryBytes); + d.readS32(47, &m_columnSort, -1); + d.readS32(48, (int *)&m_columnSortOrder, (int)Qt::AscendingOrder); for (int i = 0; i < SAT_COL_COLUMNS; i++) { d.readS32(100 + i, &m_columnIndexes[i], i); diff --git a/plugins/feature/satellitetracker/satellitetrackersettings.h b/plugins/feature/satellitetracker/satellitetrackersettings.h index 34495e41b..3d02b5d86 100644 --- a/plugins/feature/satellitetracker/satellitetrackersettings.h +++ b/plugins/feature/satellitetracker/satellitetrackersettings.h @@ -83,6 +83,8 @@ struct SatelliteTrackerSettings QString m_mapFeature; //!< Which feature when FROM_MAP QString m_fileInputDevice; //!< Which device when FROM_FILE + int m_columnSort; //!< Which column is used for sorting (-1 for none) + Qt::SortOrder m_columnSortOrder; int m_columnIndexes[SAT_COL_COLUMNS];//!< How the columns are ordered in the table int m_columnSizes[SAT_COL_COLUMNS]; //!< Size of the coumns in the table