refs #300, moved models in own namespace and directory

This commit is contained in:
Klaus Basan
2014-07-27 14:53:15 +02:00
parent 4e9828b724
commit c500a561be
40 changed files with 1759 additions and 1606 deletions

View File

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

View File

@@ -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 <QAbstractItemModel>
#include <QDBusConnection>
namespace BlackGui
{
namespace Models
{
/*!
* Aircraft list model
*/
class CAircraftListModel : public CListModelBase<BlackMisc::Aviation::CAircraft, BlackMisc::Aviation::CAircraftList>
{
public:
//! Constructor
explicit CAircraftListModel(QObject *parent = nullptr);
//! Destructor
virtual ~CAircraftListModel() {}
};
}
}
#endif // guard

View File

@@ -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 <QMetaProperty>
#include <QBrush>
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo;
namespace BlackGui
{
namespace Models
{
/*
* Constructor
*/
CAirportListModel::CAirportListModel(QObject *parent) :
CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>("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");
}
}
}

View File

@@ -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 <QAbstractItemModel>
#include "blackmisc/avairportlist.h"
#include "blackgui/models/listmodelbase.h"
namespace BlackGui
{
namespace Models
{
/*!
* Airport list model
*/
class CAirportListModel : public CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>
{
public:
//! Constructor
explicit CAirportListModel(QObject *parent = nullptr);
//! Destructor
virtual ~CAirportListModel() {}
};
}
}
#endif // guard

View File

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

View File

@@ -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 <QAbstractItemModel>
#include <QDBusConnection>
namespace BlackGui
{
namespace Models
{
//! ATC list model
class CAtcStationListModel : public CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList>
{
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

View File

@@ -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 <QMetaProperty>
#include <QBrush>
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Models
{
/*
* Constructor
*/
CClientListModel::CClientListModel(QObject *parent) :
CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>("ViewClientList", parent)
{
this->m_columns.addColumn(CColumn("", CClient::IndexCallsignIcon));
this->m_columns.addColumn(CColumn("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);
}
}
}

View File

@@ -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 <QAbstractItemModel>
#include "blackmisc/nwclientlist.h"
#include "blackgui/models/listmodelbase.h"
namespace BlackGui
{
namespace Models
{
/*!
* Server list model
*/
class CClientListModel : public CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>
{
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

View File

@@ -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 <QModelIndex>
#include <QCoreApplication>
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

View File

@@ -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 <QObject>
#include <QHash>
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<CColumn> m_columns;
QString m_translationContext;
const char *getTranslationContextChar() const;
};
}
} // namespace BlackGui
#endif // guard

View File

@@ -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 <QMetaProperty>
#include <QComboBox>
#include <QTableView>
#include <QEvent>
#include <QKeyEvent>
using namespace BlackMisc::Hardware;
namespace BlackGui
{
namespace Models
{
/*
* Constructor
*/
CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) :
CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>("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<CKeyboardKey>());
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<CKeyboardLineEdit *>(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<QTableView *>(this->parent());
if (tableView)
{
return dynamic_cast<CKeyboardKeyListModel *>(tableView->model());
}
}
return nullptr;
}
void CKeyboardLineEdit::keyPressEvent(QKeyEvent *event)
{
const Qt::Key k = static_cast<Qt::Key>(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

View File

@@ -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 <QAbstractItemModel>
#include <QDBusConnection>
#include <QItemDelegate>
#include <QLineEdit>
namespace BlackGui
{
namespace Models
{
/*!
* Keyboard key list model
*/
class CKeyboardKeyListModel : public CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>
{
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

View File

@@ -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 <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::columnCount(const QModelIndex & /** modelIndex **/) const
{
int c = this->m_columns.size();
return c;
}
/*
* Row count
*/
template <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::rowCount(const QModelIndex & /** parent */) const
{
return this->m_container.size();
}
/*
* Column to property index
*/
template <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::columnToPropertyIndex(int column) const
{
return this->m_columns.columnToPropertyIndex(column);
}
/*
* Header data
*/
template <typename ObjectType, typename ContainerType> QVariant
CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType>
QVariant CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::insert(const ObjectType &object)
{
beginInsertRows(QModelIndex(), 0, 0);
this->m_container.insert(this->m_container.begin(), object);
endInsertRows();
}
/*
* Remove object
*/
template <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::remove(const ObjectType &object)
{
beginRemoveRows(QModelIndex(), 0, 0);
this->m_container.remove(object);
endRemoveRows();
}
/*
* Clear
*/
template <typename ObjectType, typename ContainerType>
void CListModelBase<ObjectType, ContainerType>::clear()
{
beginResetModel();
this->m_container.clear();
endResetModel();
}
/*
* Sort
*/
template <typename ObjectType, typename ContainerType> void CListModelBase<ObjectType, ContainerType>::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 <typename ObjectType, typename ContainerType> ContainerType CListModelBase<ObjectType, ContainerType>::sortListByColumn(const ContainerType &list, int column, Qt::SortOrder order)
{
if (list.size() < 2) return list; // nothing to do
int propertyIndex = this->m_columns.columnToPropertyIndex(column);
Q_ASSERT(propertyIndex >= 0);
if (propertyIndex < 0) return list; // at release build do nothing
// 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 <typename ObjectType, typename ContainerType> Qt::ItemFlags CListModelBase<ObjectType, ContainerType>::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<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
template class CListModelBase<BlackMisc::CNameVariantPair, BlackMisc::CNameVariantPairList>;
template class CListModelBase<BlackMisc::Aviation::CAtcStation, BlackMisc::Aviation::CAtcStationList>;
template class CListModelBase<BlackMisc::Aviation::CAircraft, BlackMisc::Aviation::CAircraftList>;
template class CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>;
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
template class CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>;
}
} // namespace

View File

@@ -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 <QAbstractItemModel>
namespace BlackGui
{
namespace Models
{
/*!
* List model
*/
template <typename ObjectType, typename ContainerType> 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

View File

@@ -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 <QMetaProperty>
#include <QBrush>
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);
}
}
}
}

View File

@@ -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 <QAbstractItemModel>
namespace BlackGui
{
namespace Models
{
//! Server list model
class CServerListModel : public CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>
{
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

View File

@@ -0,0 +1,62 @@
#include "statusmessagelistmodel.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <QMetaProperty>
#include <QBrush>
#include <QIcon>
using namespace BlackMisc;
namespace BlackGui
{
namespace Models
{
/*
* Constructor
*/
CStatusMessageListModel::CStatusMessageListModel(QObject *parent) :
CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>("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);
}
}
}

View File

@@ -0,0 +1,32 @@
#ifndef BLACKGUI_STATUSMESSAGELISTMODEL_H
#define BLACKGUI_STATUSMESSAGELISTMODEL_H
#include <QAbstractItemModel>
#include <QDBusConnection>
#include "blackmisc/statusmessagelist.h"
#include "blackgui/models/listmodelbase.h"
namespace BlackGui
{
namespace Models
{
/*!
* Server list model
*/
class CStatusMessageListModel : public CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>
{
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

View File

@@ -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 <QMetaProperty>
#include <QBrush>
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Models
{
/*
* Constructor
*/
CUserListModel::CUserListModel(UserMode userMode, QObject *parent) :
CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>("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;
}
}
}
}

View File

@@ -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 <QAbstractItemModel>
#include "blackmisc/nwuserlist.h"
#include "blackgui/models/listmodelbase.h"
namespace BlackGui
{
namespace Models
{
/*!
* User list model
*/
class CUserListModel : public CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>
{
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