diff --git a/src/blackgui/models/aircraftpartslistmodel.cpp b/src/blackgui/models/aircraftpartslistmodel.cpp new file mode 100644 index 000000000..093071567 --- /dev/null +++ b/src/blackgui/models/aircraftpartslistmodel.cpp @@ -0,0 +1,40 @@ +/* Copyright (C) 2018 + * 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 "blackgui/models/aircraftpartslistmodel.h" +#include "blackgui/models/columnformatters.h" +#include "blackgui/models/columns.h" +#include "blackmisc/aviation/aircraftpartslist.h" +#include "blackmisc/propertyindex.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + namespace Models + { + CAircraftPartsListModel::CAircraftPartsListModel(QObject *parent) : + CListModelTimestampObjects("ViewAircraftPartsList", parent) + { + this->addTimestampOffsetColumns(); + + m_columns.addColumn(CColumn("gnd.", CAircraftParts::IndexOnGround, new CBoolIconFormatter("on gnd.", "not on gnd."))); + m_columns.addColumn(CColumn("gear", CAircraftParts::IndexGearDown, new CBoolIconFormatter("gear down", "gear up"))); + m_columns.addColumn(CColumn("spoilers", CAircraftParts::IndexSpoilersOut, new CBoolIconFormatter("spoilers", "no spoilers"))); + m_columns.addColumn(CColumn("flaps", CAircraftParts::IndexFlapsPercentage, new CIntegerFormatter())); + + m_columns.addColumn(CColumn::standardString("engines", { CAircraftParts::IndexEngines, CAircraftParts::IndexString })); + m_columns.addColumn(CColumn::standardString("lights", { CAircraftParts::IndexLights, CAircraftParts::IndexString })); + } + } // namespace +} // namespace diff --git a/src/blackgui/models/aircraftpartslistmodel.h b/src/blackgui/models/aircraftpartslistmodel.h new file mode 100644 index 000000000..e0efd27dd --- /dev/null +++ b/src/blackgui/models/aircraftpartslistmodel.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2018 + * 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_MODELS_AIRCRAFTPARTSLISTMODEL_H +#define BLACKGUI_MODELS_AIRCRAFTPARTSLISTMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodeltimestampobjects.h" +#include "blackmisc/aviation/aircraftpartslist.h" + +#include + +class QModelIndex; +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Client list model + class BLACKGUI_EXPORT CAircraftPartsListModel : public CListModelTimestampObjects + { + public: + //! Constructor + explicit CAircraftPartsListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CAircraftPartsListModel() {} + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackgui/models/aircraftsituationlistmodel.cpp b/src/blackgui/models/aircraftsituationlistmodel.cpp new file mode 100644 index 000000000..82002ee5a --- /dev/null +++ b/src/blackgui/models/aircraftsituationlistmodel.cpp @@ -0,0 +1,48 @@ +/* Copyright (C) 2018 + * 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 "blackgui/models/aircraftsituationlistmodel.h" +#include "blackgui/models/columnformatters.h" +#include "blackgui/models/columns.h" +#include "blackmisc/aviation/aircraftsituationlist.h" +#include "blackmisc/propertyindex.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackGui +{ + namespace Models + { + CAircraftSituationListModel::CAircraftSituationListModel(QObject *parent) : + CListModelTimestampObjects("ViewAircraftPartsList", parent) + { + this->addTimestampOffsetColumns(); + + m_columns.addColumn(CColumn("altitude", CAircraftSituation::IndexAltitude, new CAltitudeFormatter())); + m_columns.addColumn(CColumn("CG", CAircraftSituation::IndexCG, new CPhysiqalQuantiyFormatter(CLengthUnit::ft(), 1))); + m_columns.addColumn(CColumn("latitude", CAircraftSituation::IndexLatitude, new CLatLonFormatter())); + m_columns.addColumn(CColumn("longitude", CAircraftSituation::IndexLongitude, new CLatLonFormatter())); + m_columns.addColumn(CColumn("gs.", CAircraftSituation::IndexGroundSpeed, new CSpeedKtsFormatter())); + m_columns.addColumn(CColumn("on gnd.", "is on gnd.", CAircraftSituation::IndexIsOnGround, new CBoolIconFormatter("yes", "no"), true)); + m_columns.addColumn(CColumn::standardString("reliability", CAircraftSituation::IndexOnGroundReliabilityString)); + m_columns.addColumn(CColumn::standardString("gnd.elv.", { CAircraftSituation::IndexGroundElevationPlane, CElevationPlane::IndexGeodeticHeightAsString })); + m_columns.addColumn(CColumn("elv.radius", { CAircraftSituation::IndexGroundElevationPlane, CElevationPlane::IndexRadius }, new CPhysiqalQuantiyFormatter(CLengthUnit::m(), 1))); + + // default sort order + this->setSortColumnByPropertyIndex(CAircraftSituation::IndexAdjustedMsWithOffset); + m_sortOrder = Qt::DescendingOrder; + } + } // namespace +} // namespace diff --git a/src/blackgui/models/aircraftsituationlistmodel.h b/src/blackgui/models/aircraftsituationlistmodel.h new file mode 100644 index 000000000..6ec9bbe67 --- /dev/null +++ b/src/blackgui/models/aircraftsituationlistmodel.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2018 + * 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_MODELS_AIRCRAFTSITUATIONLISTMODEL_H +#define BLACKGUI_MODELS_AIRCRAFTSITUATIONLISTMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodeltimestampobjects.h" +#include "blackmisc/aviation/aircraftsituationlist.h" + +#include + +class QModelIndex; +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Client list model + class BLACKGUI_EXPORT CAircraftSituationListModel : public CListModelTimestampObjects + { + public: + //! Constructor + explicit CAircraftSituationListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CAircraftSituationListModel() {} + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackgui/models/allmodelcontainers.h b/src/blackgui/models/allmodelcontainers.h index e969d384c..52db51f3b 100644 --- a/src/blackgui/models/allmodelcontainers.h +++ b/src/blackgui/models/allmodelcontainers.h @@ -19,6 +19,8 @@ #include "blackmisc/aviation/airlineicaocodelist.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/aircraftpartslist.h" +#include "blackmisc/aviation/aircraftsituationlist.h" #include "blackmisc/aviation/liverylist.h" #include "blackmisc/network/clientlist.h" #include "blackmisc/network/serverlist.h" diff --git a/src/blackgui/models/allmodels.h b/src/blackgui/models/allmodels.h index 660c747c9..b8a3e8e04 100644 --- a/src/blackgui/models/allmodels.h +++ b/src/blackgui/models/allmodels.h @@ -13,9 +13,10 @@ #include "blackgui/models/actionhotkeylistmodel.h" #include "blackgui/models/aircrafticaolistmodel.h" #include "blackgui/models/aircraftmodellistmodel.h" +#include "blackgui/models/aircraftpartslistmodel.h" +#include "blackgui/models/aircraftsituationlistmodel.h" #include "blackgui/models/airlineicaolistmodel.h" #include "blackgui/models/airportlistmodel.h" -#include "blackgui/models/airportlistmodel.h" #include "blackgui/models/applicationinfolistmodel.h" #include "blackgui/models/atcstationlistmodel.h" #include "blackgui/models/clientlistmodel.h" diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 1bb8c5af8..9a8e2f1d1 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -44,26 +44,17 @@ namespace BlackGui QVariant CListModelBaseNonTemplate::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation != Qt::Horizontal) - { - return QVariant(); - } - bool handled = (role == Qt::DisplayRole || role == Qt::ToolTipRole || role == Qt::InitialSortOrderRole); - if (!handled) - { - return QVariant(); - } - if (section < 0 || section >= m_columns.size()) - { - return QVariant(); - } + if (orientation != Qt::Horizontal) { return QVariant(); } + const bool handled = (role == Qt::DisplayRole || role == Qt::ToolTipRole || role == Qt::InitialSortOrderRole); + if (!handled) { return QVariant(); } + if (section < 0 || section >= m_columns.size()) { return QVariant(); } if (role == Qt::DisplayRole) { QString header = m_columns.at(section).getColumnName(false); return QVariant(header); } - else if (role == Qt::ToolTipRole) + if (role == Qt::ToolTipRole) { QString header = m_columns.at(section).getColumnToolTip(false); return header.isEmpty() ? QVariant() : QVariant(header); @@ -375,8 +366,8 @@ namespace BlackGui if (index.row() >= m_container.size()) { return; } m_container[index.row()] = object; - QModelIndex i1 = index.sibling(index.row(), 0); - QModelIndex i2 = index.sibling(index.row(), this->columnCount(index) - 1); + const QModelIndex i1 = index.sibling(index.row(), 0); + const QModelIndex i2 = index.sibling(index.row(), this->columnCount(index) - 1); emit this->dataChanged(i1, i2); // which range has been changed } @@ -777,6 +768,8 @@ namespace BlackGui template class CListModelBase; template class CListModelBase; template class CListModelBase; + template class CListModelBase; + template class CListModelBase; template class CListModelBase; template class CListModelBase; template class CListModelBase; diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h index 8d39995fc..3f0eb0f51 100644 --- a/src/blackgui/models/listmodelbase.h +++ b/src/blackgui/models/listmodelbase.h @@ -12,11 +12,11 @@ #ifndef BLACKGUI_LISTMODELBASE_H #define BLACKGUI_LISTMODELBASE_H -#include "blackgui/blackguiexport.h" -#include "blackgui/dropbase.h" #include "blackgui/models/columns.h" #include "blackgui/models/modelfilter.h" #include "blackgui/models/selectionmodel.h" +#include "blackgui/dropbase.h" +#include "blackgui/blackguiexport.h" #include "blackmisc/digestsignal.h" #include "blackmisc/variant.h" diff --git a/src/blackgui/models/listmodeltimestampobjects.cpp b/src/blackgui/models/listmodeltimestampobjects.cpp new file mode 100644 index 000000000..9c88fbe71 --- /dev/null +++ b/src/blackgui/models/listmodeltimestampobjects.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2018 + * 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 "listmodeltimestampobjects.h" +#include "allmodelcontainers.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; + +namespace BlackGui +{ + namespace Models + { + template + CListModelTimestampObjects::CListModelTimestampObjects(const QString &translationContext, QObject *parent) : + CListModelBase(translationContext, parent) + { } + + template + void CListModelTimestampObjects::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max) + { + this->beginInsertRows(QModelIndex(), 0, 0); + CListModelBase::m_container.push_frontKeepLatestAdjustedFirst(object, max); + this->endInsertRows(); + } + + template + void CListModelTimestampObjects::addTimestampOffsetColumns() + { + CListModelBaseNonTemplate::m_columns.addColumn(CColumn::standardString("timestamp", ObjectType::IndexUtcTimestampFormattedMdhmsz)); + CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms", ObjectType::IndexMSecsSinceEpoch, new CIntegerFormatter())); + CListModelBaseNonTemplate::m_columns.addColumn(CColumn("ms adj.", ObjectType::IndexAdjustedMsWithOffset, new CIntegerFormatter())); + CListModelBaseNonTemplate::m_columns.addColumn(CColumn("offset", ObjectType::IndexOffsetMs, new CIntegerFormatter())); + } + + // see here for the reason of thess forward instantiations + // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl + template class CListModelTimestampObjects; + template class CListModelTimestampObjects; + + } // namespace +} // namespace diff --git a/src/blackgui/models/listmodeltimestampobjects.h b/src/blackgui/models/listmodeltimestampobjects.h new file mode 100644 index 000000000..486b4acb5 --- /dev/null +++ b/src/blackgui/models/listmodeltimestampobjects.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2018 + * 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_MODELS_LISTMODELTIMESTAMPOBJECTS_H +#define BLACKGUI_MODELS_LISTMODELTIMESTAMPOBJECTS_H + +#include "blackgui/models/listmodelbase.h" + +#include +#include +#include + +class QModelIndex; +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! List model for timestamp based objects + template class CListModelTimestampObjects : + public CListModelBase + { + public: + //! Destructor + virtual ~CListModelTimestampObjects() {} + + //! Insert as first element by keeping maxElements and the latest first + void push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max); + + protected: + //! Constructor + CListModelTimestampObjects(const QString &translationContext, QObject *parent = nullptr); + + //! Standard timestamp offset columns + void addTimestampOffsetColumns(); + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackgui/views/aircraftpartsview.cpp b/src/blackgui/views/aircraftpartsview.cpp new file mode 100644 index 000000000..fb940be9c --- /dev/null +++ b/src/blackgui/views/aircraftpartsview.cpp @@ -0,0 +1,25 @@ +/* Copyright (C) 2018 + * 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 "blackgui/views/aircraftpartsview.h" + +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + CAircraftPartsView::CAircraftPartsView(QWidget *parent) : + CViewWithTimestampObjects(parent) + { + this->standardInit(new CAircraftPartsListModel(this)); + this->setMenu(MenuDefault); + } + } // ns +} // ns diff --git a/src/blackgui/views/aircraftpartsview.h b/src/blackgui/views/aircraftpartsview.h new file mode 100644 index 000000000..f2b120eb9 --- /dev/null +++ b/src/blackgui/views/aircraftpartsview.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2018 + * 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_VIEWS_AIRCRAFTPARTSVIEW_H +#define BLACKGUI_VIEWS_AIRCRAFTPARTSVIEW_H + +#include "blackgui/views/viewtimestampobjects.h" +#include "blackgui/models/aircraftpartslistmodel.h" +#include "blackgui/blackguiexport.h" +#include "blackmisc/aviation/aircraftpartslist.h" + +class QWidget; + +namespace BlackGui +{ + namespace Views + { + //! Aircraft parts + class BLACKGUI_EXPORT CAircraftPartsView : public CViewWithTimestampObjects + { + public: + //! Constructor + explicit CAircraftPartsView(QWidget *parent = nullptr); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/views/aircraftsituationview.cpp b/src/blackgui/views/aircraftsituationview.cpp new file mode 100644 index 000000000..d5497338d --- /dev/null +++ b/src/blackgui/views/aircraftsituationview.cpp @@ -0,0 +1,25 @@ +/* Copyright (C) 2018 + * 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 "blackgui/views/aircraftsituationview.h" + +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + CAircraftSituationView::CAircraftSituationView(QWidget *parent) : + CViewWithTimestampObjects(parent) + { + this->standardInit(new CAircraftSituationListModel(this)); + this->setMenu(MenuDefault); + } + } // ns +} // ns diff --git a/src/blackgui/views/aircraftsituationview.h b/src/blackgui/views/aircraftsituationview.h new file mode 100644 index 000000000..214677454 --- /dev/null +++ b/src/blackgui/views/aircraftsituationview.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2018 + * 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_VIEWS_AIRCRAFTSITUATIONVIEW_H +#define BLACKGUI_VIEWS_AIRCRAFTSITUATIONVIEW_H + +#include "blackgui/views/viewtimestampobjects.h" +#include "blackgui/models/aircraftsituationlistmodel.h" +#include "blackgui/blackguiexport.h" +#include "blackmisc/aviation/aircraftsituationlist.h" + +class QWidget; + +namespace BlackGui +{ + namespace Views + { + //! Aircraft situations view + class BLACKGUI_EXPORT CAircraftSituationView : public CViewWithTimestampObjects + { + public: + //! Constructor + explicit CAircraftSituationView(QWidget *parent = nullptr); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index e66852430..8a1942d84 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -1706,6 +1706,8 @@ namespace BlackGui // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl template class CViewBase; template class CViewBase; + template class CViewBase; + template class CViewBase; template class CViewBase; template class CViewBase; template class CViewBase; @@ -1726,5 +1728,6 @@ namespace BlackGui template class CViewBase; template class CViewBase; template class CViewBase; + } // namespace } // namespace diff --git a/src/blackgui/views/viewtimestampobjects.cpp b/src/blackgui/views/viewtimestampobjects.cpp new file mode 100644 index 000000000..cd781ac42 --- /dev/null +++ b/src/blackgui/views/viewtimestampobjects.cpp @@ -0,0 +1,41 @@ +/* Copyright (C) 2018 + * 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 "blackgui/views/viewtimestampobjects.h" +#include "blackgui/models/aircraftpartslistmodel.h" +#include "blackgui/models/aircraftsituationlistmodel.h" +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackGui; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + template + void CViewWithTimestampObjects::push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max) + { + this->derivedModel()->push_frontKeepLatestAdjustedFirst(object, max); + } + + template + CViewWithTimestampObjects::CViewWithTimestampObjects(QWidget *parent) : + CViewBase(parent) + { + // void + } + + template class CViewWithTimestampObjects; + template class CViewWithTimestampObjects; + + } // namespace +} // namespace diff --git a/src/blackgui/views/viewtimestampobjects.h b/src/blackgui/views/viewtimestampobjects.h new file mode 100644 index 000000000..9bfe20857 --- /dev/null +++ b/src/blackgui/views/viewtimestampobjects.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2018 + * 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_VIEWS_VIEWTIMESTAMPOBJECTS_H +#define BLACKGUI_VIEWS_VIEWTIMESTAMPOBJECTS_H + +#include "viewbase.h" +#include +#include +#include + +namespace BlackGui +{ + namespace Menus { class CMenuActions; } + namespace Views + { + //! Base class for views with DB objects + template class CViewWithTimestampObjects : + public CViewBase + { + public: + //! Insert as first element by keeping maxElements and the latest first + void push_frontKeepLatestAdjustedFirst(const ObjectType &object, int max); + + protected: + //! Constructor + explicit CViewWithTimestampObjects(QWidget *parent = nullptr); + }; + } // namespace +} // namespace +#endif // guard