Ref T472, category model/view + tree view

This commit is contained in:
Klaus Basan
2019-02-03 21:37:30 +01:00
committed by Mat Sutcliffe
parent b85222e1f5
commit 969600b65d
14 changed files with 500 additions and 0 deletions

View 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

View 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

View 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

View 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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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>;

View File

@@ -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>;