mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
refs #568, specialized view class for DB objects
* CViewWithDbObjects * new menu for views (delete key, remove) * adjusted derived classes
This commit is contained in:
103
src/blackgui/views/viewdbobjects.cpp
Normal file
103
src/blackgui/views/viewdbobjects.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/* Copyright (C) 2015
|
||||
* 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 "viewdbobjects.h"
|
||||
#include "blackgui/models/allmodels.h"
|
||||
#include <QAction>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui;
|
||||
using namespace BlackGui::Models;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::CViewWithDbObjects(QWidget *parent) :
|
||||
CViewBase<ModelClass, ContainerType, ObjectType>(parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
ObjectType CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::latestObject() const
|
||||
{
|
||||
return this->container().latestObject();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
ObjectType CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::oldestObject() const
|
||||
{
|
||||
return this->container().oldestObject();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::selectDbKeys(const QList<KeyType> &keys)
|
||||
{
|
||||
if (keys.isEmpty()) { return; }
|
||||
this->clearSelection();
|
||||
int r = -1;
|
||||
for (const ObjectType &obj : CViewBase<ModelClass, ContainerType, ObjectType>::containerOrFilteredContainer())
|
||||
{
|
||||
r++;
|
||||
if (!obj.hasValidDbKey()) { continue; }
|
||||
if (keys.contains(obj.getDbKey()))
|
||||
{
|
||||
this->selectRow(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
int CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::removeDbKeys(const QList<KeyType> &keys)
|
||||
{
|
||||
if (keys.isEmpty()) { return 0; }
|
||||
if (this->isEmpty()) { return 0; }
|
||||
|
||||
ContainerType newObjects(this->container());
|
||||
int delta = newObjects.removeObjectsWithKeys(keys);
|
||||
if (delta > 0)
|
||||
{
|
||||
this->updateContainerMaybeAsync(newObjects);
|
||||
}
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(QMenu &menu) const
|
||||
{
|
||||
CViewBase<ModelClass, ContainerType, ObjectType>::customMenu(menu);
|
||||
if (this->m_menus.testFlag(CViewBase<ModelClass, ContainerType, ObjectType>::MenuHighlightDbData))
|
||||
{
|
||||
menu.addSeparator();
|
||||
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB data", this, SLOT(ps_toggleDbData()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(this->derivedModel()->highlightDbData());
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleDbData()
|
||||
{
|
||||
bool h = this->derivedModel()->highlightDbData();
|
||||
this->derivedModel()->setHighlightDbData(!h);
|
||||
}
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CViewWithDbObjects<BlackGui::Models::CAircraftIcaoCodeListModel, BlackMisc::Aviation::CAircraftIcaoCodeList, BlackMisc::Aviation::CAircraftIcaoCode, int>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CAirlineIcaoCodeListModel, BlackMisc::Aviation::CAirlineIcaoCodeList, BlackMisc::Aviation::CAirlineIcaoCode, int>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CCountryListModel, BlackMisc::CCountryList, BlackMisc::CCountry, QString>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CLiveryListModel, BlackMisc::Aviation::CLiveryList, BlackMisc::Aviation::CLivery, int>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user