mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
Ref T472, category model/view + tree view
This commit is contained in:
committed by
Mat Sutcliffe
parent
b85222e1f5
commit
969600b65d
40
src/blackgui/models/aircraftcategorylistmodel.cpp
Normal file
40
src/blackgui/models/aircraftcategorylistmodel.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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/aircraftcategorylistmodel.h"
|
||||
#include "blackgui/models/columnformatters.h"
|
||||
#include "blackgui/models/columns.h"
|
||||
#include "blackmisc/db/datastore.h"
|
||||
#include "blackmisc/timestampbased.h"
|
||||
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
CAircraftCategoryListModel::CAircraftCategoryListModel(QObject *parent) :
|
||||
CListModelDbObjects("AircraftCategoryListModel", parent)
|
||||
{
|
||||
m_columns.addColumn(CColumn::standardString("id", CAircraftCategory::IndexDbIntegerKey, CDefaultFormatter::alignRightVCenter()));
|
||||
m_columns.addColumn(CColumn::standardString("level", CAircraftCategory::IndexLevelString));
|
||||
m_columns.addColumn(CColumn::standardString("path", CAircraftCategory::IndexPath));
|
||||
m_columns.addColumn(CColumn::standardString("name", CAircraftCategory::IndexName));
|
||||
m_columns.addColumn(CColumn::standardString("description", CAircraftCategory::IndexDescription));
|
||||
m_columns.addColumn(CColumn::standardString("changed", CAircraftCategory::IndexUtcTimestampFormattedYmdhms));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CAircraftCategory::IndexLevelString);
|
||||
m_sortOrder = Qt::AscendingOrder;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
39
src/blackgui/models/aircraftcategorylistmodel.h
Normal file
39
src/blackgui/models/aircraftcategorylistmodel.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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_AIRCRAFTCATEGORYLISTMODEL_H
|
||||
#define BLACKGUI_MODELS_AIRCRAFTCATEGORYLISTMODEL_H
|
||||
|
||||
#include "blackmisc/aviation/aircraftcategorylist.h"
|
||||
#include "blackmisc/aviation/aircraftcategory.h"
|
||||
#include "blackgui/models/listmodeldbobjects.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
//! Airport list model
|
||||
class BLACKGUI_EXPORT CAircraftCategoryListModel :
|
||||
public CListModelDbObjects<BlackMisc::Aviation::CAircraftCategoryList, int, true>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CAircraftCategoryListModel(QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAircraftCategoryListModel() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
109
src/blackgui/models/aircraftcategorytreemodel.cpp
Normal file
109
src/blackgui/models/aircraftcategorytreemodel.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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/aircraftcategorytreemodel.h"
|
||||
#include "blackgui/models/columnformatters.h"
|
||||
#include "blackgui/models/columns.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QStandardItem>
|
||||
#include <QStandardItemModel>
|
||||
#include <QString>
|
||||
#include <Qt>
|
||||
#include <QtDebug>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
CAircraftCategoryTreeModel::CAircraftCategoryTreeModel(QObject *parent) : QStandardItemModel(parent)
|
||||
{
|
||||
m_columns.addColumn(CColumn::standardString("description", CAircraftCategory::IndexDescription));
|
||||
m_columns.addColumn(CColumn::standardString("changed", CAircraftCategory::IndexUtcTimestampFormattedYmdhms));
|
||||
}
|
||||
|
||||
void CAircraftCategoryTreeModel::updateContainer(const CAircraftCategoryList &categories)
|
||||
{
|
||||
if (categories.isEmpty())
|
||||
{
|
||||
CAircraftCategoryTreeModel::clear();
|
||||
return;
|
||||
}
|
||||
|
||||
m_categories = categories;
|
||||
m_categories.sortByLevel();
|
||||
QStandardItemModel::clear();
|
||||
QMap<int, QStandardItem *> items;
|
||||
this->setColumnCount(m_columns.size() + 1);
|
||||
|
||||
for (const CAircraftCategory &category : m_categories)
|
||||
{
|
||||
QList<QStandardItem *> categoryRow;
|
||||
|
||||
// ownership of QStandardItem is taken by model
|
||||
QStandardItem *si = new QStandardItem(
|
||||
category.isAssignable() ? CIcons::paperPlane16() : CIcons::folder16(),
|
||||
category.getLevelAndName()
|
||||
);
|
||||
si->setEditable(false);
|
||||
categoryRow.push_back(si);
|
||||
|
||||
// add all clumns
|
||||
for (const CColumn &column : m_columns.columns())
|
||||
{
|
||||
const CPropertyIndex i(column.getPropertyIndex());
|
||||
const CVariant v(category.propertyByIndex(i));
|
||||
|
||||
if (column.getFormatter()->supportsRole(Qt::DecorationRole))
|
||||
{
|
||||
const QIcon icon = column.getFormatter()->decorationRole(v).toPixmap();
|
||||
si = new QStandardItem(icon, QString());
|
||||
}
|
||||
else if (column.getFormatter()->supportsRole(Qt::DisplayRole))
|
||||
{
|
||||
const CVariant f = column.getFormatter()->displayRole(v);
|
||||
si = new QStandardItem(f.toQString(true));
|
||||
}
|
||||
if (!si) { continue; }
|
||||
si->setEditable(false); // make not editable
|
||||
categoryRow.push_back(si);
|
||||
} // columns
|
||||
|
||||
// add all items
|
||||
if (categoryRow.isEmpty()) { continue; }
|
||||
if (category.isFirstLevel())
|
||||
{
|
||||
this->invisibleRootItem()->appendRow(categoryRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int p = category.getDepth() - 1;
|
||||
items[p]->appendRow(categoryRow);
|
||||
}
|
||||
items.insert(category.getDepth(), categoryRow.front());
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftCategoryTreeModel::clear()
|
||||
{
|
||||
m_categories.clear();
|
||||
QStandardItemModel::clear();
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
57
src/blackgui/models/aircraftcategorytreemodel.h
Normal file
57
src/blackgui/models/aircraftcategorytreemodel.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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_AIRCRAFTCATEGORYTREEMODEL_H
|
||||
#define BLACKGUI_MODELS_AIRCRAFTCATEGORYTREEMODEL_H
|
||||
|
||||
#include "columns.h"
|
||||
#include "blackmisc/aviation/aircraftcategorylist.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
//! ATC list model
|
||||
class BLACKGUI_EXPORT CAircraftCategoryTreeModel : public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CAircraftCategoryTreeModel(QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAircraftCategoryTreeModel() override {}
|
||||
|
||||
//! Set columns
|
||||
void setColumns(const CColumns &columns) { m_columns.setColumns(columns); }
|
||||
|
||||
//! Update container
|
||||
void updateContainer(const BlackMisc::Aviation::CAircraftCategoryList &categories);
|
||||
|
||||
//! Clear everything
|
||||
//! \remark hiding QStandardItemModel::clear()
|
||||
void clear();
|
||||
|
||||
//! Get container
|
||||
const BlackMisc::Aviation::CAircraftCategoryList &container() const { return m_categories; }
|
||||
|
||||
private:
|
||||
CColumns m_columns { "CAircraftCategoryTreeModel" };
|
||||
BlackMisc::Aviation::CAircraftCategoryList m_categories;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/matchingstatistics.h"
|
||||
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
||||
#include "blackmisc/aviation/aircraftcategorylist.h"
|
||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||
#include "blackmisc/aviation/airportlist.h"
|
||||
#include "blackmisc/aviation/atcstationlist.h"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "blackgui/models/actionhotkeylistmodel.h"
|
||||
#include "blackgui/models/aircrafticaolistmodel.h"
|
||||
#include "blackgui/models/aircraftcategorylistmodel.h"
|
||||
#include "blackgui/models/aircraftmodellistmodel.h"
|
||||
#include "blackgui/models/aircraftpartslistmodel.h"
|
||||
#include "blackgui/models/aircraftsituationlistmodel.h"
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace BlackGui
|
||||
template class CListModelBase<BlackMisc::Aviation::CAtcStationList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirportList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftCategoryList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirlineIcaoCodeList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftPartsList, true>;
|
||||
template class CListModelBase<BlackMisc::Aviation::CAircraftSituationList, true>;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "blackmisc/simulation/distributor.h"
|
||||
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/aviation/aircraftcategorylist.h"
|
||||
#include "blackmisc/aviation/aircraftcategory.h"
|
||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "blackmisc/aviation/liverylist.h"
|
||||
@@ -114,6 +116,7 @@ namespace BlackGui
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CLiveryList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::CCountryList, QString, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAircraftIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAircraftCategoryList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Aviation::CAirlineIcaoCodeList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CAircraftModelList, int, true>;
|
||||
template class CListModelDbObjects<BlackMisc::Simulation::CDistributorList, QString, true>;
|
||||
|
||||
Reference in New Issue
Block a user