From b35bbd8b81a2a501a1e3a0b24ad6a6e94400c633 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 5 Jan 2017 02:21:33 +0100 Subject: [PATCH] refs #849, model/view for statistics --- src/blackgui/models/allmodels.h | 1 + src/blackgui/models/listmodelbase.cpp | 5 +- .../models/matchingstatisticsmodel.cpp | 58 +++++++++++++++++++ src/blackgui/models/matchingstatisticsmodel.h | 51 ++++++++++++++++ src/blackgui/views/matchingstatisticsview.cpp | 28 +++++++++ src/blackgui/views/matchingstatisticsview.h | 38 ++++++++++++ src/blackgui/views/viewbase.cpp | 9 +-- 7 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 src/blackgui/models/matchingstatisticsmodel.cpp create mode 100644 src/blackgui/models/matchingstatisticsmodel.h create mode 100644 src/blackgui/views/matchingstatisticsview.cpp create mode 100644 src/blackgui/views/matchingstatisticsview.h diff --git a/src/blackgui/models/allmodels.h b/src/blackgui/models/allmodels.h index f1ac491a7..5be60935c 100644 --- a/src/blackgui/models/allmodels.h +++ b/src/blackgui/models/allmodels.h @@ -23,6 +23,7 @@ #include "blackgui/models/distributorlistmodel.h" #include "blackgui/models/identifierlistmodel.h" #include "blackgui/models/liverylistmodel.h" +#include "blackgui/models/matchingstatisticsmodel.h" #include "blackgui/models/namevariantpairlistmodel.h" #include "blackgui/models/serverlistmodel.h" #include "blackgui/models/simulatedaircraftlistmodel.h" diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 767269399..3e1ed9d43 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -47,6 +47,8 @@ #include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/simulation/matchingstatisticsentry.h" +#include "blackmisc/simulation/matchingstatistics.h" #include "blackmisc/statusmessage.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/variant.h" @@ -774,13 +776,14 @@ 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; 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/matchingstatisticsmodel.cpp b/src/blackgui/models/matchingstatisticsmodel.cpp new file mode 100644 index 000000000..7af1eff66 --- /dev/null +++ b/src/blackgui/models/matchingstatisticsmodel.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2017 + * 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 "matchingstatisticsmodel.h" +#include "blackgui/models/columns.h" +#include + +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Models + { + CMatchingStatisticsModel::CMatchingStatisticsModel(MatchingStatisticsMode mode, QObject *parent) : + CListModelBase("MatchingStatisticsModel", parent) + { + this->setMode(mode); + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "session"); + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "model set"); + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "combination"); + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "type"); + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "aircraft"); + (void)QT_TRANSLATE_NOOP("MatchingStatisticsModel", "airline"); + } + + void CMatchingStatisticsModel::setMode(CMatchingStatisticsModel::MatchingStatisticsMode mode) + { + if (this->m_mode == mode) { return; } + this->m_mode = mode; + this->m_columns.clear(); + switch (mode) + { + case ForMultiSessions: + this->m_columns.addColumn(CColumn::standardString("session", CMatchingStatisticsEntry::IndexSessionId)); + this->m_columns.addColumn(CColumn::standardString("model set", CMatchingStatisticsEntry::IndexModelSetId)); + // fall thru + case ForSingleSession: + this->m_columns.addColumn(CColumn("type", CMatchingStatisticsEntry::IndexEntryTypeAsIcon)); + this->m_columns.addColumn(CColumn::standardString("aircraft", CMatchingStatisticsEntry::IndexAircraftDesignator)); + this->m_columns.addColumn(CColumn::standardString("airline", CMatchingStatisticsEntry::IndexAirlineDesignator)); + this->m_columns.addColumn(CColumn::standardString("description", CMatchingStatisticsEntry::IndexDescription)); + this->m_columns.addColumn(CColumn::standardInteger("#", "count", CMatchingStatisticsEntry::IndexCount)); + break; + default: + break; + } + this->setSortColumnByPropertyIndex(CMatchingStatisticsEntry::IndexAircraftDesignator); + } + } // namespace +} // namespace diff --git a/src/blackgui/models/matchingstatisticsmodel.h b/src/blackgui/models/matchingstatisticsmodel.h new file mode 100644 index 000000000..ed17b18d3 --- /dev/null +++ b/src/blackgui/models/matchingstatisticsmodel.h @@ -0,0 +1,51 @@ +/* Copyright (C) 2017 + * 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_MATCHINGSTATISTICSMODEL_H +#define BLACKGUI_MATCHINGSTATISTICSMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodelbase.h" +#include "blackmisc/simulation/matchingstatistics.h" + +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Matching statistics entry + class BLACKGUI_EXPORT CMatchingStatisticsModel : public CListModelBase + { + public: + //! How to display + enum MatchingStatisticsMode + { + NoSet, + ForSingleSession, + ForMultiSessions + }; + + //! Constructor + explicit CMatchingStatisticsModel(MatchingStatisticsMode mode, QObject *parent = nullptr); + + //! Destructor + virtual ~CMatchingStatisticsModel() {} + + //! Set mode + void setMode(MatchingStatisticsMode mode); + + private: + MatchingStatisticsMode m_mode = NoSet; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/views/matchingstatisticsview.cpp b/src/blackgui/views/matchingstatisticsview.cpp new file mode 100644 index 000000000..df657d52c --- /dev/null +++ b/src/blackgui/views/matchingstatisticsview.cpp @@ -0,0 +1,28 @@ +/* Copyright (C) 2017 + * 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 "matchingstatisticsview.h" + +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + CMatchingStatisticsView::CMatchingStatisticsView(QWidget *parent) : CViewBase(parent) + { + this->standardInit(new CMatchingStatisticsModel(CMatchingStatisticsModel::ForSingleSession, this)); + } + + void CMatchingStatisticsView::setStatisticsModelMode(CMatchingStatisticsModel::MatchingStatisticsMode mode) + { + this->m_model->setMode(mode); + } + } +} // namespace diff --git a/src/blackgui/views/matchingstatisticsview.h b/src/blackgui/views/matchingstatisticsview.h new file mode 100644 index 000000000..c7bb02b44 --- /dev/null +++ b/src/blackgui/views/matchingstatisticsview.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2017 + * 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_MATCHINGSTATISTICSVIEW_H +#define BLACKGUI_VIEWS_MATCHINGSTATISTICSVIEW_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/matchingstatisticsmodel.h" +#include "blackgui/views/viewbase.h" +#include "blackmisc/network/serverlist.h" + +class QWidget; + +namespace BlackGui +{ + namespace Views + { + //! Matching statistics + class BLACKGUI_EXPORT CMatchingStatisticsView : public CViewBase + { + public: + //! Constructor + explicit CMatchingStatisticsView(QWidget *parent = nullptr); + + //! Set vie mode + void setStatisticsModelMode(Models::CMatchingStatisticsModel::MatchingStatisticsMode mode); + }; + } +} // ns +#endif // guard diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index e846c6df8..6f194c3cd 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -53,6 +53,8 @@ #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/distributor.h" #include "blackmisc/simulation/distributorlist.h" +#include "blackmisc/simulation/matchingstatisticsentry.h" +#include "blackmisc/simulation/matchingstatistics.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/statusmessagelist.h" @@ -1440,20 +1442,19 @@ namespace BlackGui template class CViewBase; template class CViewBase; template class CViewBase; + template class CViewBase; template class CViewBase; template class CViewBase; template class CViewBase; template class CViewBase; + template class CViewBase; template class CViewBase; template class CViewBase; template class CViewBase; template class CViewBase; + template class CViewBase; template class CViewBase; template class CViewBase; - - template class CViewBase; - template class CViewBase; template class CViewBase; - } // namespace } // namespace