Using the same optimizations as in category tree view (Ref T472)

* isEmpty
* digest signal
This commit is contained in:
Klaus Basan
2019-02-05 21:49:00 +01:00
committed by Mat Sutcliffe
parent fe05c2287b
commit c123c8bbca
3 changed files with 23 additions and 8 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -16,6 +16,7 @@
#include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/comsystem.h"
#include "blackmisc/pq/frequency.h"
#include "blackmisc/digestsignal.h"
#include <QTreeView>
#include <QList>
@@ -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<QString, bool> m_expanded; //!< suffix/expanded
};
} // ns