mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:11:00 +08:00
refs #319, cleaned up views for formatters, in the same step fixed bug sort column based on view mode was missing
This commit is contained in:
@@ -19,13 +19,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CAircraftView::CAircraftView(QWidget *parent) : CViewBase(parent)
|
CAircraftView::CAircraftView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CAircraftListModel(this);
|
this->standardInit(new CAircraftListModel(this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAircraft::IndexDistance);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CAirportView::CAirportView(QWidget *parent) : CViewBase(parent)
|
CAirportView::CAirportView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CAirportListModel(this);
|
this->standardInit(new CAirportListModel(this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAirport::IndexDistance);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
{
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,27 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CAtcStationView::CAtcStationView(QWidget *parent) : CViewBase(parent)
|
CAtcStationView::CAtcStationView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CAtcStationListModel(CAtcStationListModel::StationsOnline, this);
|
this->standardInit(new CAtcStationListModel(CAtcStationListModel::StationsOnline, this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAtcStation::IndexDistance);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAtcStationView::setStationMode(CAtcStationListModel::AtcStationMode stationMode)
|
void CAtcStationView::setStationMode(CAtcStationListModel::AtcStationMode stationMode)
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->m_model);
|
Q_ASSERT(this->m_model);
|
||||||
this->m_model->setStationMode(stationMode);
|
this->m_model->setStationMode(stationMode);
|
||||||
|
|
||||||
|
switch (stationMode)
|
||||||
|
{
|
||||||
|
case CAtcStationListModel::NotSet:
|
||||||
|
case CAtcStationListModel::StationsOnline:
|
||||||
|
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAtcStation::IndexDistance);
|
||||||
|
break;
|
||||||
|
case CAtcStationListModel::StationsBooked:
|
||||||
|
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAtcStation::IndexBookedFrom);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this->setSortIndicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAtcStationView::changedAtcStationConnectionStatus(const Aviation::CAtcStation &station, bool added)
|
void CAtcStationView::changedAtcStationConnectionStatus(const Aviation::CAtcStation &station, bool added)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "clientview.h"
|
#include "clientview.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackGui::Models;
|
using namespace BlackGui::Models;
|
||||||
@@ -19,14 +20,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CClientView::CClientView(QWidget *parent) : CViewBase(parent)
|
CClientView::CClientView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CClientListModel(this);
|
this->standardInit(new CClientListModel(this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex( { BlackMisc::Network::CClient::IndexUser, BlackMisc::Network::CUser::IndexRealName });
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
this->horizontalHeader()->setStretchLastSection(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,8 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CKeyboardKeyView::CKeyboardKeyView(QWidget *parent) : CViewBase(parent)
|
CKeyboardKeyView::CKeyboardKeyView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CKeyboardKeyListModel(this);
|
this->standardInit(new CKeyboardKeyListModel(this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
this->setItemDelegate(new CKeyboardKeyItemDelegate(this)); // for editing
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Settings::CSettingKeyboardHotkey::IndexFunctionAsString);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
this->setItemDelegate(new CKeyboardKeyItemDelegate(this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CNameVariantPairView::CNameVariantPairView(QWidget *parent) : CViewBase(parent)
|
CNameVariantPairView::CNameVariantPairView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CNameVariantPairModel(true, this);
|
this->standardInit(new CNameVariantPairModel(true, this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::CNameVariantPair::IndexName);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
this->horizontalHeader()->setStretchLastSection(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNameVariantPairView::setIconMode(bool withIcon)
|
void CNameVariantPairView::setIconMode(bool withIcon)
|
||||||
@@ -39,15 +32,13 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
Q_ASSERT(this->m_model);
|
Q_ASSERT(this->m_model);
|
||||||
this->m_model->addOrUpdateByName(name, value, icon);
|
this->m_model->addOrUpdateByName(name, value, icon);
|
||||||
this->resizeColumnsToContents();
|
this->resizeToContents();
|
||||||
this->resizeRowsToContents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNameVariantPairView::removeByName(const QString &name)
|
void CNameVariantPairView::removeByName(const QString &name)
|
||||||
{
|
{
|
||||||
this->m_model->removeByName(name);
|
this->m_model->removeByName(name);
|
||||||
this->resizeColumnsToContents();
|
this->resizeToContents();
|
||||||
this->resizeRowsToContents();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CServerView::CServerView(QWidget *parent) : CViewBase(parent)
|
CServerView::CServerView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CServerListModel(this);
|
this->standardInit(new CServerListModel(this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Network::CServer::IndexName);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerView::setSelectedServer(const Network::CServer &selectedServer)
|
void CServerView::setSelectedServer(const Network::CServer &selectedServer)
|
||||||
|
|||||||
@@ -23,16 +23,7 @@ namespace BlackGui
|
|||||||
*/
|
*/
|
||||||
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent), m_contextMenu(nullptr)
|
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent), m_contextMenu(nullptr)
|
||||||
{
|
{
|
||||||
this->m_model = new CStatusMessageListModel(this);
|
this->standardInit(new CStatusMessageListModel(this));
|
||||||
this->setModel(this->m_model); // QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::CStatusMessage::IndexTimestamp);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
{
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
this->m_contextMenu = new QMenu(this);
|
this->m_contextMenu = new QMenu(this);
|
||||||
this->m_contextMenu->addAction("Clear");
|
this->m_contextMenu->addAction("Clear");
|
||||||
@@ -58,5 +49,5 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
}
|
} // namespace
|
||||||
|
|||||||
@@ -19,14 +19,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CUserView::CUserView(QWidget *parent) : CViewBase(parent)
|
CUserView::CUserView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->m_model = new CUserListModel(CUserListModel::UserDetailed, this);
|
this->standardInit(new CUserListModel(CUserListModel::UserDetailed, this));
|
||||||
this->setModel(this->m_model); // via QTableView
|
|
||||||
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Network::CUser::IndexRealName);
|
|
||||||
if (this->m_model->hasValidSortColumn())
|
|
||||||
this->horizontalHeader()->setSortIndicator(
|
|
||||||
this->m_model->getSortColumn(),
|
|
||||||
this->m_model->getSortOrder());
|
|
||||||
this->horizontalHeader()->setStretchLastSection(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUserView::setUserMode(CUserListModel::UserMode userMode)
|
void CUserView::setUserMode(CUserListModel::UserMode userMode)
|
||||||
|
|||||||
@@ -22,20 +22,6 @@ namespace BlackGui
|
|||||||
template <class ModelClass> class CViewBase : public QTableView
|
template <class ModelClass> class CViewBase : public QTableView
|
||||||
{
|
{
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
CViewBase(QWidget *parent, ModelClass *model = nullptr) : QTableView(parent), m_model(model)
|
|
||||||
{
|
|
||||||
this->setSortingEnabled(true);
|
|
||||||
this->horizontalHeader()->setStretchLastSection(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
virtual ~CViewBase() {}
|
|
||||||
|
|
||||||
ModelClass *m_model; //!< corresponding model
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Model
|
//! Model
|
||||||
@@ -95,6 +81,59 @@ namespace BlackGui
|
|||||||
Q_ASSERT(this->m_model);
|
Q_ASSERT(this->m_model);
|
||||||
return this->m_model->rowCount() < 1;
|
return this->m_model->rowCount() < 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Set own name and the model's name
|
||||||
|
void setObjectName(const QString &name)
|
||||||
|
{
|
||||||
|
// then name here is mainly set for debugging purposes so each model can be identified
|
||||||
|
Q_ASSERT(m_model);
|
||||||
|
QTableView::setObjectName(name);
|
||||||
|
QString modelName = QString(name).append(':').append(this->m_model->getTranslationContext());
|
||||||
|
this->m_model->setObjectName(modelName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
CViewBase(QWidget *parent, ModelClass *model = nullptr) : QTableView(parent), m_model(model)
|
||||||
|
{
|
||||||
|
this->setSortingEnabled(true);
|
||||||
|
if (model) { this->setModel(this->m_model); }
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
virtual ~CViewBase() {}
|
||||||
|
|
||||||
|
//! Set the search indicator based on model
|
||||||
|
void setSortIndicator()
|
||||||
|
{
|
||||||
|
if (this->m_model->hasValidSortColumn())
|
||||||
|
{
|
||||||
|
this->horizontalHeader()->setSortIndicator(
|
||||||
|
this->m_model->getSortColumn(),
|
||||||
|
this->m_model->getSortOrder());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Resize to content
|
||||||
|
void resizeToContents()
|
||||||
|
{
|
||||||
|
this->resizeColumnsToContents();
|
||||||
|
this->resizeRowsToContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Init
|
||||||
|
void standardInit(ModelClass *model = nullptr)
|
||||||
|
{
|
||||||
|
Q_ASSERT(model || this->m_model);
|
||||||
|
if (model) { this->m_model = model; }
|
||||||
|
this->setModel(this->m_model); // via QTableView
|
||||||
|
this->setSortIndicator();
|
||||||
|
this->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelClass *m_model = nullptr; //!< corresponding model
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user