diff --git a/src/blackgui/aircraftlistmodel.cpp b/src/blackgui/aircraftlistmodel.cpp deleted file mode 100644 index 0f8b0e01e..000000000 --- a/src/blackgui/aircraftlistmodel.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "aircraftlistmodel.h" -#include "blackmisc/avaircraftsituation.h" -#include "blackmisc/blackmiscfreefunctions.h" - -using namespace BlackMisc::Aviation; - -namespace BlackGui -{ - /* - * Constructor - */ - 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("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::IndexPositionLatitude, Qt::AlignRight | Qt::AlignVCenter)); - this->m_columns.addColumn(CColumn("longitude", CAircraftSituation::IndexPositionLongitude, 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)); - - // default sort order - this->setSortColumnByPropertyIndex(CAircraft::IndexDistance); - this->m_sortOrder = Qt::AscendingOrder; - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "callsign"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "pilotrealname"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "latitude"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "longitude"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "altitude"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "distance"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "height"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "transponder"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "groundspeed"); - (void)QT_TRANSLATE_NOOP("ViewAircraftList", "model"); - } -} diff --git a/src/blackgui/aircraftlistmodel.h b/src/blackgui/aircraftlistmodel.h deleted file mode 100644 index b3aff9f5a..000000000 --- a/src/blackgui/aircraftlistmodel.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKGUI_AIRCRAFTLISTMODEL_H -#define BLACKGUI_AIRCRAFTLISTMODEL_H - -#include "blackmisc/avaircraftlist.h" -#include "blackgui/listmodelbase.h" -#include -#include - -namespace BlackGui -{ - /*! - * Aircraft list model - */ - class CAircraftListModel : public CListModelBase - { - - public: - - //! Constructor - explicit CAircraftListModel(QObject *parent = nullptr); - - //! Destructor - virtual ~CAircraftListModel() {} - - }; -} -#endif // guard diff --git a/src/blackgui/airportlistmodel.cpp b/src/blackgui/airportlistmodel.cpp deleted file mode 100644 index f5daa67c3..000000000 --- a/src/blackgui/airportlistmodel.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "airportlistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include - -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Geo; - -namespace BlackGui -{ - /* - * Constructor - */ - CAirportListModel::CAirportListModel(QObject *parent) : - CListModelBase("ViewAirportList", parent) - { - this->m_columns.addColumn(CColumn("ICAO", CAirport::IndexIcao)); - this->m_columns.addColumn(CColumn("distance", CAirport::IndexDistance, Qt::AlignRight | Qt::AlignVCenter)); - this->m_columns.addColumn(CColumn("bearing", CAirport::IndexBearing, Qt::AlignRight | Qt::AlignVCenter)); - this->m_columns.addColumn(CColumn("name", CAirport::IndexDescriptiveName)); - this->m_columns.addColumn(CColumn("elevation", CAirport::IndexElevation, Qt::AlignRight | Qt::AlignVCenter)); - this->m_columns.addColumn(CColumn("latitude", CCoordinateGeodetic::IndexLatitude, Qt::AlignRight | Qt::AlignVCenter)); - this->m_columns.addColumn(CColumn("longitude", CCoordinateGeodetic::IndexLongitude, Qt::AlignRight | Qt::AlignVCenter)); - - // default sort order - this->setSortColumnByPropertyIndex(CAirport::IndexDistance); - this->m_sortOrder = Qt::AscendingOrder; - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewAirportList", "ICAO"); - (void)QT_TRANSLATE_NOOP("ViewAirportList", "distance"); - (void)QT_TRANSLATE_NOOP("ViewAirportList", "name"); - (void)QT_TRANSLATE_NOOP("ViewAirportList", "elevation"); - (void)QT_TRANSLATE_NOOP("ViewAirportList", "bearing"); - } -} diff --git a/src/blackgui/airportlistmodel.h b/src/blackgui/airportlistmodel.h deleted file mode 100644 index 4d296a895..000000000 --- a/src/blackgui/airportlistmodel.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BLACKGUI_AIRPORTLISTMODEL_H -#define BLACKGUI_AIRPORTLISTMODEL_H - -#include -#include "blackmisc/avairportlist.h" -#include "blackgui/listmodelbase.h" - -namespace BlackGui -{ - /*! - * Airport list model - */ - class CAirportListModel : public CListModelBase - { - - public: - - //! Constructor - explicit CAirportListModel(QObject *parent = nullptr); - - //! Destructor - virtual ~CAirportListModel() {} - }; -} -#endif // guard diff --git a/src/blackgui/atcstationlistmodel.cpp b/src/blackgui/atcstationlistmodel.cpp deleted file mode 100644 index 437b55d67..000000000 --- a/src/blackgui/atcstationlistmodel.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "atcstationlistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" - -using namespace BlackMisc::Aviation; - -namespace BlackGui -{ - /* - * Constructor - */ - CAtcStationListModel::CAtcStationListModel(AtcStationMode stationMode, QObject *parent) : - CListModelBase("ViewAtcList", parent), m_stationMode(NotSet) - { - this->setStationMode(stationMode); - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewAtcList", "callsign"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "distance"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "frequency"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "controllername"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "online"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookedfrom"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookeduntil"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "voiceroomurl"); - } - - void CAtcStationListModel::setStationMode(CAtcStationListModel::AtcStationMode stationMode) - { - if (this->m_stationMode == stationMode) return; - this->m_stationMode = stationMode; - this->m_columns.clear(); - switch (stationMode) - { - case NotSet: - case StationsOnline: - this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet)); - this->m_columns.addColumn(CColumn(CAtcStation::IndexCallsignIcon, 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("bookedfrom", CAtcStation::IndexBookedFrom)); - this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil)); - this->m_columns.addColumn(CColumn("voiceroomurl", CAtcStation::IndexVoiceRoomUrl)); - - // default sort order - this->setSortColumnByPropertyIndex(CAtcStation::IndexDistance); - this->m_sortOrder = Qt::AscendingOrder; - break; - - case StationsBooked: - this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet)); - this->m_columns.addColumn(CColumn(CAtcStation::IndexCallsignIcon, true)); - this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName)); - 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)); - this->m_columns.addColumn(CColumn("online", CAtcStation::IndexIsOnline)); - - // default sort order - this->setSortColumnByPropertyIndex(CAtcStation::IndexBookedFrom); - this->m_sortOrder = Qt::AscendingOrder; - break; - - default: - qFatal("Wrong mode"); - break; - } - } - - void CAtcStationListModel::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) - { - if (station.getCallsign().isEmpty()) return; - if (added) - { - if (this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign())) - { - this->m_container.replaceIf(&CAtcStation::getCallsign, station.getCallsign(), station); - } - else - { - this->insert(station); - } - } - else - { - beginRemoveRows(QModelIndex(), 0, 0); - this->m_container.removeIf(&CAtcStation::getCallsign, station.getCallsign()); - endRemoveRows(); - } - } -} diff --git a/src/blackgui/atcstationlistmodel.h b/src/blackgui/atcstationlistmodel.h deleted file mode 100644 index 5894342d6..000000000 --- a/src/blackgui/atcstationlistmodel.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/*! - \file -*/ - -#ifndef BLACKGUI_ATCLISTMODEL_H -#define BLACKGUI_ATCLISTMODEL_H - -#include "blackmisc/avatcstationlist.h" -#include "blackgui/listmodelbase.h" -#include -#include - -namespace BlackGui -{ - /*! - * \brief ATC list model - */ - class CAtcStationListModel : public CListModelBase - { - - public: - //! What kind of stations - enum AtcStationMode - { - NotSet, - StationsBooked, - StationsOnline - }; - - //! Constructor - explicit CAtcStationListModel(AtcStationMode stationMode, QObject *parent = nullptr); - - //! Destructor - virtual ~CAtcStationListModel() {} - - //! Set station mode - void setStationMode(AtcStationMode stationMode); - - public slots: - //! Used to quickly update single station (better response for the user) - void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); - - private: - AtcStationMode m_stationMode; - }; -} -#endif // guard diff --git a/src/blackgui/clientlistmodel.cpp b/src/blackgui/clientlistmodel.cpp deleted file mode 100644 index 29ebda324..000000000 --- a/src/blackgui/clientlistmodel.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "clientlistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include - -using namespace BlackMisc::Network; - -namespace BlackGui -{ - /* - * Constructor - */ - CClientListModel::CClientListModel(QObject *parent) : - CListModelBase("ViewClientList", parent) - { - this->m_columns.addColumn(CColumn("", CClient::IndexCallsignIcon)); - this->m_columns.addColumn(CColumn("callsign", CClient::IndexCallsign)); - this->m_columns.addColumn(CColumn("realname", CClient::IndexRealName)); - this->m_columns.addColumn(CColumn("", CClient::IndexVoiceCapabilitiesIcon)); - this->m_columns.addColumn(CColumn("capabilities", CClient::IndexCapabilitiesString)); - this->m_columns.addColumn(CColumn("model", CClient::IndexQueriedModelString)); - this->m_columns.addColumn(CColumn("server", CClient::IndexServer)); - - // force strings for translation in resource files - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewClientList", "callsign"); - (void)QT_TRANSLATE_NOOP("ViewClientList", "realname"); - (void)QT_TRANSLATE_NOOP("ViewClientList", "userid"); - (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 u.toIcon(); - } - } - return CListModelBase::data(modelIndex, role); - } -} diff --git a/src/blackgui/clientlistmodel.h b/src/blackgui/clientlistmodel.h deleted file mode 100644 index 37ad07e1d..000000000 --- a/src/blackgui/clientlistmodel.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef BLACKGUI_CLIENTLISTMODEL_H -#define BLACKGUI_CLIENTLISTMODEL_H - -#include -#include "blackmisc/nwclientlist.h" -#include "blackgui/listmodelbase.h" - -namespace BlackGui -{ - /*! - * \brief Server list model - */ - class CClientListModel : public CListModelBase - { - - public: - - //! \brief Constructor - explicit CClientListModel(QObject *parent = nullptr); - - //! \brief Destructor - virtual ~CClientListModel() {} - - //! \copydoc CListModelBase::data - QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const; - - }; -} -#endif // guard diff --git a/src/blackgui/columns.cpp b/src/blackgui/columns.cpp deleted file mode 100644 index 222769233..000000000 --- a/src/blackgui/columns.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "columns.h" -#include -#include - -namespace BlackGui -{ - CColumn::CColumn(const QString &headerName, int 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) : - m_columnName(headerName), m_alignment(-1), m_propertyIndex(propertyIndex), - m_editable(editable), m_icon(false) - {} - - CColumn::CColumn(int propertyIndex, bool isIcon) : - m_alignment(-1), m_propertyIndex(propertyIndex), - m_editable(false), m_icon(isIcon) - {} - - const char *CColumn::getTranslationContextChar() const - { - return this->m_translationContext.toUtf8().constData(); - } - - const char *CColumn::getColumnNameChar() const - { - return this->m_columnName.toUtf8().constData(); - } - - QVariant CColumn::aligmentAsQVariant() const - { - if (this->hasAlignment()) return QVariant(this->m_alignment); - return QVariant(Qt::AlignVCenter | Qt::AlignLeft); // default - } - - QString CColumn::getColumnName(bool i18n) const - { - if (!i18n || this->m_translationContext.isEmpty()) return this->m_columnName; - return QCoreApplication::translate(this->getTranslationContextChar(), this->getColumnNameChar()); - } - - /* - * Header - */ - CColumns::CColumns(const QString &translationContext, QObject *parent) : - QObject(parent), m_translationContext(translationContext) - { - // void - } - - /* - * Add column - */ - void CColumns::addColumn(CColumn column) - { - Q_ASSERT(!this->m_translationContext.isEmpty()); - column.setTranslationContext(this->m_translationContext); - this->m_columns.push_back(column); - } - - /* - * Property index to name - */ - QString CColumns::propertyIndexToColumnName(int propertyIndex, bool i18n) const - { - int column = this->propertyIndexToColumn(propertyIndex); - return this->m_columns.at(column).getColumnName(i18n); - } - - /* - * Index to name - */ - QString CColumns::columnToName(int column, bool i18n) const - { - Q_ASSERT(column >= 0 && column < this->m_columns.size()); - return this->m_columns.at(column).getColumnName(i18n); - } - - /* - * Get property index - */ - int CColumns::columnToPropertyIndex(int column) const - { - Q_ASSERT(column >= 0 && column < this->m_columns.size()); - return this->m_columns.at(column).getPropertyIndex(); - } - - /* - * Property index to column - */ - int CColumns::propertyIndexToColumn(int propertyIndex) const - { - for (int i = 0; i < this->m_columns.size(); i++) - { - if (this->m_columns.at(i).getPropertyIndex() == propertyIndex) - return i; - } - return -1; - } - - /* - * Name to property index - */ - int CColumns::nameToPropertyIndex(const QString &name) const - { - for (int i = 0; i < this->m_columns.size(); i++) - { - if (this->m_columns.at(i).getColumnName(false) == name) - return i; - } - return -1; - } - - /* - * Size - */ - int CColumns::size() const - { - return this->m_columns.size(); - } - - /* - * Alignment? - */ - bool CColumns::hasAlignment(const QModelIndex &index) const - { - if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; - return this->m_columns.at(index.column()).hasAlignment(); - } - - /* - * Editable? - */ - bool CColumns::isEditable(const QModelIndex &index) const - { - if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; - return this->m_columns.at(index.column()).isEditable(); - } - - /* - * Is icon? - */ - bool CColumns::isIcon(const QModelIndex &index) const - { - if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; - return this->m_columns.at(index.column()).isIcon(); - } - - /* - * Aligment as QVariant - */ - QVariant CColumns::aligmentAsQVariant(const QModelIndex &index) const - { - if (index.column() < 0 || index.column() >= this->m_columns.size()) return QVariant(); - return this->m_columns.at(index.column()).aligmentAsQVariant(); - } - - /* - * Context - */ - const char *CColumns::getTranslationContextChar() const - { - return this->m_translationContext.toUtf8().constData(); - } - -} // namespace BlackGui diff --git a/src/blackgui/columns.h b/src/blackgui/columns.h deleted file mode 100644 index d5f553c48..000000000 --- a/src/blackgui/columns.h +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/*! - \file -*/ - -#ifndef BLACKGUI_COLUMNS_H -#define BLACKGUI_COLUMNS_H - -#include "blackmisc/valueobject.h" // for qHash overload, include before Qt stuff due GCC issue -#include "blackmisc/collection.h" -#include -#include - -namespace BlackGui -{ - //! Single column - class CColumn - { - public: - /*! - * \brief Constructor - * \param headerName - * \param propertyIndex as in CValueObject::propertyByIndex - * \param alignment Qt::Alignment - * \param editable - */ - CColumn(const QString &headerName, int propertyIndex, int alignment = -1, bool editable = false); - - /*! - * \brief Constructor - * \param headerName - * \param propertyIndex as in CValueObject::propertyByIndex - * \param editable - */ - CColumn(const QString &headerName, int propertyIndex, bool editable); - - /*! - * \brief 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); - - //! Alignment for this column? - bool hasAlignment() const { return this->m_alignment >= 0; } - - //! Editable? - bool isEditable() const { return this->m_editable; } - - //! Icon? - bool isIcon() const { return this->m_icon; } - - //! Aligment as QVariant - QVariant aligmentAsQVariant() const; - - //! Column name - QString getColumnName(bool i18n = false) const; - - //! Property index - int getPropertyIndex() const { return this->m_propertyIndex;} - - //! Translation context - void setTranslationContext(const QString &translationContext) - { - this->m_translationContext = translationContext; - } - - private: - QString m_translationContext; - QString m_columnName; - int m_alignment; - int m_propertyIndex; // property index - bool m_editable; - bool m_icon; - const char *getTranslationContextChar() const; - const char *getColumnNameChar() const; - }; - - /*! - * \brief Header data for a table - */ - class CColumns : public QObject - { - public: - /*! - * \brief Columns constructors - * \param translationContext - * \param parent - */ - CColumns(const QString &translationContext, QObject *parent = nullptr); - - //! Add a column - void addColumn(CColumn column); - - //! Property index to name - QString propertyIndexToColumnName(int 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; - - //! Property index to column - int propertyIndexToColumn(int propertyIndex) const; - - //! Column index to property index - int indexToPropertyIndex(int index) const; - - //! Column index to name - int nameToPropertyIndex(const QString &name) const; - - //! Size (number of columns) - int size() const; - - //! Alignment for this column? - bool hasAlignment(const QModelIndex &index) const; - - //! Is this column editable? - bool isEditable(const QModelIndex &index) const; - - //! Is icon? - bool isIcon(const QModelIndex &index) const; - - //! Aligment as QVariant - QVariant aligmentAsQVariant(const QModelIndex &index) const; - - //! Column at position - const CColumn &at(int columnNumber) const { return this->m_columns.at(columnNumber); } - - //! Clear - void clear() { this->m_columns.clear(); } - - private: - QList m_columns; - QString m_translationContext; - const char *getTranslationContextChar() const; - }; - -} // namespace BlackGui - -#endif // guard diff --git a/src/blackgui/keyboardkeylistmodel.cpp b/src/blackgui/keyboardkeylistmodel.cpp deleted file mode 100644 index 6e6f2d3a4..000000000 --- a/src/blackgui/keyboardkeylistmodel.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include "keyboardkeylistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include -#include -#include -#include - - -using namespace BlackMisc::Hardware; - -namespace BlackGui -{ - /* - * Constructor - */ - CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) : - CListModelBase("ViewKeyboardKeyList", parent) - { - this->m_columns.addColumn(CColumn("key", CKeyboardKey::IndexKeyAsStringRepresentation, true)); - this->m_columns.addColumn(CColumn("modifier 1", CKeyboardKey::IndexModifier1AsString, true)); - this->m_columns.addColumn(CColumn("modifier 2", CKeyboardKey::IndexModifier2AsString, true)); - this->m_columns.addColumn(CColumn("function", CKeyboardKey::IndexFunctionAsString)); - - this->setSortColumnByPropertyIndex(CKeyboardKey::IndexFunctionAsString); - this->m_sortOrder = Qt::AscendingOrder; - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 1"); - (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 2"); - (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "function"); - (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "key"); - } - - /* - * Display icons - */ - QVariant CKeyboardKeyListModel::data(const QModelIndex &modelIndex, int role) const - { - // shortcut, fast check - return CListModelBase::data(modelIndex, role); - } - - bool CKeyboardKeyListModel::setData(const QModelIndex &index, const QVariant &value, int role) - { - if (role == Qt::EditRole) - { - int pi = this->indexToPropertyIndex(index); - if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) - { - if (index.row() >= this->m_container.size()) return true; - CKeyboardKey key = this->m_container[index.row()]; - key.setPropertyByIndex(value, pi); - key.cleanup(); - this->m_container[index.row()] = key; - return true; - } - else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) - { - Q_ASSERT(value.canConvert()); - if (index.row() >= this->m_container.size()) return true; - CKeyboardKey key = this->m_container[index.row()]; - key.setPropertyByIndex(value, CKeyboardKey::IndexKeyObject); - key.cleanup(); - this->m_container[index.row()] = key; - return true; - } - } - return CListModelBase::setData(index, value, role); - } - - QWidget *CKeyboardKeyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const - { - const CKeyboardKeyListModel *model = this->model(); - Q_ASSERT(model); - - if (index.row() < model->rowCount()) - { - int pi = model->indexToPropertyIndex(index); - if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) - { - CKeyboardKey key = model->at(index); - QString v = (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString(); - QComboBox *edit = new QComboBox(parent); - edit->addItems(CKeyboardKey::modifiers()); - edit->setCurrentText(v); - return edit; - } - else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) - { - CKeyboardKey key = model->at(index); - CKeyboardLineEdit *edit = new CKeyboardLineEdit(key, parent); - edit->setText(key.getKeyAsString()); - return edit; - } - } - return QItemDelegate::createEditor(parent, option, index); - } - - void CKeyboardKeyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const - { - QItemDelegate::setEditorData(editor, index); - } - - void CKeyboardKeyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const - { - // with our own line edit we have a special treatment - // otherwise (comboboxes) standard handling via QItemDelegate - CKeyboardLineEdit *lineEdit = qobject_cast(editor); - if (lineEdit) - model->setData(index, lineEdit->getKey().toQVariant() , Qt::EditRole); - else - QItemDelegate::setModelData(editor, model, index); - } - - void CKeyboardKeyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const - { - QItemDelegate::updateEditorGeometry(editor, option, index); - } - - const CKeyboardKeyListModel *CKeyboardKeyItemDelegate::model() const - { - if (this->parent()) - { - QTableView *tableView = dynamic_cast(this->parent()); - if (tableView) - { - return dynamic_cast(tableView->model()); - } - } - return nullptr; - } - - void CKeyboardLineEdit::keyPressEvent(QKeyEvent *event) - { - const Qt::Key k = static_cast(event->key()); - if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return; - this->m_key.setKey(k); - this->m_key.setNativeVirtualKey(event->nativeVirtualKey()); - this->setText(CKeyboardKey::toStringRepresentation(event->key())); - } - -} // namespace diff --git a/src/blackgui/keyboardkeylistmodel.h b/src/blackgui/keyboardkeylistmodel.h deleted file mode 100644 index 9feb544f7..000000000 --- a/src/blackgui/keyboardkeylistmodel.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef BLACKGUI_KEYBOARDKEYLISTMODEL_H -#define BLACKGUI_KEYBOARDKEYLISTMODEL_H - -#include "blackmisc/hwkeyboardkeylist.h" -#include "blackgui/listmodelbase.h" -#include -#include -#include -#include - -namespace BlackGui -{ - /*! - * \brief Keyboard key list model - */ - class CKeyboardKeyListModel : public CListModelBase - { - - public: - - //! \brief Constructor - explicit CKeyboardKeyListModel(QObject *parent = nullptr); - - //! \brief Destructor - virtual ~CKeyboardKeyListModel() {} - - //! \copydoc CListModelBase::data - QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override; - - //! \copydoc CKeyboardKeyList::initAsHotkeyList(bool reset) - void initAsHotkeyList() { this->m_container.initAsHotkeyList(); } - - //! \copydoc QAbstractTableModel::setData - virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override; - }; - - /*! - * \brief Special edit delegate for key sequence - */ - class CKeyboardKeyItemDelegate : public QItemDelegate - { - Q_OBJECT - - public: - //! \brief Constructor - explicit CKeyboardKeyItemDelegate(QObject *parent = nullptr) : - QItemDelegate(parent) {} - - //! \copydoc QItemDelegate::createEditor - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - - //! \copydoc QItemDelegate::setEditorData - virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override; - - //! \copydoc QItemDelegate::setModelData - virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; - - //! \copydoc QItemDelegate::updateEditorGeometry - virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - - //! \brief correspondig model - const CKeyboardKeyListModel *model() const; - }; - - /*! - * \brief Special edit widget for key sequence - */ - class CKeyboardLineEdit : public QLineEdit - { - Q_OBJECT - - public: - //! Constructor - CKeyboardLineEdit(BlackMisc::Hardware::CKeyboardKey &key, QWidget *parent = nullptr) : - QLineEdit(parent), m_key(key) { } - - //! \brief get key - BlackMisc::Hardware::CKeyboardKey getKey() const { return this->m_key; } - - protected: - //! \brief Overriding and handling key press - virtual void keyPressEvent(QKeyEvent *event) override; - - private: - BlackMisc::Hardware::CKeyboardKey m_key; - }; -} -#endif // guard diff --git a/src/blackgui/listmodelbase.cpp b/src/blackgui/listmodelbase.cpp deleted file mode 100644 index 2606ab060..000000000 --- a/src/blackgui/listmodelbase.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "listmodelbase.h" -#include "blackmisc/statusmessagelist.h" -#include "blackmisc/avatcstationlist.h" -#include "blackmisc/avaircraftlist.h" -#include "blackmisc/avairportlist.h" -#include "blackmisc/nwserverlist.h" -#include "blackmisc/nwuserlist.h" -#include "blackmisc/nwclientlist.h" -#include "blackmisc/hwkeyboardkeylist.h" -#include "blackmisc/blackmiscfreefunctions.h" - -namespace BlackGui -{ - - /* - * Column count - */ - template - int CListModelBase::columnCount(const QModelIndex & /** modelIndex **/) const - { - int c = this->m_columns.size(); - return c; - } - - /* - * Row count - */ - template - int CListModelBase::rowCount(const QModelIndex & /** parent */) const - { - return this->m_container.size(); - } - - /* - * Column to property index - */ - template - int CListModelBase::columnToPropertyIndex(int column) const - { - return this->m_columns.columnToPropertyIndex(column); - } - - /* - * Header data - */ - template QVariant - CListModelBase::headerData(int section, Qt::Orientation orientation, int role) const - { - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) - { - if (section < 0 || section >= this->m_columns.size()) return QVariant(); - QString header = this->m_columns.at(section).getColumnName(false); - return QVariant(header); - } - return QVariant(); - } - - /* - * Data - */ - template - QVariant CListModelBase::data(const QModelIndex &index, int role) const - { - // checks - if (index.row() < 0 || index.row() >= this->m_container.size() || - index.column() < 0 || index.column() >= this->columnCount(index)) - { - return QVariant(); - } - - if (role == Qt::DisplayRole) - { - if (this->m_columns.isIcon(index)) return QVariant(); - ObjectType obj = this->m_container[index.row()]; - int propertyIndex = this->columnToPropertyIndex(index.column()); - QString propertyString = obj.propertyByIndexAsString(propertyIndex, true); - return QVariant::fromValue(propertyString); - } - else if (role == Qt::DecorationRole) - { - if (!this->m_columns.isIcon(index)) return QVariant(); - ObjectType obj = this->m_container[index.row()]; - int propertyIndex = this->columnToPropertyIndex(index.column()); - return obj.propertyByIndex(propertyIndex); - } - else if (role == Qt::TextAlignmentRole) - { - return this->m_columns.aligmentAsQVariant(index); - } - return QVariant(); - } - - /* - * Update - */ - template - int CListModelBase::update(const ContainerType &container) - { - ContainerType copyList = (container.size() > 1 && this->hasValidSortColumn() ? - this->sortListByColumn(container, this->m_sortedColumn, this->m_sortOrder) : - container); - this->beginResetModel(); - this->m_container.clear(); - foreach(ObjectType object, copyList) - { - this->m_container.push_back(object); - } - this->endResetModel(); - return this->m_container.size(); - } - - - /* - * Update - */ - template - void CListModelBase::update(const QModelIndex &index, const ObjectType &object) - { - if (index.row() >= this->m_container.size()) return; - this->m_container[index.row()] = object; - - QModelIndex i1 = index.sibling(index.row(), 0); - QModelIndex i2 = index.sibling(index.row(), this->columnCount(index) - 1); - emit this->dataChanged(i1, i2); // which range has been changed - } - - /* - * Push back - */ - template - void CListModelBase::push_back(const ObjectType &object) - { - beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size()); - this->m_container.push_back(object); - endInsertRows(); - } - - /* - * Push back - */ - template - void CListModelBase::insert(const ObjectType &object) - { - beginInsertRows(QModelIndex(), 0, 0); - this->m_container.insert(this->m_container.begin(), object); - endInsertRows(); - } - - /* - * Remove object - */ - template - void CListModelBase::remove(const ObjectType &object) - { - beginRemoveRows(QModelIndex(), 0, 0); - this->m_container.remove(object); - endRemoveRows(); - } - - /* - * Clear - */ - template - void CListModelBase::clear() - { - beginResetModel(); - this->m_container.clear(); - endResetModel(); - } - - /* - * Sort - */ - template void CListModelBase::sort(int column, Qt::SortOrder order) - { - this->m_sortedColumn = column; - this->m_sortOrder = order; - if (this->m_container.size() < 2) return; // nothing to do - - // sort the values - this->update( - this->sortListByColumn(this->m_container, column, order) - ); - } - - /* - * Sort list - */ - template ContainerType CListModelBase::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 - - // sort the values - return list.sorted - ([ = ](const ObjectType & a, const ObjectType & b) -> bool - { - QVariant aQv = a.propertyByIndex(propertyIndex); - QVariant bQv = b.propertyByIndex(propertyIndex); - int compare = (order == Qt::AscendingOrder) ? - BlackMisc::compareQVariants(aQv, bQv) : - BlackMisc::compareQVariants(bQv, aQv); - return compare < 0; - } - ); // sorted - } - - /* - * Make editable - */ - template Qt::ItemFlags CListModelBase::flags(const QModelIndex &index) const - { - Qt::ItemFlags f = QAbstractListModel::flags(index); - if (this->m_columns.isEditable(index)) - return f | Qt::ItemIsEditable; - else - return f; - } - - // see here for the reason of thess forward instantiations - // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - template class CListModelBase; - -} // namespace diff --git a/src/blackgui/listmodelbase.h b/src/blackgui/listmodelbase.h deleted file mode 100644 index 6dabb15e9..000000000 --- a/src/blackgui/listmodelbase.h +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKGUI_LISTMODELBASE_H -#define BLACKGUI_LISTMODELBASE_H - -#include "blackgui/columns.h" -#include - -namespace BlackGui -{ - /*! - * \brief List model - */ - template class CListModelBase : public QAbstractListModel - { - - protected: - ContainerType m_container; //!< used container - CColumns m_columns; //!< columns metadata - int m_sortedColumn; //!< current sort column - Qt::SortOrder m_sortOrder; //!< sort order (asc/desc) - - /*! - * \brief Constructor - * \param translationContext I18N context - * \param parent - */ - CListModelBase(const QString &translationContext, QObject *parent = nullptr) - : QAbstractListModel(parent), m_columns(translationContext), m_sortedColumn(-1), m_sortOrder(Qt::AscendingOrder) - { - // void - } - - /*! - * \brief Sort list by given order - * \param list used list - * \param column column inder - * \param order sort order (asccending / descending) - * \return - */ - ContainerType sortListByColumn(const ContainerType &list, int column, Qt::SortOrder order); - - public: - - //! \brief Destructor - virtual ~CListModelBase() {} - - //! \copydoc QAbstractListModel::columnCount() - virtual int columnCount(const QModelIndex &modelIndex) const override; - - //! \copydoc QAbstractItemModel::headerData() - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - //! Column to property index - virtual int columnToPropertyIndex(int column) const; - - //! Index to property index - virtual int indexToPropertyIndex(const QModelIndex &index) const - { - return this->columnToPropertyIndex(index.column()); - } - - //! Set sort column - virtual void setSortColumn(int column) - { - this->m_sortedColumn = column; - } - - /*! - * \brief Set column for sort - * \param propertyIndex index of column to be sorted by - */ - virtual void setSortColumnByPropertyIndex(int propertyIndex) - { - this->m_sortedColumn = this->m_columns.propertyIndexToColumn(propertyIndex); - } - - //! Get sort column - virtual int getSortColumn() const - { - return this->m_sortedColumn; - } - - //! Has valid sort column? - virtual bool hasValidSortColumn() const - { - return this->m_sortedColumn >= 0 && this->m_sortedColumn < this->m_columns.size(); - } - - //! Get sort order - virtual Qt::SortOrder getSortOrder() const - { - return this->m_sortOrder; - } - - //! Used container data - virtual const ContainerType &getContainer() const - { - return this->m_container; - } - - //! \copydoc QAbstractListModel::data() - virtual QVariant data(const QModelIndex &index, int role) const override; - - //! \copydoc QAbstractListModel::rowCount() - virtual int rowCount(const QModelIndex &index = QModelIndex()) const override; - - //! \copydoc QAbstractTableModel::flags - Qt::ItemFlags flags(const QModelIndex &index) const override; - - //! Update by new list - virtual int update(const ContainerType &container); - - //! Update single element - virtual void update(const QModelIndex &index, const ObjectType &object); - - //! Object at row position - virtual const ObjectType &at(const QModelIndex &index) const - { - if (index.row() < 0 || index.row() >= this->m_container.size()) - { - const static ObjectType def; - return def; - } - else - { - return this->m_container[index.row()]; - } - } - - //! \copydoc QAbstractListModel::sort() - virtual void sort(int column, Qt::SortOrder order); - - //! Similar to ContainerType::push_back - virtual void push_back(const ObjectType &object); - - //! Similar to ContainerType::insert here inserts at first position - virtual void insert(const ObjectType &object); - - //! Remove object - virtual void remove(const ObjectType &object); - - //! Clear the list - virtual void clear(); -}; -} -#endif // guard diff --git a/src/blackgui/models/aircraftlistmodel.cpp b/src/blackgui/models/aircraftlistmodel.cpp new file mode 100644 index 000000000..06af45035 --- /dev/null +++ b/src/blackgui/models/aircraftlistmodel.cpp @@ -0,0 +1,53 @@ +/* Copyright (C) 2013 + * Swift Project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "aircraftlistmodel.h" +#include "blackmisc/avaircraftsituation.h" +#include "blackmisc/blackmiscfreefunctions.h" + +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + 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("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::IndexPositionLatitude, Qt::AlignRight | Qt::AlignVCenter)); + this->m_columns.addColumn(CColumn("longitude", CAircraftSituation::IndexPositionLongitude, 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)); + + // default sort order + this->setSortColumnByPropertyIndex(CAircraft::IndexDistance); + this->m_sortOrder = Qt::AscendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "callsign"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "pilotrealname"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "latitude"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "longitude"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "altitude"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "distance"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "height"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "transponder"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "groundspeed"); + (void)QT_TRANSLATE_NOOP("ViewAircraftList", "model"); + } + } +} diff --git a/src/blackgui/models/aircraftlistmodel.h b/src/blackgui/models/aircraftlistmodel.h new file mode 100644 index 000000000..652aeb619 --- /dev/null +++ b/src/blackgui/models/aircraftlistmodel.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2013 + * Swift Project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_AIRCRAFTLISTMODEL_H +#define BLACKGUI_AIRCRAFTLISTMODEL_H + +#include "blackmisc/avaircraftlist.h" +#include "blackgui/models/listmodelbase.h" +#include +#include + +namespace BlackGui +{ + namespace Models + { + + /*! + * Aircraft list model + */ + class CAircraftListModel : public CListModelBase + { + + public: + + //! Constructor + explicit CAircraftListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CAircraftListModel() {} + + }; + } +} +#endif // guard diff --git a/src/blackgui/models/airportlistmodel.cpp b/src/blackgui/models/airportlistmodel.cpp new file mode 100644 index 000000000..bc7170b45 --- /dev/null +++ b/src/blackgui/models/airportlistmodel.cpp @@ -0,0 +1,48 @@ +/* Copyright (C) 2013 + * Swift Project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "airportlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CAirportListModel::CAirportListModel(QObject *parent) : + CListModelBase("ViewAirportList", parent) + { + this->m_columns.addColumn(CColumn("ICAO", CAirport::IndexIcao)); + this->m_columns.addColumn(CColumn("distance", CAirport::IndexDistance, Qt::AlignRight | Qt::AlignVCenter)); + this->m_columns.addColumn(CColumn("bearing", CAirport::IndexBearing, Qt::AlignRight | Qt::AlignVCenter)); + this->m_columns.addColumn(CColumn("name", CAirport::IndexDescriptiveName)); + this->m_columns.addColumn(CColumn("elevation", CAirport::IndexElevation, Qt::AlignRight | Qt::AlignVCenter)); + this->m_columns.addColumn(CColumn("latitude", CCoordinateGeodetic::IndexLatitude, Qt::AlignRight | Qt::AlignVCenter)); + this->m_columns.addColumn(CColumn("longitude", CCoordinateGeodetic::IndexLongitude, Qt::AlignRight | Qt::AlignVCenter)); + + // default sort order + this->setSortColumnByPropertyIndex(CAirport::IndexDistance); + this->m_sortOrder = Qt::AscendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewAirportList", "ICAO"); + (void)QT_TRANSLATE_NOOP("ViewAirportList", "distance"); + (void)QT_TRANSLATE_NOOP("ViewAirportList", "name"); + (void)QT_TRANSLATE_NOOP("ViewAirportList", "elevation"); + (void)QT_TRANSLATE_NOOP("ViewAirportList", "bearing"); + } + } +} diff --git a/src/blackgui/models/airportlistmodel.h b/src/blackgui/models/airportlistmodel.h new file mode 100644 index 000000000..51eb17f5e --- /dev/null +++ b/src/blackgui/models/airportlistmodel.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_AIRPORTLISTMODEL_H +#define BLACKGUI_AIRPORTLISTMODEL_H + +#include +#include "blackmisc/avairportlist.h" +#include "blackgui/models/listmodelbase.h" + +namespace BlackGui +{ + namespace Models + { + + /*! + * Airport list model + */ + class CAirportListModel : public CListModelBase + { + + public: + + //! Constructor + explicit CAirportListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CAirportListModel() {} + }; + } +} +#endif // guard diff --git a/src/blackgui/models/atcstationlistmodel.cpp b/src/blackgui/models/atcstationlistmodel.cpp new file mode 100644 index 000000000..c956506e6 --- /dev/null +++ b/src/blackgui/models/atcstationlistmodel.cpp @@ -0,0 +1,98 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "atcstationlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" + +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CAtcStationListModel::CAtcStationListModel(AtcStationMode stationMode, QObject *parent) : + CListModelBase("ViewAtcList", parent), m_stationMode(NotSet) + { + this->setStationMode(stationMode); + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewAtcList", "callsign"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "distance"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "frequency"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "controllername"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "online"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookedfrom"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookeduntil"); + (void)QT_TRANSLATE_NOOP("ViewAtcList", "voiceroomurl"); + } + + void CAtcStationListModel::setStationMode(CAtcStationListModel::AtcStationMode stationMode) + { + if (this->m_stationMode == stationMode) return; + this->m_stationMode = stationMode; + this->m_columns.clear(); + switch (stationMode) + { + case NotSet: + case StationsOnline: + this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet)); + this->m_columns.addColumn(CColumn(CAtcStation::IndexIcon, 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("bookedfrom", CAtcStation::IndexBookedFrom)); + this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil)); + this->m_columns.addColumn(CColumn("voiceroomurl", CAtcStation::IndexVoiceRoomUrl)); + + // default sort order + this->setSortColumnByPropertyIndex(CAtcStation::IndexDistance); + this->m_sortOrder = Qt::AscendingOrder; + break; + + case StationsBooked: + this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet)); + this->m_columns.addColumn(CColumn(CAtcStation::IndexIcon, true)); + this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName)); + 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)); + this->m_columns.addColumn(CColumn("online", CAtcStation::IndexIsOnline)); + + // default sort order + this->setSortColumnByPropertyIndex(CAtcStation::IndexBookedFrom); + this->m_sortOrder = Qt::AscendingOrder; + break; + + default: + qFatal("Wrong mode"); + break; + } + } + + void CAtcStationListModel::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) + { + if (station.getCallsign().isEmpty()) return; + if (added) + { + if (this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign())) + { + this->m_container.replaceIf(&CAtcStation::getCallsign, station.getCallsign(), station); + } + else + { + this->insert(station); + } + } + else + { + beginRemoveRows(QModelIndex(), 0, 0); + this->m_container.removeIf(&CAtcStation::getCallsign, station.getCallsign()); + endRemoveRows(); + } + } + } +} diff --git a/src/blackgui/models/atcstationlistmodel.h b/src/blackgui/models/atcstationlistmodel.h new file mode 100644 index 000000000..63a32e570 --- /dev/null +++ b/src/blackgui/models/atcstationlistmodel.h @@ -0,0 +1,53 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/*! + \file +*/ + +#ifndef BLACKGUI_ATCLISTMODEL_H +#define BLACKGUI_ATCLISTMODEL_H + +#include "blackmisc/avatcstationlist.h" +#include "blackgui/models/listmodelbase.h" +#include +#include + +namespace BlackGui +{ + namespace Models + { + //! ATC list model + class CAtcStationListModel : public CListModelBase + { + + public: + //! What kind of stations + enum AtcStationMode + { + NotSet, + StationsBooked, + StationsOnline + }; + + //! Constructor + explicit CAtcStationListModel(AtcStationMode stationMode, QObject *parent = nullptr); + + //! Destructor + virtual ~CAtcStationListModel() {} + + //! Set station mode + void setStationMode(AtcStationMode stationMode); + + public slots: + //! Used to quickly update single station (better response for the user) + void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); + + private: + AtcStationMode m_stationMode; + }; + } +} +#endif // guard diff --git a/src/blackgui/models/clientlistmodel.cpp b/src/blackgui/models/clientlistmodel.cpp new file mode 100644 index 000000000..db2fe0fd0 --- /dev/null +++ b/src/blackgui/models/clientlistmodel.cpp @@ -0,0 +1,62 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "clientlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CClientListModel::CClientListModel(QObject *parent) : + CListModelBase("ViewClientList", parent) + { + this->m_columns.addColumn(CColumn("", CClient::IndexCallsignIcon)); + this->m_columns.addColumn(CColumn("callsign", CClient::IndexCallsign)); + this->m_columns.addColumn(CColumn("realname", CClient::IndexRealName)); + this->m_columns.addColumn(CColumn("", CClient::IndexVoiceCapabilitiesIcon)); + this->m_columns.addColumn(CColumn("capabilities", CClient::IndexCapabilitiesString)); + this->m_columns.addColumn(CColumn("model", CClient::IndexQueriedModelString)); + this->m_columns.addColumn(CColumn("server", CClient::IndexServer)); + + // force strings for translation in resource files + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewClientList", "callsign"); + (void)QT_TRANSLATE_NOOP("ViewClientList", "realname"); + (void)QT_TRANSLATE_NOOP("ViewClientList", "userid"); + (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 u.toIcon(); + } + } + return CListModelBase::data(modelIndex, role); + } + } +} diff --git a/src/blackgui/models/clientlistmodel.h b/src/blackgui/models/clientlistmodel.h new file mode 100644 index 000000000..38ff8365b --- /dev/null +++ b/src/blackgui/models/clientlistmodel.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_CLIENTLISTMODEL_H +#define BLACKGUI_CLIENTLISTMODEL_H + +#include +#include "blackmisc/nwclientlist.h" +#include "blackgui/models/listmodelbase.h" + +namespace BlackGui +{ + namespace Models + { + /*! + * Server list model + */ + class CClientListModel : public CListModelBase + { + + public: + + //! \brief Constructor + explicit CClientListModel(QObject *parent = nullptr); + + //! \brief Destructor + virtual ~CClientListModel() {} + + //! \copydoc CListModelBase::data + QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const; + + }; + } +} +#endif // guard diff --git a/src/blackgui/models/columns.cpp b/src/blackgui/models/columns.cpp new file mode 100644 index 000000000..e0a2537e4 --- /dev/null +++ b/src/blackgui/models/columns.cpp @@ -0,0 +1,179 @@ +/* Copyright (C) 2013 + * Swift Project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "columns.h" +#include +#include + +namespace BlackGui +{ + namespace Models + { + CColumn::CColumn(const QString &headerName, int 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) : + m_columnName(headerName), m_alignment(-1), m_propertyIndex(propertyIndex), + m_editable(editable), m_icon(false) + {} + + CColumn::CColumn(int propertyIndex, bool isIcon) : + m_alignment(-1), m_propertyIndex(propertyIndex), + m_editable(false), m_icon(isIcon) + {} + + const char *CColumn::getTranslationContextChar() const + { + return this->m_translationContext.toUtf8().constData(); + } + + const char *CColumn::getColumnNameChar() const + { + return this->m_columnName.toUtf8().constData(); + } + + QVariant CColumn::aligmentAsQVariant() const + { + if (this->hasAlignment()) return QVariant(this->m_alignment); + return QVariant(Qt::AlignVCenter | Qt::AlignLeft); // default + } + + QString CColumn::getColumnName(bool i18n) const + { + if (!i18n || this->m_translationContext.isEmpty()) return this->m_columnName; + return QCoreApplication::translate(this->getTranslationContextChar(), this->getColumnNameChar()); + } + + /* + * Header + */ + CColumns::CColumns(const QString &translationContext, QObject *parent) : + QObject(parent), m_translationContext(translationContext) + { + // void + } + + /* + * Add column + */ + void CColumns::addColumn(CColumn column) + { + Q_ASSERT(!this->m_translationContext.isEmpty()); + column.setTranslationContext(this->m_translationContext); + this->m_columns.push_back(column); + } + + /* + * Property index to name + */ + QString CColumns::propertyIndexToColumnName(int propertyIndex, bool i18n) const + { + int column = this->propertyIndexToColumn(propertyIndex); + return this->m_columns.at(column).getColumnName(i18n); + } + + /* + * Index to name + */ + QString CColumns::columnToName(int column, bool i18n) const + { + Q_ASSERT(column >= 0 && column < this->m_columns.size()); + return this->m_columns.at(column).getColumnName(i18n); + } + + /* + * Get property index + */ + int CColumns::columnToPropertyIndex(int column) const + { + Q_ASSERT(column >= 0 && column < this->m_columns.size()); + return this->m_columns.at(column).getPropertyIndex(); + } + + /* + * Property index to column + */ + int CColumns::propertyIndexToColumn(int propertyIndex) const + { + for (int i = 0; i < this->m_columns.size(); i++) + { + if (this->m_columns.at(i).getPropertyIndex() == propertyIndex) + return i; + } + return -1; + } + + /* + * Name to property index + */ + int CColumns::nameToPropertyIndex(const QString &name) const + { + for (int i = 0; i < this->m_columns.size(); i++) + { + if (this->m_columns.at(i).getColumnName(false) == name) + return i; + } + return -1; + } + + /* + * Size + */ + int CColumns::size() const + { + return this->m_columns.size(); + } + + /* + * Alignment? + */ + bool CColumns::hasAlignment(const QModelIndex &index) const + { + if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; + return this->m_columns.at(index.column()).hasAlignment(); + } + + /* + * Editable? + */ + bool CColumns::isEditable(const QModelIndex &index) const + { + if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; + return this->m_columns.at(index.column()).isEditable(); + } + + /* + * Is icon? + */ + bool CColumns::isIcon(const QModelIndex &index) const + { + if (index.column() < 0 || index.column() >= this->m_columns.size()) return false; + return this->m_columns.at(index.column()).isIcon(); + } + + /* + * Aligment as QVariant + */ + QVariant CColumns::aligmentAsQVariant(const QModelIndex &index) const + { + if (index.column() < 0 || index.column() >= this->m_columns.size()) return QVariant(); + return this->m_columns.at(index.column()).aligmentAsQVariant(); + } + + /* + * Context + */ + const char *CColumns::getTranslationContextChar() const + { + return this->m_translationContext.toUtf8().constData(); + } + } +} // namespace BlackGui diff --git a/src/blackgui/models/columns.h b/src/blackgui/models/columns.h new file mode 100644 index 000000000..c5231a24f --- /dev/null +++ b/src/blackgui/models/columns.h @@ -0,0 +1,151 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_COLUMNS_H +#define BLACKGUI_COLUMNS_H + +//! \file + +#include "blackmisc/valueobject.h" // for qHash overload, include before Qt stuff due GCC issue +#include "blackmisc/collection.h" +#include +#include + +namespace BlackGui +{ + namespace Models + { + //! Single column + class CColumn + { + public: + /*! + * \brief Constructor + * \param headerName + * \param propertyIndex as in CValueObject::propertyByIndex + * \param alignment Qt::Alignment + * \param editable + */ + CColumn(const QString &headerName, int propertyIndex, int alignment = -1, bool editable = false); + + /*! + * \brief Constructor + * \param headerName + * \param propertyIndex as in CValueObject::propertyByIndex + * \param editable + */ + CColumn(const QString &headerName, int propertyIndex, bool editable); + + /*! + * \brief 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); + + //! Alignment for this column? + bool hasAlignment() const { return this->m_alignment >= 0; } + + //! Editable? + bool isEditable() const { return this->m_editable; } + + //! Icon? + bool isIcon() const { return this->m_icon; } + + //! Aligment as QVariant + QVariant aligmentAsQVariant() const; + + //! Column name + QString getColumnName(bool i18n = false) const; + + //! Property index + int getPropertyIndex() const { return this->m_propertyIndex;} + + //! Translation context + void setTranslationContext(const QString &translationContext) + { + this->m_translationContext = translationContext; + } + + private: + QString m_translationContext; + QString m_columnName; + int m_alignment; + int m_propertyIndex; // property index + bool m_editable; + bool m_icon; + const char *getTranslationContextChar() const; + const char *getColumnNameChar() const; + }; + + /*! + * \brief Header data for a table + */ + class CColumns : public QObject + { + public: + /*! + * \brief Columns constructors + * \param translationContext + * \param parent + */ + CColumns(const QString &translationContext, QObject *parent = nullptr); + + //! Add a column + void addColumn(CColumn column); + + //! Property index to name + QString propertyIndexToColumnName(int 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; + + //! Property index to column + int propertyIndexToColumn(int propertyIndex) const; + + //! Column index to property index + int indexToPropertyIndex(int index) const; + + //! Column index to name + int nameToPropertyIndex(const QString &name) const; + + //! Size (number of columns) + int size() const; + + //! Alignment for this column? + bool hasAlignment(const QModelIndex &index) const; + + //! Is this column editable? + bool isEditable(const QModelIndex &index) const; + + //! Is icon? + bool isIcon(const QModelIndex &index) const; + + //! Aligment as QVariant + QVariant aligmentAsQVariant(const QModelIndex &index) const; + + //! Column at position + const CColumn &at(int columnNumber) const { return this->m_columns.at(columnNumber); } + + //! Clear + void clear() { this->m_columns.clear(); } + + private: + QList m_columns; + QString m_translationContext; + const char *getTranslationContextChar() const; + }; + } +} // namespace BlackGui + +#endif // guard diff --git a/src/blackgui/models/keyboardkeylistmodel.cpp b/src/blackgui/models/keyboardkeylistmodel.cpp new file mode 100644 index 000000000..537d6ff5e --- /dev/null +++ b/src/blackgui/models/keyboardkeylistmodel.cpp @@ -0,0 +1,155 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "keyboardkeylistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include +#include +#include +#include + + +using namespace BlackMisc::Hardware; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) : + CListModelBase("ViewKeyboardKeyList", parent) + { + this->m_columns.addColumn(CColumn("key", CKeyboardKey::IndexKeyAsStringRepresentation, true)); + this->m_columns.addColumn(CColumn("modifier 1", CKeyboardKey::IndexModifier1AsString, true)); + this->m_columns.addColumn(CColumn("modifier 2", CKeyboardKey::IndexModifier2AsString, true)); + this->m_columns.addColumn(CColumn("function", CKeyboardKey::IndexFunctionAsString)); + + this->setSortColumnByPropertyIndex(CKeyboardKey::IndexFunctionAsString); + this->m_sortOrder = Qt::AscendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 1"); + (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 2"); + (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "function"); + (void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "key"); + } + + /* + * Display icons + */ + QVariant CKeyboardKeyListModel::data(const QModelIndex &modelIndex, int role) const + { + // shortcut, fast check + return CListModelBase::data(modelIndex, role); + } + + bool CKeyboardKeyListModel::setData(const QModelIndex &index, const QVariant &value, int role) + { + if (role == Qt::EditRole) + { + int pi = this->indexToPropertyIndex(index); + if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) + { + if (index.row() >= this->m_container.size()) return true; + CKeyboardKey key = this->m_container[index.row()]; + key.setPropertyByIndex(value, pi); + key.cleanup(); + this->m_container[index.row()] = key; + return true; + } + else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) + { + Q_ASSERT(value.canConvert()); + if (index.row() >= this->m_container.size()) return true; + CKeyboardKey key = this->m_container[index.row()]; + key.setPropertyByIndex(value, CKeyboardKey::IndexKeyObject); + key.cleanup(); + this->m_container[index.row()] = key; + return true; + } + } + return CListModelBase::setData(index, value, role); + } + + QWidget *CKeyboardKeyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const + { + const CKeyboardKeyListModel *model = this->model(); + Q_ASSERT(model); + + if (index.row() < model->rowCount()) + { + int pi = model->indexToPropertyIndex(index); + if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) + { + CKeyboardKey key = model->at(index); + QString v = (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString(); + QComboBox *edit = new QComboBox(parent); + edit->addItems(CKeyboardKey::modifiers()); + edit->setCurrentText(v); + return edit; + } + else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) + { + CKeyboardKey key = model->at(index); + CKeyboardLineEdit *edit = new CKeyboardLineEdit(key, parent); + edit->setText(key.getKeyAsString()); + return edit; + } + } + return QItemDelegate::createEditor(parent, option, index); + } + + void CKeyboardKeyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const + { + QItemDelegate::setEditorData(editor, index); + } + + void CKeyboardKeyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const + { + // with our own line edit we have a special treatment + // otherwise (comboboxes) standard handling via QItemDelegate + CKeyboardLineEdit *lineEdit = qobject_cast(editor); + if (lineEdit) + model->setData(index, lineEdit->getKey().toQVariant() , Qt::EditRole); + else + QItemDelegate::setModelData(editor, model, index); + } + + void CKeyboardKeyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const + { + QItemDelegate::updateEditorGeometry(editor, option, index); + } + + const CKeyboardKeyListModel *CKeyboardKeyItemDelegate::model() const + { + if (this->parent()) + { + QTableView *tableView = dynamic_cast(this->parent()); + if (tableView) + { + return dynamic_cast(tableView->model()); + } + } + return nullptr; + } + + void CKeyboardLineEdit::keyPressEvent(QKeyEvent *event) + { + const Qt::Key k = static_cast(event->key()); + if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return; + this->m_key.setKey(k); + this->m_key.setNativeVirtualKey(event->nativeVirtualKey()); + this->setText(CKeyboardKey::toStringRepresentation(event->key())); + } + + } +} // namespace diff --git a/src/blackgui/models/keyboardkeylistmodel.h b/src/blackgui/models/keyboardkeylistmodel.h new file mode 100644 index 000000000..8c7ac73d3 --- /dev/null +++ b/src/blackgui/models/keyboardkeylistmodel.h @@ -0,0 +1,100 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_KEYBOARDKEYLISTMODEL_H +#define BLACKGUI_KEYBOARDKEYLISTMODEL_H + +#include "blackmisc/hwkeyboardkeylist.h" +#include "blackgui/models/listmodelbase.h" +#include +#include +#include +#include + +namespace BlackGui +{ + namespace Models + { + /*! + * Keyboard key list model + */ + class CKeyboardKeyListModel : public CListModelBase + { + + public: + + //! Constructor + explicit CKeyboardKeyListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CKeyboardKeyListModel() {} + + //! \copydoc CListModelBase::data + QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override; + + //! \copydoc CKeyboardKeyList::initAsHotkeyList(bool reset) + void initAsHotkeyList() { this->m_container.initAsHotkeyList(); } + + //! \copydoc QAbstractTableModel::setData + virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override; + }; + + /*! + * Special edit delegate for key sequence + */ + class CKeyboardKeyItemDelegate : public QItemDelegate + { + Q_OBJECT + + public: + //! Constructor + explicit CKeyboardKeyItemDelegate(QObject *parent = nullptr) : + QItemDelegate(parent) {} + + //! \copydoc QItemDelegate::createEditor + virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + + //! \copydoc QItemDelegate::setEditorData + virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override; + + //! \copydoc QItemDelegate::setModelData + virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + + //! \copydoc QItemDelegate::updateEditorGeometry + virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + + //! correspondig model + const CKeyboardKeyListModel *model() const; + }; + + /*! + * Special edit widget for key sequence + */ + class CKeyboardLineEdit : public QLineEdit + { + Q_OBJECT + + public: + //! Constructor + CKeyboardLineEdit(BlackMisc::Hardware::CKeyboardKey &key, QWidget *parent = nullptr) : + QLineEdit(parent), m_key(key) { } + + //! get key + BlackMisc::Hardware::CKeyboardKey getKey() const { return this->m_key; } + + protected: + //! Overriding and handling key press + virtual void keyPressEvent(QKeyEvent *event) override; + + private: + BlackMisc::Hardware::CKeyboardKey m_key; + }; + } +} +#endif // guard diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp new file mode 100644 index 000000000..2860190c9 --- /dev/null +++ b/src/blackgui/models/listmodelbase.cpp @@ -0,0 +1,245 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "listmodelbase.h" +#include "blackmisc/namevariantpairlist.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/avatcstationlist.h" +#include "blackmisc/avaircraftlist.h" +#include "blackmisc/avairportlist.h" +#include "blackmisc/nwserverlist.h" +#include "blackmisc/nwuserlist.h" +#include "blackmisc/nwclientlist.h" +#include "blackmisc/hwkeyboardkeylist.h" +#include "blackmisc/blackmiscfreefunctions.h" + +namespace BlackGui +{ + namespace Models + { + /* + * Column count + */ + template + int CListModelBase::columnCount(const QModelIndex & /** modelIndex **/) const + { + int c = this->m_columns.size(); + return c; + } + + /* + * Row count + */ + template + int CListModelBase::rowCount(const QModelIndex & /** parent */) const + { + return this->m_container.size(); + } + + /* + * Column to property index + */ + template + int CListModelBase::columnToPropertyIndex(int column) const + { + return this->m_columns.columnToPropertyIndex(column); + } + + /* + * Header data + */ + template QVariant + CListModelBase::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) + { + if (section < 0 || section >= this->m_columns.size()) return QVariant(); + QString header = this->m_columns.at(section).getColumnName(false); + return QVariant(header); + } + return QVariant(); + } + + /* + * Data + */ + template + QVariant CListModelBase::data(const QModelIndex &index, int role) const + { + // checks + if (index.row() < 0 || index.row() >= this->m_container.size() || + index.column() < 0 || index.column() >= this->columnCount(index)) + { + return QVariant(); + } + + if (role == Qt::DisplayRole) + { + if (this->m_columns.isIcon(index)) return QVariant(); + ObjectType obj = this->m_container[index.row()]; + int propertyIndex = this->columnToPropertyIndex(index.column()); + QString propertyString = obj.propertyByIndexAsString(propertyIndex, true); + return QVariant::fromValue(propertyString); + } + else if (role == Qt::DecorationRole) + { + if (!this->m_columns.isIcon(index)) return QVariant(); + ObjectType obj = this->m_container[index.row()]; + int propertyIndex = this->columnToPropertyIndex(index.column()); + return obj.propertyByIndex(propertyIndex); + } + else if (role == Qt::TextAlignmentRole) + { + return this->m_columns.aligmentAsQVariant(index); + } + return QVariant(); + } + + /* + * Update + */ + template + int CListModelBase::update(const ContainerType &container) + { + ContainerType copyList = (container.size() > 1 && this->hasValidSortColumn() ? + this->sortListByColumn(container, this->m_sortedColumn, this->m_sortOrder) : + container); + this->beginResetModel(); + this->m_container.clear(); + foreach(ObjectType object, copyList) + { + this->m_container.push_back(object); + } + this->endResetModel(); + return this->m_container.size(); + } + + + /* + * Update + */ + template + void CListModelBase::update(const QModelIndex &index, const ObjectType &object) + { + if (index.row() >= this->m_container.size()) return; + this->m_container[index.row()] = object; + + QModelIndex i1 = index.sibling(index.row(), 0); + QModelIndex i2 = index.sibling(index.row(), this->columnCount(index) - 1); + emit this->dataChanged(i1, i2); // which range has been changed + } + + /* + * Push back + */ + template + void CListModelBase::push_back(const ObjectType &object) + { + beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size()); + this->m_container.push_back(object); + endInsertRows(); + } + + /* + * Push back + */ + template + void CListModelBase::insert(const ObjectType &object) + { + beginInsertRows(QModelIndex(), 0, 0); + this->m_container.insert(this->m_container.begin(), object); + endInsertRows(); + } + + /* + * Remove object + */ + template + void CListModelBase::remove(const ObjectType &object) + { + beginRemoveRows(QModelIndex(), 0, 0); + this->m_container.remove(object); + endRemoveRows(); + } + + /* + * Clear + */ + template + void CListModelBase::clear() + { + beginResetModel(); + this->m_container.clear(); + endResetModel(); + } + + /* + * Sort + */ + template void CListModelBase::sort(int column, Qt::SortOrder order) + { + this->m_sortedColumn = column; + this->m_sortOrder = order; + if (this->m_container.size() < 2) return; // nothing to do + + // sort the values + this->update( + this->sortListByColumn(this->m_container, column, order) + ); + } + + /* + * Sort list + */ + template ContainerType CListModelBase::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 + + // sort the values + return list.sorted + ([ = ](const ObjectType & a, const ObjectType & b) -> bool + { + QVariant aQv = a.propertyByIndex(propertyIndex); + QVariant bQv = b.propertyByIndex(propertyIndex); + int compare = (order == Qt::AscendingOrder) ? + BlackMisc::compareQVariants(aQv, bQv) : + BlackMisc::compareQVariants(bQv, aQv); + return compare < 0; + } + ); // sorted + } + + /* + * Make editable + */ + template Qt::ItemFlags CListModelBase::flags(const QModelIndex &index) const + { + Qt::ItemFlags f = QAbstractListModel::flags(index); + if (this->m_columns.isEditable(index)) + return f | Qt::ItemIsEditable; + else + return f; + } + + // see here for the reason of thess forward instantiations + // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + } +} // namespace diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h new file mode 100644 index 000000000..cd90c5811 --- /dev/null +++ b/src/blackgui/models/listmodelbase.h @@ -0,0 +1,158 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_LISTMODELBASE_H +#define BLACKGUI_LISTMODELBASE_H + +#include "blackgui/models/columns.h" +#include + +namespace BlackGui +{ + namespace Models + { + + /*! + * List model + */ + template class CListModelBase : public QAbstractListModel + { + + protected: + ContainerType m_container; //!< used container + CColumns m_columns; //!< columns metadata + int m_sortedColumn; //!< current sort column + Qt::SortOrder m_sortOrder; //!< sort order (asc/desc) + + /*! + * Constructor + * \param translationContext I18N context + * \param parent + */ + CListModelBase(const QString &translationContext, QObject *parent = nullptr) + : QAbstractListModel(parent), m_columns(translationContext), m_sortedColumn(-1), m_sortOrder(Qt::AscendingOrder) + { + // void + } + + /*! + * Sort list by given order + * \param list used list + * \param column column inder + * \param order sort order (asccending / descending) + * \return + */ + ContainerType sortListByColumn(const ContainerType &list, int column, Qt::SortOrder order); + + public: + + //! Destructor + virtual ~CListModelBase() {} + + //! \copydoc QAbstractListModel::columnCount() + virtual int columnCount(const QModelIndex &modelIndex) const override; + + //! \copydoc QAbstractItemModel::headerData() + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + + //! Column to property index + virtual int columnToPropertyIndex(int column) const; + + //! Index to property index + virtual int indexToPropertyIndex(const QModelIndex &index) const + { + return this->columnToPropertyIndex(index.column()); + } + + //! Set sort column + virtual void setSortColumn(int column) + { + this->m_sortedColumn = column; + } + + /*! + * Set column for sort + * \param propertyIndex index of column to be sorted by + */ + virtual void setSortColumnByPropertyIndex(int propertyIndex) + { + this->m_sortedColumn = this->m_columns.propertyIndexToColumn(propertyIndex); + } + + //! Get sort column + virtual int getSortColumn() const + { + return this->m_sortedColumn; + } + + //! Has valid sort column? + virtual bool hasValidSortColumn() const + { + return this->m_sortedColumn >= 0 && this->m_sortedColumn < this->m_columns.size(); + } + + //! Get sort order + virtual Qt::SortOrder getSortOrder() const + { + return this->m_sortOrder; + } + + //! Used container data + virtual const ContainerType &getContainer() const + { + return this->m_container; + } + + //! \copydoc QAbstractListModel::data() + virtual QVariant data(const QModelIndex &index, int role) const override; + + //! \copydoc QAbstractListModel::rowCount() + virtual int rowCount(const QModelIndex &index = QModelIndex()) const override; + + //! \copydoc QAbstractTableModel::flags + Qt::ItemFlags flags(const QModelIndex &index) const override; + + //! Update by new list + virtual int update(const ContainerType &container); + + //! Update single element + virtual void update(const QModelIndex &index, const ObjectType &object); + + //! Object at row position + virtual const ObjectType &at(const QModelIndex &index) const + { + if (index.row() < 0 || index.row() >= this->m_container.size()) + { + const static ObjectType def; + return def; + } + else + { + return this->m_container[index.row()]; + } + } + + //! \copydoc QAbstractListModel::sort() + virtual void sort(int column, Qt::SortOrder order); + + //! Similar to ContainerType::push_back + virtual void push_back(const ObjectType &object); + + //! Similar to ContainerType::insert here inserts at first position + virtual void insert(const ObjectType &object); + + //! Remove object + virtual void remove(const ObjectType &object); + + //! Clear the list + virtual void clear(); + }; + } +} +#endif // guard diff --git a/src/blackgui/models/serverlistmodel.cpp b/src/blackgui/models/serverlistmodel.cpp new file mode 100644 index 000000000..3790a8e03 --- /dev/null +++ b/src/blackgui/models/serverlistmodel.cpp @@ -0,0 +1,65 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "serverlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Models + { + + /* + * Constructor + */ + CServerListModel::CServerListModel(QObject *parent) : + CListModelBase("ViewServerList", parent) + { + this->m_columns.addColumn(CColumn("name", CServer::IndexName)); + 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)); + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewServerList", "name"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "description"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "address"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "port"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "realname"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "userid"); + } + + /* + * Special functions + */ + QVariant CServerListModel::data(const QModelIndex &index, int role) const + { + if (role == Qt::BackgroundRole) + { + if (!this->hasSelectedServer()) return QVariant(); + CServer currentRow = this->at(index); + if (currentRow == this->getSelectedServer()) + { + QBrush background(Qt::green); + return background; + } + else + { + return QVariant(); + } + } + else + { + return CListModelBase::data(index, role); + } + } + } +} diff --git a/src/blackgui/models/serverlistmodel.h b/src/blackgui/models/serverlistmodel.h new file mode 100644 index 000000000..873937348 --- /dev/null +++ b/src/blackgui/models/serverlistmodel.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKGUI_SERVERLISTMODEL_H +#define BLACKGUI_SERVERLISTMODEL_H + +//! \file + +#include "blackmisc/nwserverlist.h" +#include "blackgui/models/listmodelbase.h" +#include + +namespace BlackGui +{ + namespace Models + { + //! Server list model + class CServerListModel : public CListModelBase + { + + private: + BlackMisc::Network::CServer m_selectedServer; + + public: + + //! Constructor + explicit CServerListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CServerListModel() {} + + //! Has selected server? + bool hasSelectedServer() const + { + return this->m_selectedServer.isValidForLogin(); + } + + //! Get selected server + const BlackMisc::Network::CServer &getSelectedServer() const + { + return this->m_selectedServer; + } + + //! Set selected server + void setSelectedServer(const BlackMisc::Network::CServer &selectedServer) + { + this->m_selectedServer = selectedServer; + } + + //! \copydoc CListModelBase::data + virtual QVariant data(const QModelIndex &index, int role) const; + + }; + } +} +#endif // guard diff --git a/src/blackgui/models/statusmessagelistmodel.cpp b/src/blackgui/models/statusmessagelistmodel.cpp new file mode 100644 index 000000000..b949da687 --- /dev/null +++ b/src/blackgui/models/statusmessagelistmodel.cpp @@ -0,0 +1,62 @@ +#include "statusmessagelistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include +#include + +using namespace BlackMisc; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CStatusMessageListModel::CStatusMessageListModel(QObject *parent) : + CListModelBase("ViewStatusMessageList", parent) + { + this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexTimestamp)); + this->m_columns.addColumn(CColumn("", CStatusMessage::IndexSeverity, Qt::AlignCenter)); + this->m_columns.addColumn(CColumn("message", CStatusMessage::IndexMessage)); + this->m_columns.addColumn(CColumn("type", CStatusMessage::IndexTypeAsString)); + + this->m_sortedColumn = CStatusMessage::IndexTimestamp; + this->m_sortOrder = Qt::DescendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "time"); + (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "severity"); + (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "type"); + (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "message"); + } + + /* + * Display icons + */ + QVariant CStatusMessageListModel::data(const QModelIndex &modelIndex, int role) const + { + // shortcut, fast check + if (role != Qt::DisplayRole && role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role); + if (this->columnToPropertyIndex(modelIndex.column()) == CStatusMessage::IndexSeverity) + { + if (role == Qt::DecorationRole) + { + CStatusMessage msg = this->at(modelIndex); + return msg.toIcon(); + } + else if (role == Qt::DisplayRole) + { + // the text itself should be empty + return QVariant(""); + } + else if (role == Qt::ToolTipRole) + { + CStatusMessage msg = this->at(modelIndex); + return QVariant(msg.getSeverityAsString()); + } + } + return CListModelBase::data(modelIndex, role); + } + } +} diff --git a/src/blackgui/models/statusmessagelistmodel.h b/src/blackgui/models/statusmessagelistmodel.h new file mode 100644 index 000000000..855b1e8bc --- /dev/null +++ b/src/blackgui/models/statusmessagelistmodel.h @@ -0,0 +1,32 @@ +#ifndef BLACKGUI_STATUSMESSAGELISTMODEL_H +#define BLACKGUI_STATUSMESSAGELISTMODEL_H + +#include +#include +#include "blackmisc/statusmessagelist.h" +#include "blackgui/models/listmodelbase.h" + +namespace BlackGui +{ + namespace Models + { + /*! + * Server list model + */ + class CStatusMessageListModel : public CListModelBase + { + + public: + + //! Constructor + explicit CStatusMessageListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CStatusMessageListModel() {} + + //! \copydoc CListModelBase::data + QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const; + }; + } +} +#endif // guard diff --git a/src/blackgui/models/userlistmodel.cpp b/src/blackgui/models/userlistmodel.cpp new file mode 100644 index 000000000..6498a1f58 --- /dev/null +++ b/src/blackgui/models/userlistmodel.cpp @@ -0,0 +1,66 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "userlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CUserListModel::CUserListModel(UserMode userMode, QObject *parent) : + CListModelBase("ViewUserList", parent), m_userMode(NotSet) + { + this->setUserMode(userMode); + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewUserList", "callsign"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "realname"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "userid"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "email"); + } + + /* + * Mode + */ + void CUserListModel::setUserMode(CUserListModel::UserMode userMode) + { + if (this->m_userMode == userMode) return; + this->m_userMode = userMode; + this->m_columns.clear(); + switch (userMode) + { + case NotSet: + case UserDetailed: + this->m_columns.addColumn(CColumn(CUser::IndexCallsignIcon, 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)); + // this->m_columns.addColumn(CUser::IndexEmail, "email"); + break; + + case UserShort: + this->m_columns.addColumn(CColumn(CUser::IndexCallsignIcon, true)); + this->m_columns.addColumn(CColumn("realname", CUser::IndexRealName)); + this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign)); + break; + + default: + qFatal("Wrong mode"); + break; + } + } + } +} diff --git a/src/blackgui/models/userlistmodel.h b/src/blackgui/models/userlistmodel.h new file mode 100644 index 000000000..e10fd7205 --- /dev/null +++ b/src/blackgui/models/userlistmodel.h @@ -0,0 +1,51 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_USERLISTMODEL_H +#define BLACKGUI_USERLISTMODEL_H + +#include +#include "blackmisc/nwuserlist.h" +#include "blackgui/models/listmodelbase.h" + +namespace BlackGui +{ + namespace Models + { + /*! + * User list model + */ + class CUserListModel : public CListModelBase + { + + public: + + //! What level of detail + enum UserMode + { + NotSet, + UserDetailed, + UserShort + }; + + //! Constructor + explicit CUserListModel(UserMode userMode, QObject *parent = nullptr); + + //! Destructor + virtual ~CUserListModel() {} + + //! Set station mode + void setUserMode(UserMode userMode); + + private: + UserMode m_userMode; + }; + } +} +#endif // guard diff --git a/src/blackgui/serverlistmodel.cpp b/src/blackgui/serverlistmodel.cpp deleted file mode 100644 index 9250119f9..000000000 --- a/src/blackgui/serverlistmodel.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "serverlistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include - -using namespace BlackMisc::Network; - -namespace BlackGui -{ - /* - * Constructor - */ - CServerListModel::CServerListModel(QObject *parent) : - CListModelBase("ViewServerList", parent) - { - this->m_columns.addColumn(CColumn("name", CServer::IndexName)); - 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)); - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewServerList", "name"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "description"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "address"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "port"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "realname"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "userid"); - } - - /* - * Special functions - */ - QVariant CServerListModel::data(const QModelIndex &index, int role) const - { - if (role == Qt::BackgroundRole) - { - if (!this->hasSelectedServer()) return QVariant(); - CServer currentRow = this->at(index); - if (currentRow == this->getSelectedServer()) - { - QBrush background(Qt::green); - return background; - } - else - { - return QVariant(); - } - } - else - { - return CListModelBase::data(index, role); - } - } -} diff --git a/src/blackgui/serverlistmodel.h b/src/blackgui/serverlistmodel.h deleted file mode 100644 index cc52ab8ee..000000000 --- a/src/blackgui/serverlistmodel.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/*! - \file -*/ - -#ifndef BLACKGUI_SERVERLISTMODEL_H -#define BLACKGUI_SERVERLISTMODEL_H - -#include "blackmisc/nwserverlist.h" -#include "blackgui/listmodelbase.h" -#include -#include - -namespace BlackGui -{ - /*! - * \brief Server list model - */ - class CServerListModel : public CListModelBase - { - - private: - BlackMisc::Network::CServer m_selectedServer; - - public: - - //! Constructor - explicit CServerListModel(QObject *parent = nullptr); - - //! Destructor - virtual ~CServerListModel() {} - - //! Has selected server? - bool hasSelectedServer() const - { - return this->m_selectedServer.isValidForLogin(); - } - - //! Get selected server - const BlackMisc::Network::CServer &getSelectedServer() const - { - return this->m_selectedServer; - } - - //! Set selected server - void setSelectedServer(const BlackMisc::Network::CServer &selectedServer) - { - this->m_selectedServer = selectedServer; - } - - //! \copydoc CListModelBase::data - virtual QVariant data(const QModelIndex &index, int role) const; - - }; -} -#endif // guard diff --git a/src/blackgui/statusmessagelistmodel.cpp b/src/blackgui/statusmessagelistmodel.cpp deleted file mode 100644 index f7fccbf2f..000000000 --- a/src/blackgui/statusmessagelistmodel.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "statusmessagelistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include -#include - -using namespace BlackMisc; - -namespace BlackGui -{ - /* - * Constructor - */ - CStatusMessageListModel::CStatusMessageListModel(QObject *parent) : - CListModelBase("ViewStatusMessageList", parent) - { - this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexTimestamp)); - this->m_columns.addColumn(CColumn("", CStatusMessage::IndexSeverity, Qt::AlignCenter)); - this->m_columns.addColumn(CColumn("message", CStatusMessage::IndexMessage)); - this->m_columns.addColumn(CColumn("type", CStatusMessage::IndexTypeAsString)); - - this->m_sortedColumn = CStatusMessage::IndexTimestamp; - this->m_sortOrder = Qt::DescendingOrder; - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "time"); - (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "severity"); - (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "type"); - (void)QT_TRANSLATE_NOOP("ViewStatusMessageList", "message"); - } - - /* - * Display icons - */ - QVariant CStatusMessageListModel::data(const QModelIndex &modelIndex, int role) const - { - // shortcut, fast check - if (role != Qt::DisplayRole && role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role); - if (this->columnToPropertyIndex(modelIndex.column()) == CStatusMessage::IndexSeverity) - { - if (role == Qt::DecorationRole) - { - CStatusMessage msg = this->at(modelIndex); - return msg.toIcon(); - } - else if (role == Qt::DisplayRole) - { - // the text itself should be empty - return QVariant(""); - } - else if (role == Qt::ToolTipRole) - { - CStatusMessage msg = this->at(modelIndex); - return QVariant(msg.getSeverityAsString()); - } - } - return CListModelBase::data(modelIndex, role); - } -} diff --git a/src/blackgui/statusmessagelistmodel.h b/src/blackgui/statusmessagelistmodel.h deleted file mode 100644 index a5e3c71e8..000000000 --- a/src/blackgui/statusmessagelistmodel.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef BLACKGUI_STATUSMESSAGELISTMODEL_H -#define BLACKGUI_STATUSMESSAGELISTMODEL_H - -#include -#include -#include "blackmisc/statusmessagelist.h" -#include "blackgui/listmodelbase.h" - -namespace BlackGui -{ - /*! - * \brief Server list model - */ - class CStatusMessageListModel : public CListModelBase - { - - public: - - //! Constructor - explicit CStatusMessageListModel(QObject *parent = nullptr); - - //! Destructor - virtual ~CStatusMessageListModel() {} - - //! \copydoc CListModelBase::data - QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const; - }; -} -#endif // guard diff --git a/src/blackgui/userlistmodel.cpp b/src/blackgui/userlistmodel.cpp deleted file mode 100644 index 9c47b7229..000000000 --- a/src/blackgui/userlistmodel.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "userlistmodel.h" -#include "blackmisc/blackmiscfreefunctions.h" -#include -#include - -using namespace BlackMisc::Network; - -namespace BlackGui -{ - /* - * Constructor - */ - CUserListModel::CUserListModel(UserMode userMode, QObject *parent) : - CListModelBase("ViewUserList", parent), m_userMode(NotSet) - { - this->setUserMode(userMode); - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewUserList", "callsign"); - (void)QT_TRANSLATE_NOOP("ViewUserList", "realname"); - (void)QT_TRANSLATE_NOOP("ViewUserList", "userid"); - (void)QT_TRANSLATE_NOOP("ViewUserList", "email"); - } - - /* - * Mode - */ - void CUserListModel::setUserMode(CUserListModel::UserMode userMode) - { - if (this->m_userMode == userMode) return; - this->m_userMode = userMode; - this->m_columns.clear(); - switch (userMode) - { - case NotSet: - case UserDetailed: - this->m_columns.addColumn(CColumn(CUser::IndexCallsignIcon, 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)); - // this->m_columns.addColumn(CUser::IndexEmail, "email"); - break; - - case UserShort: - this->m_columns.addColumn(CColumn(CUser::IndexCallsignIcon, true)); - this->m_columns.addColumn(CColumn("realname", CUser::IndexRealName)); - this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign)); - break; - - default: - qFatal("Wrong mode"); - break; - } - } -} diff --git a/src/blackgui/userlistmodel.h b/src/blackgui/userlistmodel.h deleted file mode 100644 index 0ba1b787b..000000000 --- a/src/blackgui/userlistmodel.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef BLACKGUI_USERLISTMODEL_H -#define BLACKGUI_USERLISTMODEL_H - -#include -#include "blackmisc/nwuserlist.h" -#include "blackgui/listmodelbase.h" - -namespace BlackGui -{ - /*! - * User list model - */ - class CUserListModel : public CListModelBase - { - - public: - - //! What level of detail - enum UserMode - { - NotSet, - UserDetailed, - UserShort - }; - - //! Constructor - explicit CUserListModel(UserMode userMode, QObject *parent = nullptr); - - //! Destructor - virtual ~CUserListModel() {} - - //! Set station mode - void setUserMode(UserMode userMode); - - private: - UserMode m_userMode; - }; -} -#endif // guard