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:
Klaus Basan
2014-08-31 15:52:00 +02:00
parent 983a8d5d30
commit 538cee89b2
10 changed files with 82 additions and 92 deletions

View File

@@ -19,13 +19,7 @@ namespace BlackGui
{
CAircraftView::CAircraftView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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());
this->standardInit(new CAircraftListModel(this));
}
}
}

View File

@@ -19,15 +19,7 @@ namespace BlackGui
{
CAirportView::CAirportView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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());
}
this->standardInit(new CAirportListModel(this));
}
}
}

View File

@@ -19,19 +19,27 @@ namespace BlackGui
{
CAtcStationView::CAtcStationView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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());
this->standardInit(new CAtcStationListModel(CAtcStationListModel::StationsOnline, this));
}
void CAtcStationView::setStationMode(CAtcStationListModel::AtcStationMode stationMode)
{
Q_ASSERT(this->m_model);
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)

View File

@@ -9,6 +9,7 @@
#include "clientview.h"
#include <QHeaderView>
#include <QDebug>
using namespace BlackMisc;
using namespace BlackGui::Models;
@@ -19,14 +20,7 @@ namespace BlackGui
{
CClientView::CClientView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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);
this->standardInit(new CClientListModel(this));
}
}
}

View File

@@ -19,14 +19,8 @@ namespace BlackGui
{
CKeyboardKeyView::CKeyboardKeyView(QWidget *parent) : CViewBase(parent)
{
this->m_model = new CKeyboardKeyListModel(this);
this->setModel(this->m_model); // via QTableView
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));
this->standardInit(new CKeyboardKeyListModel(this));
this->setItemDelegate(new CKeyboardKeyItemDelegate(this)); // for editing
}
}
}

View File

@@ -19,14 +19,7 @@ namespace BlackGui
{
CNameVariantPairView::CNameVariantPairView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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);
this->standardInit(new CNameVariantPairModel(true, this));
}
void CNameVariantPairView::setIconMode(bool withIcon)
@@ -39,15 +32,13 @@ namespace BlackGui
{
Q_ASSERT(this->m_model);
this->m_model->addOrUpdateByName(name, value, icon);
this->resizeColumnsToContents();
this->resizeRowsToContents();
this->resizeToContents();
}
void CNameVariantPairView::removeByName(const QString &name)
{
this->m_model->removeByName(name);
this->resizeColumnsToContents();
this->resizeRowsToContents();
this->resizeToContents();
}
}
}

View File

@@ -19,13 +19,7 @@ namespace BlackGui
{
CServerView::CServerView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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());
this->standardInit(new CServerListModel(this));
}
void CServerView::setSelectedServer(const Network::CServer &selectedServer)

View File

@@ -23,16 +23,7 @@ namespace BlackGui
*/
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent), m_contextMenu(nullptr)
{
this->m_model = 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->standardInit(new CStatusMessageListModel(this));
this->setContextMenuPolicy(Qt::CustomContextMenu);
this->m_contextMenu = new QMenu(this);
this->m_contextMenu->addAction("Clear");
@@ -58,5 +49,5 @@ namespace BlackGui
}
}
}
}
}
} // namespace
} // namespace

View File

@@ -19,14 +19,7 @@ namespace BlackGui
{
CUserView::CUserView(QWidget *parent) : CViewBase(parent)
{
this->m_model = 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);
this->standardInit(new CUserListModel(CUserListModel::UserDetailed, this));
}
void CUserView::setUserMode(CUserListModel::UserMode userMode)

View File

@@ -22,20 +22,6 @@ namespace BlackGui
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:
//! Model
@@ -95,6 +81,59 @@ namespace BlackGui
Q_ASSERT(this->m_model);
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
};
}
}