refs #314, changed models and views to new CPropertyIndex approach

This commit is contained in:
Klaus Basan
2014-08-16 00:54:09 +02:00
parent f4a94aa8ff
commit d88c1bb252
14 changed files with 75 additions and 97 deletions

View File

@@ -330,9 +330,6 @@ namespace BlackGui
CVoiceRoom room1 = selectedVoiceRooms[0];
CVoiceRoom room2 = selectedVoiceRooms[1];
// KB_REMOVE
qDebug() << "selected rooms" << room1.isConnected() << room1.getVoiceRoomUrl() << room2.isConnected() << room2.getVoiceRoomUrl();
// remark
// isAudioPlaying() is not set, as this is only a temporary value when really "something is playing"

View File

@@ -8,10 +8,12 @@
*/
#include "aircraftlistmodel.h"
#include "blackmisc/nwuser.h"
#include "blackmisc/avaircraftsituation.h"
#include "blackmisc/blackmiscfreefunctions.h"
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Network;
namespace BlackGui
{
@@ -23,15 +25,15 @@ namespace BlackGui
CAircraftListModel::CAircraftListModel(QObject *parent) : CListModelBase("ViewAircraftList", parent)
{
this->m_columns.addColumn(CColumn("callsign", CAircraft::IndexCallsign));
this->m_columns.addColumn(CColumn("pilotrealname", CAircraft::IndexPilotRealName));
this->m_columns.addColumn(CColumn("pilotrealname", { CAircraft::IndexPilot, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn("distance", CAircraft::IndexDistance, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("frequency", CAircraft::IndexFrequencyCom1, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("model", CAircraftIcao::IndexAsString));
this->m_columns.addColumn(CColumn("transponder", CAircraft::IndexTansponderFormatted));
this->m_columns.addColumn(CColumn("latitude", CAircraftSituation::IndexLatitude, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("longitude", CAircraftSituation::IndexLongitude, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("altitude", CAircraftSituation::IndexAltitude, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("groundspeed", CAircraftSituation::IndexGroundspeed, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("frequency", { CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency }, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("model", { CAircraft::IndexIcao, CAircraftIcao::IndexAsString}));
this->m_columns.addColumn(CColumn("transponder", { CAircraft::IndexTransponder, CTransponder::IndexTransponderCodeAndModeFormatted }));
this->m_columns.addColumn(CColumn("latitude", { CAircraft::IndexSituation, CAircraftSituation::IndexLatitude }, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("longitude", { CAircraft::IndexSituation, CAircraftSituation::IndexLongitude }, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("altitude", { CAircraft::IndexSituation, CAircraftSituation::IndexAltitude }, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("groundspeed", { CAircraft::IndexSituation, CAircraftSituation::IndexGroundspeed }, Qt::AlignRight | Qt::AlignVCenter));
// default sort order
this->setSortColumnByPropertyIndex(CAircraft::IndexDistance);

View File

@@ -8,9 +8,13 @@
*/
#include "atcstationlistmodel.h"
#include "blackmisc/voiceroom.h"
#include "blackmisc/nwuser.h"
#include "blackmisc/blackmiscfreefunctions.h"
using namespace BlackMisc::Audio;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Network;
namespace BlackGui
{
@@ -43,14 +47,14 @@ namespace BlackGui
{
case NotSet:
case StationsOnline:
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
this->m_columns.addColumn(CColumn("callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet }));
this->m_columns.addColumn(CColumn(CAtcStation::IndexPixmap, true));
this->m_columns.addColumn(CColumn("distance", CAtcStation::IndexDistance, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, Qt::AlignRight | Qt::AlignVCenter));
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
this->m_columns.addColumn(CColumn("controllername", { CAtcStation::IndexController, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn("bookedfrom", CAtcStation::IndexBookedFrom));
this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil));
this->m_columns.addColumn(CColumn("voiceroomurl", CAtcStation::IndexVoiceRoomUrl));
this->m_columns.addColumn(CColumn("voiceroomurl", { CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }));
// default sort order
this->setSortColumnByPropertyIndex(CAtcStation::IndexDistance);
@@ -58,9 +62,9 @@ namespace BlackGui
break;
case StationsBooked:
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
this->m_columns.addColumn(CColumn("callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet}));
this->m_columns.addColumn(CColumn(CAtcStation::IndexPixmap, true));
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
this->m_columns.addColumn(CColumn("controllername", {CAtcStation::IndexController, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn("bookedfrom", CAtcStation::IndexBookedFrom));
this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil));
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, Qt::AlignRight | Qt::AlignVCenter));

View File

@@ -13,6 +13,7 @@
#include <QMetaProperty>
#include <QBrush>
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackGui
@@ -25,12 +26,13 @@ namespace BlackGui
CClientListModel::CClientListModel(QObject *parent) :
CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>("ViewClientList", parent)
{
this->m_columns.addColumn(CColumn("", CClient::IndexCallsignIcon));
this->m_columns.addColumn(CColumn(CClient::IndexPixmap, true));
this->m_columns.addColumn(CColumn("callsign", CClient::IndexCallsign));
this->m_columns.addColumn(CColumn("realname", CClient::IndexRealName));
this->m_columns.addColumn(CColumn("", CClient::IndexVoiceCapabilitiesPixmap));
this->m_columns.addColumn(CColumn("realname", { CClient::IndexUser, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn(CClient::IndexVoiceCapabilitiesPixmap, true));
this->m_columns.addColumn(CColumn("capabilities", CClient::IndexCapabilitiesString));
this->m_columns.addColumn(CColumn("model", CClient::IndexQueriedModelString));
this->m_columns.addColumn(CColumn("model", {CClient::IndexModel, CAircraftModel::IndexModelString}));
this->m_columns.addColumn(CColumn("queried?", {CClient::IndexModel, CAircraftModel::IndexIsQueriedModelString}));
this->m_columns.addColumn(CColumn("server", CClient::IndexServer));
// force strings for translation in resource files
@@ -41,23 +43,5 @@ namespace BlackGui
(void)QT_TRANSLATE_NOOP("ViewClientList", "model");
(void)QT_TRANSLATE_NOOP("ViewClientList", "server");
}
/*
* Display icons
*/
QVariant CClientListModel::data(const QModelIndex &modelIndex, int role) const
{
// shortcut, fast check
if (role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role);
if (this->columnToPropertyIndex(modelIndex.column()) == CClient::IndexCallsignIcon)
{
if (role == Qt::DecorationRole)
{
CClient u = this->at(modelIndex);
return QVariant(u.toPixmap());
}
}
return CListModelBase::data(modelIndex, role);
}
}
}

View File

@@ -7,6 +7,8 @@
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_CLIENTLISTMODEL_H
#define BLACKGUI_CLIENTLISTMODEL_H
@@ -30,10 +32,6 @@ namespace BlackGui
//! Destructor
virtual ~CClientListModel() {}
//! \copydoc CListModelBase::data
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const;
};
}
}

View File

@@ -15,17 +15,17 @@ namespace BlackGui
{
namespace Models
{
CColumn::CColumn(const QString &headerName, int propertyIndex, int alignment, bool editable) :
CColumn::CColumn(const QString &headerName, const BlackMisc::CPropertyIndex &propertyIndex, int alignment, bool editable) :
m_columnName(headerName), m_alignment(alignment), m_propertyIndex(propertyIndex),
m_editable(editable), m_icon(false)
{}
CColumn::CColumn(const QString &headerName, int propertyIndex, bool editable) :
CColumn::CColumn(const QString &headerName, const BlackMisc::CPropertyIndex &propertyIndex, bool editable) :
m_columnName(headerName), m_alignment(-1), m_propertyIndex(propertyIndex),
m_editable(editable), m_icon(false)
{}
CColumn::CColumn(int propertyIndex, bool isIcon) :
CColumn::CColumn(const BlackMisc::CPropertyIndex &propertyIndex, bool isIcon) :
m_alignment(-1), m_propertyIndex(propertyIndex),
m_editable(false), m_icon(isIcon)
{}
@@ -74,7 +74,7 @@ namespace BlackGui
/*
* Property index to name
*/
QString CColumns::propertyIndexToColumnName(int propertyIndex, bool i18n) const
QString CColumns::propertyIndexToColumnName(const BlackMisc::CPropertyIndex &propertyIndex, bool i18n) const
{
int column = this->propertyIndexToColumn(propertyIndex);
return this->m_columns.at(column).getColumnName(i18n);
@@ -92,7 +92,7 @@ namespace BlackGui
/*
* Get property index
*/
int CColumns::columnToPropertyIndex(int column) const
BlackMisc::CPropertyIndex CColumns::columnToPropertyIndex(int column) const
{
Q_ASSERT(column >= 0 && column < this->m_columns.size());
return this->m_columns.at(column).getPropertyIndex();
@@ -101,12 +101,14 @@ namespace BlackGui
/*
* Property index to column
*/
int CColumns::propertyIndexToColumn(int propertyIndex) const
int CColumns::propertyIndexToColumn(const BlackMisc::CPropertyIndex &propertyIndex) const
{
for (int i = 0; i < this->m_columns.size(); i++)
{
if (this->m_columns.at(i).getPropertyIndex() == propertyIndex)
{
return i;
}
}
return -1;
}
@@ -176,4 +178,4 @@ namespace BlackGui
return this->m_translationContext.toUtf8().constData();
}
}
} // namespace BlackGui
} // namespace

View File

@@ -14,6 +14,7 @@
#include "blackmisc/valueobject.h" // for qHash overload, include before Qt stuff due GCC issue
#include "blackmisc/collection.h"
#include "blackmisc/propertyindex.h"
#include <QObject>
#include <QHash>
@@ -32,23 +33,23 @@ namespace BlackGui
* \param alignment Qt::Alignment
* \param editable
*/
CColumn(const QString &headerName, int propertyIndex, int alignment = -1, bool editable = false);
CColumn(const QString &headerName, const BlackMisc::CPropertyIndex &propertyIndex, int alignment = -1, bool editable = false);
/*!
* \brief Constructor
* Constructor
* \param headerName
* \param propertyIndex as in CValueObject::propertyByIndex
* \param editable
*/
CColumn(const QString &headerName, int propertyIndex, bool editable);
CColumn(const QString &headerName, const BlackMisc::CPropertyIndex &propertyIndex, bool editable);
/*!
* \brief Constructor column is icon
* Constructor column is icon
* \remarks only make sense with isIcon as true
* \param propertyIndex as in CValueObject::propertyByIndex
* \param isIcon icon, should be used with true only
*/
CColumn(int propertyIndex, bool isIcon);
CColumn(const BlackMisc::CPropertyIndex &propertyIndex, bool isIcon);
//! Alignment for this column?
bool hasAlignment() const { return this->m_alignment >= 0; }
@@ -66,7 +67,7 @@ namespace BlackGui
QString getColumnName(bool i18n = false) const;
//! Property index
int getPropertyIndex() const { return this->m_propertyIndex;}
const BlackMisc::CPropertyIndex &getPropertyIndex() const { return this->m_propertyIndex;}
//! Translation context
void setTranslationContext(const QString &translationContext)
@@ -78,7 +79,7 @@ namespace BlackGui
QString m_translationContext;
QString m_columnName;
int m_alignment;
int m_propertyIndex; // property index
BlackMisc::CPropertyIndex m_propertyIndex;
bool m_editable;
bool m_icon;
const char *getTranslationContextChar() const;
@@ -86,13 +87,13 @@ namespace BlackGui
};
/*!
* \brief Header data for a table
* Header data for a table
*/
class CColumns : public QObject
{
public:
/*!
* \brief Columns constructors
* Columns constructors
* \param translationContext
* \param parent
*/
@@ -102,19 +103,19 @@ namespace BlackGui
void addColumn(CColumn column);
//! Property index to name
QString propertyIndexToColumnName(int propertyIndex, bool i18n = false) const;
QString propertyIndexToColumnName(const BlackMisc::CPropertyIndex &propertyIndex, bool i18n = false) const;
//! Column index to name
QString columnToName(int column, bool i18n = false) const;
//! Column to property index
int columnToPropertyIndex(int column) const;
BlackMisc::CPropertyIndex columnToPropertyIndex(int column) const;
//! Property index to column
int propertyIndexToColumn(int propertyIndex) const;
int propertyIndexToColumn(const BlackMisc::CPropertyIndex &propertyIndex) const;
//! Column index to property index
int indexToPropertyIndex(int index) const;
int indexToPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex) const;
//! Column index to name
int nameToPropertyIndex(const QString &name) const;

View File

@@ -56,7 +56,7 @@ namespace BlackGui
{
if (role == Qt::EditRole)
{
int pi = this->indexToPropertyIndex(index);
CSettingKeyboardHotkey::ColumnIndex pi = this->modelIndexToPropertyIndex(index).frontCasted<CSettingKeyboardHotkey::ColumnIndex>();
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
{
if (index.row() >= this->m_container.size()) return true;
@@ -87,7 +87,7 @@ namespace BlackGui
if (index.row() < model->rowCount())
{
int pi = model->indexToPropertyIndex(index);
CSettingKeyboardHotkey::ColumnIndex pi = model->modelIndexToPropertyIndex(index).frontCasted<CSettingKeyboardHotkey::ColumnIndex>();
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
{
CSettingKeyboardHotkey key = model->at(index);

View File

@@ -46,7 +46,7 @@ namespace BlackGui
* Column to property index
*/
template <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::columnToPropertyIndex(int column) const
BlackMisc::CPropertyIndex CListModelBase<ObjectType, ContainerType>::columnToPropertyIndex(int column) const
{
return this->m_columns.columnToPropertyIndex(column);
}
@@ -83,7 +83,7 @@ namespace BlackGui
{
if (this->m_columns.isIcon(index)) return QVariant();
ObjectType obj = this->m_container[index.row()];
int propertyIndex = this->columnToPropertyIndex(index.column());
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
QString propertyString = obj.propertyByIndexAsString(propertyIndex, true);
return QVariant::fromValue(propertyString);
}
@@ -91,7 +91,7 @@ namespace BlackGui
{
if (!this->m_columns.isIcon(index)) return QVariant();
ObjectType obj = this->m_container[index.row()];
int propertyIndex = this->columnToPropertyIndex(index.column());
BlackMisc::CPropertyIndex propertyIndex = this->columnToPropertyIndex(index.column());
return obj.propertyByIndex(propertyIndex);
}
else if (role == Qt::TextAlignmentRole)
@@ -108,7 +108,7 @@ namespace BlackGui
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container)
{
ContainerType copyList = (container.size() > 1 && this->hasValidSortColumn() ?
this->sortListByColumn(container, this->m_sortedColumn, this->m_sortOrder) :
this->sortListByColumn(container, this->getSortColumn(), this->m_sortOrder) :
container);
this->beginResetModel();
this->m_container.clear();
@@ -199,9 +199,9 @@ namespace BlackGui
template <typename ObjectType, typename ContainerType> ContainerType CListModelBase<ObjectType, ContainerType>::sortListByColumn(const ContainerType &list, int column, Qt::SortOrder order)
{
if (list.size() < 2) return list; // nothing to do
int propertyIndex = this->m_columns.columnToPropertyIndex(column);
Q_ASSERT(propertyIndex >= 0);
if (propertyIndex < 0) return list; // at release build do nothing
BlackMisc::CPropertyIndex propertyIndex = this->m_columns.columnToPropertyIndex(column);
Q_ASSERT(!propertyIndex.isEmpty());
if (propertyIndex.isEmpty()) return list; // at release build do nothing
// sort the values
return list.sorted

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_LISTMODELBASE_H
#include "blackgui/models/columns.h"
#include "blackmisc/propertyindex.h"
#include <QAbstractItemModel>
namespace BlackGui
@@ -64,10 +65,10 @@ namespace BlackGui
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
//! Column to property index
virtual int columnToPropertyIndex(int column) const;
virtual BlackMisc::CPropertyIndex columnToPropertyIndex(int column) const;
//! Index to property index
virtual int indexToPropertyIndex(const QModelIndex &index) const
virtual BlackMisc::CPropertyIndex modelIndexToPropertyIndex(const QModelIndex &index) const
{
return this->columnToPropertyIndex(index.column());
}
@@ -79,15 +80,15 @@ namespace BlackGui
}
/*!
* Set column for sort
* Set column for sorting
* \param propertyIndex index of column to be sorted by
*/
virtual void setSortColumnByPropertyIndex(int propertyIndex)
virtual void setSortColumnByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex)
{
this->m_sortedColumn = this->m_columns.propertyIndexToColumn(propertyIndex);
}
//! Get sort column
//! Get sort column property index
virtual int getSortColumn() const
{
return this->m_sortedColumn;
@@ -96,7 +97,7 @@ namespace BlackGui
//! Has valid sort column?
virtual bool hasValidSortColumn() const
{
return this->m_sortedColumn >= 0 && this->m_sortedColumn < this->m_columns.size();
return this->m_sortedColumn >=0 && this->m_sortedColumn < this->m_columns.size();
}
//! Get sort order

View File

@@ -25,8 +25,8 @@ namespace BlackGui
this->m_columns.addColumn(CColumn("description", CServer::IndexDescription));
this->m_columns.addColumn(CColumn("address", CServer::IndexAddress));
this->m_columns.addColumn(CColumn("port", CServer::IndexPort));
this->m_columns.addColumn(CColumn("realname", CServer::IndexUserRealName));
this->m_columns.addColumn(CColumn("userid", CServer::IndexUserId));
this->m_columns.addColumn(CColumn("realname", { CServer::IndexUser, CUser::IndexRealName}));
this->m_columns.addColumn(CColumn("userid", { CServer::IndexUser, CUser::IndexId}));
// force strings for translation in resource files
(void)QT_TRANSLATE_NOOP("ViewServerList", "name");

View File

@@ -44,7 +44,7 @@ namespace BlackGui
{
case NotSet:
case UserDetailed:
this->m_columns.addColumn(CColumn(CUser::IndexCallsignPixmap, true));
this->m_columns.addColumn(CColumn(CUser::IndexPixmap, true));
this->m_columns.addColumn(CColumn("realname", CUser::IndexRealName));
this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign));
this->m_columns.addColumn(CColumn("userid", CUser::IndexId));
@@ -52,7 +52,7 @@ namespace BlackGui
break;
case UserShort:
this->m_columns.addColumn(CColumn(CUser::IndexCallsignPixmap, true));
this->m_columns.addColumn(CColumn(CUser::IndexPixmap, true));
this->m_columns.addColumn(CColumn("realname", CUser::IndexRealName));
this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign));
break;

View File

@@ -21,7 +21,7 @@ namespace BlackGui
{
this->m_model = new CClientListModel(this);
this->setModel(this->m_model); // via QTableView
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Network::CClient::IndexRealName);
this->m_model->setSortColumnByPropertyIndex( { BlackMisc::Network::CClient::IndexUser, BlackMisc::Network::CUser::IndexRealName });
if (this->m_model->hasValidSortColumn())
this->horizontalHeader()->setSortIndicator(
this->m_model->getSortColumn(),

View File

@@ -304,14 +304,11 @@ namespace BlackMisc
return CKeyboardKey::equalsModifierReleaxed(this->getModifier1(), key.getModifier1());
}
bool CKeyboardKey::equalsWithoutFunction(const CKeyboardKey &key) const
QString CKeyboardKey::toStringRepresentation(int key)
{
if (key == (*this)) return true;
CKeyboardKey k1(*this);
CKeyboardKey k2(*this);
k1.setFunction(HotkeyNone);
k2.setFunction(HotkeyNone);
return k1 == k2;
if (key == 0) return "";
QString ks = QKeySequence(key).toString();
return ks;
}
QVariant CKeyboardKey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
@@ -343,14 +340,6 @@ namespace BlackMisc
return QVariant::fromValue(m);
}
QString CKeyboardKey::toStringRepresentation(int key)
{
if (key == 0) return "";
QString ks = QKeySequence(key).toString();
// ks.append('(').append(QString::number(key)).append(')');
return ks;
}
void CKeyboardKey::setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself())