From c123c8bbcabf39213a82a0b72cd8f5c6542dd3a4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 5 Feb 2019 21:49:00 +0100 Subject: [PATCH] Using the same optimizations as in category tree view (Ref T472) * isEmpty * digest signal --- src/blackgui/models/atcstationtreemodel.cpp | 7 ++----- src/blackgui/views/atcstationtreeview.cpp | 16 +++++++++++++--- src/blackgui/views/atcstationtreeview.h | 8 ++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/blackgui/models/atcstationtreemodel.cpp b/src/blackgui/models/atcstationtreemodel.cpp index a3cf45b47..0a8213416 100644 --- a/src/blackgui/models/atcstationtreemodel.cpp +++ b/src/blackgui/models/atcstationtreemodel.cpp @@ -47,11 +47,8 @@ namespace BlackGui void CAtcStationTreeModel::updateContainer(const CAtcStationList &stations) { - if (stations.isEmpty()) - { - CAtcStationTreeModel::clear(); - return; - } + this->clear(); + if (stations.isEmpty()) { return; } m_stations = stations.sortedByAtcSuffixSortOrderAndDistance(); m_stationsBySuffix = m_stations.splitPerSuffix(); diff --git a/src/blackgui/views/atcstationtreeview.cpp b/src/blackgui/views/atcstationtreeview.cpp index d900c9c69..ff9e9be10 100644 --- a/src/blackgui/views/atcstationtreeview.cpp +++ b/src/blackgui/views/atcstationtreeview.cpp @@ -57,6 +57,11 @@ namespace BlackGui this->stationModel()->clear(); } + bool CAtcStationTreeView::isEmpty() const + { + return this->stationModel()->rowCount() < 1; + } + void CAtcStationTreeView::setColumns(const CColumns &columns) { if (this->stationModel()) { this->stationModel()->setColumns(columns); } @@ -64,6 +69,12 @@ namespace BlackGui void CAtcStationTreeView::fullResizeToContents() { + m_dsFullResize.inputSignal(); + } + + void CAtcStationTreeView::fullResizeToContentsImpl() + { + if (this->isEmpty()) { return; } for (int c = 0; c < this->model()->columnCount(); c++) { this->resizeColumnToContents(c); @@ -83,8 +94,7 @@ namespace BlackGui CAtcStation CAtcStationTreeView::selectedObject() const { const QModelIndex index = this->currentIndex(); - // Qt 5.11 or later const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign - const QVariant data = this->model()->data(index.sibling(index.row(), 0)); // supposed to be the callsign + const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign const QString callsign = data.toString(); const CAtcStationTreeModel *model = this->stationModel(); if (!model) { return CAtcStation(); } @@ -118,7 +128,7 @@ namespace BlackGui connect(com1, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom1); connect(com2, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom2); connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage); - connect(resize, &QAction::triggered, this, &CAtcStationTreeView::fullResizeToContents); + connect(resize, &QAction::triggered, this, &CAtcStationTreeView::fullResizeToContentsImpl); menu->addAction(com1); menu->addAction(com2); diff --git a/src/blackgui/views/atcstationtreeview.h b/src/blackgui/views/atcstationtreeview.h index 84b9ff192..82daa5a22 100644 --- a/src/blackgui/views/atcstationtreeview.h +++ b/src/blackgui/views/atcstationtreeview.h @@ -16,6 +16,7 @@ #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/comsystem.h" #include "blackmisc/pq/frequency.h" +#include "blackmisc/digestsignal.h" #include #include @@ -52,6 +53,9 @@ namespace BlackGui //! Clear void clear(); + //! Empty + bool isEmpty() const; + //! Set columns void setColumns(const Models::CColumns &columns); @@ -75,6 +79,9 @@ namespace BlackGui //! Used model Models::CAtcStationTreeModel *stationModel(); + //! Resize all columns + void fullResizeToContentsImpl(); + //! The selected object BlackMisc::Aviation::CAtcStation selectedObject() const; @@ -99,6 +106,7 @@ namespace BlackGui void requestTextMessage(); //! @} + BlackMisc::CDigestSignal m_dsFullResize { this, &CAtcStationTreeView::fullResizeToContentsImpl, 1000, 25 }; QMap m_expanded; //!< suffix/expanded }; } // ns