mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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:
@@ -50,4 +50,15 @@ namespace BlackGui
|
||||
return k;
|
||||
}
|
||||
|
||||
const QKeySequence &CShortcut::keyDelete()
|
||||
{
|
||||
static const QKeySequence k(Qt::Key_Delete);
|
||||
return k;
|
||||
}
|
||||
|
||||
const QKeySequence &CShortcut::keyEscape()
|
||||
{
|
||||
static const QKeySequence k(Qt::Key_Escape);
|
||||
return k;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -44,6 +44,12 @@ namespace BlackGui
|
||||
|
||||
//! Save in views
|
||||
static const QKeySequence &keySaveViews();
|
||||
|
||||
//! Delete, e.g. selected rows
|
||||
static const QKeySequence &keyDelete();
|
||||
|
||||
//! Escape
|
||||
static const QKeySequence &keyEscape();
|
||||
};
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CAircraftIcaoCodeView::CAircraftIcaoCodeView(QWidget *parent) : CViewBase(parent)
|
||||
CAircraftIcaoCodeView::CAircraftIcaoCodeView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
{
|
||||
this->m_menus |= MenuBackend;
|
||||
this->standardInit(new CAircraftIcaoCodeListModel(this));
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define BLACKGUI_AIRCRAFTICAOVIEW_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "viewbase.h"
|
||||
#include "viewdbobjects.h"
|
||||
#include "../models/aircrafticaolistmodel.h"
|
||||
|
||||
namespace BlackGui
|
||||
@@ -21,9 +21,9 @@ namespace BlackGui
|
||||
namespace Views
|
||||
{
|
||||
//! Aircraft ICAO codes view
|
||||
class BLACKGUI_EXPORT CAircraftIcaoCodeView : public CViewBase<Models::CAircraftIcaoCodeListModel, BlackMisc::Aviation::CAircraftIcaoCodeList, BlackMisc::Aviation::CAircraftIcaoCode>
|
||||
class BLACKGUI_EXPORT CAircraftIcaoCodeView :
|
||||
public CViewWithDbObjects<Models::CAircraftIcaoCodeListModel, BlackMisc::Aviation::CAircraftIcaoCodeList, BlackMisc::Aviation::CAircraftIcaoCode, int>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CAircraftIcaoCodeView(QWidget *parent = nullptr);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CAircraftModelView::CAircraftModelView(QWidget *parent) : CViewBase(parent)
|
||||
CAircraftModelView::CAircraftModelView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
{
|
||||
// default
|
||||
this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::OwnSimulatorModel, this));
|
||||
@@ -50,26 +50,22 @@ namespace BlackGui
|
||||
switch (mode)
|
||||
{
|
||||
case CAircraftModelListModel::StashModel:
|
||||
this->m_menus = MenuClear;
|
||||
this->setCustomMenu(new CHighlightDbModelsMenu(this, true));
|
||||
this->m_menus = MenuClear | MenuHighlightDbData;
|
||||
break;
|
||||
case CAircraftModelListModel::Database:
|
||||
this->m_menus = MenuBackend;
|
||||
break;
|
||||
case CAircraftModelListModel::VPilotRuleModel:
|
||||
this->m_menus = MenuRefresh;
|
||||
this->setCustomMenu(new CHighlightDbModelsMenu(this, true));
|
||||
this->m_menus = MenuRefresh | MenuHighlightDbData;;
|
||||
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
|
||||
break;
|
||||
case CAircraftModelListModel::OwnSimulatorModelMapping:
|
||||
this->m_menus = MenuDisplayAutomatically;
|
||||
this->setCustomMenu(new CHighlightDbModelsMenu(this, true));
|
||||
this->m_menus = MenuDisplayAutomatically | MenuHighlightDbData;
|
||||
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
|
||||
break;
|
||||
case CAircraftModelListModel::OwnSimulatorModel:
|
||||
default:
|
||||
this->m_menus = MenuDisplayAutomatically | MenuBackend | MenuRefresh;
|
||||
this->setCustomMenu(new CHighlightDbModelsMenu(this, true));
|
||||
this->m_menus = MenuDisplayAutomatically | MenuBackend | MenuRefresh | MenuHighlightDbData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +91,7 @@ namespace BlackGui
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CAircraftModelView::hasModelsToStash() const
|
||||
bool CAircraftModelView::hasSelectedModelsToStash() const
|
||||
{
|
||||
return m_allowStash && hasSelection();
|
||||
}
|
||||
@@ -117,6 +113,18 @@ namespace BlackGui
|
||||
this->setFilterDialog(new CAircraftModelFilterDialog(this));
|
||||
}
|
||||
|
||||
int CAircraftModelView::removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity)
|
||||
{
|
||||
if (modelStrings.isEmpty()) { return 0; }
|
||||
CAircraftModelList copy(this->container());
|
||||
int delta = copy.removeModelsWithString(modelStrings, sensitivity);
|
||||
if (delta > 0)
|
||||
{
|
||||
this->updateContainerMaybeAsync(copy);
|
||||
}
|
||||
return delta;
|
||||
}
|
||||
|
||||
void CAircraftModelView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!isDropAllowed()) { return; }
|
||||
@@ -207,12 +215,6 @@ namespace BlackGui
|
||||
} // valid mime?
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightDbModels()
|
||||
{
|
||||
bool h = derivedModel()->highlightDbData();
|
||||
derivedModel()->setHighlightDbData(!h);
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightStashedModels()
|
||||
{
|
||||
bool h = derivedModel()->highlightGivenModelStrings();
|
||||
@@ -225,16 +227,6 @@ namespace BlackGui
|
||||
emit requestStash();
|
||||
}
|
||||
|
||||
void CAircraftModelView::CHighlightDbModelsMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
|
||||
Q_ASSERT_X(mv, Q_FUNC_INFO, "no view");
|
||||
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB models", mv, SLOT(ps_toggleHighlightDbModels()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(mv->derivedModel()->highlightDbData());
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
|
||||
void CAircraftModelView::CHighlightStashedModelsMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/filters/aircraftmodelfilterdialog.h"
|
||||
#include "blackgui/models/aircraftmodellistmodel.h"
|
||||
#include "viewbase.h"
|
||||
#include "viewdbobjects.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Aircraft view
|
||||
class BLACKGUI_EXPORT CAircraftModelView :
|
||||
public CViewBase<Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel>
|
||||
public CViewWithDbObjects<Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -46,15 +46,18 @@ namespace BlackGui
|
||||
//! Allow to stash
|
||||
void setAllowStash(bool stash) { m_allowStash = stash; }
|
||||
|
||||
//! Has any models to stash amd is allowed to stash
|
||||
bool hasModelsToStash() const;
|
||||
//! Has any models to stash and it is allowed to stash
|
||||
bool hasSelectedModelsToStash() const;
|
||||
|
||||
//! Add the technically supported metatypes as allows
|
||||
//! Add the technically supported metatypes allowed for drag and drop
|
||||
void setImplementedMetaTypeIds();
|
||||
|
||||
//! Add my own filter dialog
|
||||
void addFilterDialog();
|
||||
|
||||
//! Remove models with model strings
|
||||
int removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
|
||||
|
||||
signals:
|
||||
//! Request to stash if applicable
|
||||
void requestStash();
|
||||
@@ -67,9 +70,6 @@ namespace BlackGui
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private slots:
|
||||
//! Highlight DB models
|
||||
void ps_toggleHighlightDbModels();
|
||||
|
||||
//! Highlight stashed models
|
||||
void ps_toggleHighlightStashedModels();
|
||||
|
||||
@@ -79,17 +79,6 @@ namespace BlackGui
|
||||
private:
|
||||
bool m_allowStash = false; //!< allow to stash
|
||||
|
||||
//! Custom menu for the models which have been loaded
|
||||
class CHighlightDbModelsMenu : public BlackGui::IMenuDelegate
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CHighlightDbModelsMenu(CAircraftModelView *parent, bool separatorAtEnd) : IMenuDelegate(parent, separatorAtEnd) {}
|
||||
|
||||
//! \copydoc IMenuDelegate::customMenu
|
||||
virtual void customMenu(QMenu &menu) const override;
|
||||
};
|
||||
|
||||
//! Custom menu for the models which have been loaded
|
||||
class CHighlightStashedModelsMenu : public BlackGui::IMenuDelegate
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CAirlineIcaoCodeView::CAirlineIcaoCodeView(QWidget *parent) : CViewBase(parent)
|
||||
CAirlineIcaoCodeView::CAirlineIcaoCodeView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
{
|
||||
this->m_menus |= MenuBackend;
|
||||
this->standardInit(new CAirlineIcaoCodeListModel(this));
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define BLACKGUI_AIRLINEICAOVIEW_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "viewbase.h"
|
||||
#include "viewdbobjects.h"
|
||||
#include "../models/airlineicaolistmodel.h"
|
||||
|
||||
namespace BlackGui
|
||||
@@ -21,9 +21,9 @@ namespace BlackGui
|
||||
namespace Views
|
||||
{
|
||||
//! Aircraft ICAO codes view
|
||||
class BLACKGUI_EXPORT CAirlineIcaoCodeView : public CViewBase<Models::CAirlineIcaoCodeListModel, BlackMisc::Aviation::CAirlineIcaoCodeList, BlackMisc::Aviation::CAirlineIcaoCode>
|
||||
class BLACKGUI_EXPORT CAirlineIcaoCodeView :
|
||||
public CViewWithDbObjects<Models::CAirlineIcaoCodeListModel, BlackMisc::Aviation::CAirlineIcaoCodeList, BlackMisc::Aviation::CAirlineIcaoCode, int>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CAirlineIcaoCodeView(QWidget *parent = nullptr);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CDistributorView::CDistributorView(QWidget *parent) : CViewBase(parent)
|
||||
CDistributorView::CDistributorView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
{
|
||||
this->m_menus |= MenuBackend;
|
||||
this->standardInit(new CDistributorListModel(this));
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define BLACKGUI_DISTRIBUTORVIEW_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "viewbase.h"
|
||||
#include "viewdbobjects.h"
|
||||
#include "../models/distributorlistmodel.h"
|
||||
|
||||
namespace BlackGui
|
||||
@@ -21,13 +21,13 @@ namespace BlackGui
|
||||
namespace Views
|
||||
{
|
||||
//! Distributors
|
||||
class BLACKGUI_EXPORT CDistributorView : public CViewBase<Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor>
|
||||
class BLACKGUI_EXPORT CDistributorView :
|
||||
public CViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CDistributorView(QWidget *parent = nullptr);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CLiveryView::CLiveryView(QWidget *parent) : CViewBase(parent)
|
||||
CLiveryView::CLiveryView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
{
|
||||
this->m_menus |= MenuBackend;
|
||||
this->standardInit(new CLiveryListModel(this));
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef BLACKGUI_LIVERYVIEW_H
|
||||
#define BLACKGUI_LIVERYVIEW_H
|
||||
|
||||
#include "viewbase.h"
|
||||
#include "viewdbobjects.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/models/liverylistmodel.h"
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace BlackGui
|
||||
namespace Views
|
||||
{
|
||||
//! Distributors
|
||||
class BLACKGUI_EXPORT CLiveryView : public CViewBase<Models::CLiveryListModel, BlackMisc::Aviation::CLiveryList, BlackMisc::Aviation::CLivery>
|
||||
class BLACKGUI_EXPORT CLiveryView :
|
||||
public CViewWithDbObjects<Models::CLiveryListModel, BlackMisc::Aviation::CLiveryList, BlackMisc::Aviation::CLivery, int>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CLiveryView(QWidget *parent = nullptr);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace BlackGui
|
||||
clearSelection->setObjectName("Clear selection shortcut for " + this->objectName());
|
||||
QShortcut *saveJson = new QShortcut(CShortcut::keySaveViews(), this, SLOT(ps_saveJsonShortcut()), nullptr, Qt::WidgetShortcut);
|
||||
saveJson->setObjectName("Save JSON for " + this->objectName());
|
||||
QShortcut *deleteRow = new QShortcut(CShortcut::keyDelete(), this, SLOT(ps_removeSelectedRows()), nullptr, Qt::WidgetShortcut);
|
||||
deleteRow->setObjectName("Delete selected rows for " + this->objectName());
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget)
|
||||
@@ -166,6 +168,13 @@ namespace BlackGui
|
||||
if (this->m_menus.testFlag(MenuRefresh)) { menu.addAction(BlackMisc::CIcons::refresh16(), "Update", this, SIGNAL(requestUpdate())); }
|
||||
if (this->m_menus.testFlag(MenuBackend)) { menu.addAction(BlackMisc::CIcons::refresh16(), "Reload from backend", this, SIGNAL(requestNewBackendData())); }
|
||||
if (this->m_menus.testFlag(MenuClear)) { menu.addAction(BlackMisc::CIcons::delete16(), "Clear", this, SLOT(ps_clear())); }
|
||||
if (this->m_menus.testFlag(MenuRemoveSelectedRows))
|
||||
{
|
||||
if (this->hasSelection())
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::delete16(), "Remove selected rows", this, SLOT(ps_removeSelectedRows()), CShortcut::keyDelete());
|
||||
}
|
||||
}
|
||||
if (this->m_menus.testFlag(MenuDisplayAutomatically))
|
||||
{
|
||||
QAction *a = menu.addAction(CIcons::appMappings16(), "Automatically display (when loaded)", this, SLOT(ps_toggleAutoDisplay()));
|
||||
@@ -347,6 +356,10 @@ namespace BlackGui
|
||||
void CViewBaseNonTemplate::menuAddItems(Menu menusToAdd)
|
||||
{
|
||||
this->m_menus |= menusToAdd;
|
||||
if (menusToAdd.testFlag(MenuRemoveSelectedRows))
|
||||
{
|
||||
this->m_enableDeleteSelectedRows = true;
|
||||
}
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::ps_updateContainer(const CVariant &variant, bool sort, bool resize)
|
||||
@@ -488,6 +501,12 @@ namespace BlackGui
|
||||
this->m_displayAutomatically = a->isChecked();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_removeSelectedRows()
|
||||
{
|
||||
if (!m_enableDeleteSelectedRows) { return; }
|
||||
this->removeSelectedRows();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_updatedIndicator()
|
||||
{
|
||||
this->update();
|
||||
@@ -531,6 +550,14 @@ namespace BlackGui
|
||||
int CViewBase<ModelClass, ContainerType, ObjectType>::updateContainer(const ContainerType &container, bool sort, bool resize)
|
||||
{
|
||||
Q_ASSERT_X(this->m_model, Q_FUNC_INFO, "Missing model");
|
||||
if (container.isEmpty())
|
||||
{
|
||||
// shortcut
|
||||
this->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we have data
|
||||
this->showLoadIndicator(container.size());
|
||||
bool reallyResize = resize && isResizeConditionMet(container.size()); // do we really perform resizing
|
||||
bool presize = (m_resizeMode == ResizingOnceSubset) &&
|
||||
@@ -622,6 +649,13 @@ namespace BlackGui
|
||||
return this->m_model->container();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
const ContainerType &CViewBase<ModelClass, ContainerType, ObjectType>::containerOrFilteredContainer() const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->containerOrFilteredContainer();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
ContainerType CViewBase<ModelClass, ContainerType, ObjectType>::selectedObjects() const
|
||||
{
|
||||
|
||||
@@ -70,14 +70,17 @@ namespace BlackGui
|
||||
{
|
||||
MenuNone = 0, ///< no menu
|
||||
MenuClear = 1 << 0, ///< allow clearing the view via menu
|
||||
MenuRefresh = 1 << 1, ///< allow refreshing the view via menu
|
||||
MenuBackend = 1 << 2, ///< allow to request data from backend
|
||||
MenuDisplayAutomatically = 1 << 3, ///< allow to switch display automatically
|
||||
MenuFilter = 1 << 4, ///< filter can be opened
|
||||
MenuSave = 1 << 5, ///< save as JSON
|
||||
MenuLoad = 1 << 6, ///< load from JSON
|
||||
MenuRemoveSelectedRows = 1 << 1, ///< allow to remove selected rows
|
||||
MenuRefresh = 1 << 2, ///< allow refreshing the view via menu
|
||||
MenuBackend = 1 << 3, ///< allow to request data from backend
|
||||
MenuDisplayAutomatically = 1 << 4, ///< allow to switch display automatically
|
||||
MenuFilter = 1 << 5, ///< filter can be opened
|
||||
MenuSave = 1 << 6, ///< save as JSON
|
||||
MenuLoad = 1 << 7, ///< load from JSON
|
||||
MenuLoadAndSave = MenuLoad | MenuSave,
|
||||
MenuDefault = MenuClear | MenuDisplayAutomatically
|
||||
MenuDefault = MenuClear | MenuDisplayAutomatically,
|
||||
// special menu, should be in derived class but enums cannot be derived
|
||||
MenuHighlightDbData = 1 << 8, ///< highlight DB data
|
||||
};
|
||||
Q_DECLARE_FLAGS(Menu, MenuFlag)
|
||||
|
||||
@@ -224,6 +227,9 @@ namespace BlackGui
|
||||
//! Hide loading indicator
|
||||
void hideLoadIndicator();
|
||||
|
||||
//! Remove selected rows
|
||||
virtual int removeSelectedRows() = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CViewBaseNonTemplate(QWidget *parent);
|
||||
@@ -286,6 +292,7 @@ namespace BlackGui
|
||||
bool m_acceptRowSelected = false; //!< selection changed
|
||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
@@ -341,6 +348,9 @@ namespace BlackGui
|
||||
//! Clear the model
|
||||
virtual void ps_clear() { this->clear(); }
|
||||
|
||||
//! Remove selected rows
|
||||
void ps_removeSelectedRows();
|
||||
|
||||
private:
|
||||
//! Set the filter widget internally
|
||||
void setFilterWidgetImpl(QWidget *filterWidget);
|
||||
@@ -350,6 +360,9 @@ namespace BlackGui
|
||||
//! Base class for views
|
||||
template <class ModelClass, class ContainerType, class ObjectType> class CViewBase : public CViewBaseNonTemplate
|
||||
{
|
||||
// I cannot use Q_OBJECT here, because error: Template classes not supported by Q_OBJECT
|
||||
// Cannot declare slots as SLOT because I have no Q_OBJECT macro
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~CViewBase() { if (this->m_model) { this->m_model->markDestroyed(); }}
|
||||
@@ -364,6 +377,7 @@ namespace BlackGui
|
||||
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||
|
||||
//! Update whole container
|
||||
//! \return int size after update
|
||||
int updateContainer(const ContainerType &container, bool sort = true, bool resize = true);
|
||||
|
||||
//! Update whole container in background
|
||||
@@ -381,18 +395,22 @@ namespace BlackGui
|
||||
//! Access to container
|
||||
const ContainerType &container() const;
|
||||
|
||||
//! \copydoc BlackGui::Models::ListModelBase::containerOrFilteredContainer
|
||||
const ContainerType &containerOrFilteredContainer() const;
|
||||
|
||||
//! Selected objects
|
||||
ContainerType selectedObjects() const;
|
||||
|
||||
//! \copydoc CViewBaseNonTemplate::removeSelectedRows
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual int removeSelectedRows() override;
|
||||
|
||||
//! Update selected objects
|
||||
int updateSelected(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Selected object (or default)
|
||||
ObjectType selectedObject() const;
|
||||
|
||||
//! Remove selected rows
|
||||
int removeSelectedRows();
|
||||
|
||||
//! \copydoc BlackMisc::CContainerBase::removeIf
|
||||
template <class K0, class V0, class... KeysValues>
|
||||
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
|
||||
|
||||
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
|
||||
53
src/blackgui/views/viewdbobjects.h
Normal file
53
src/blackgui/views/viewdbobjects.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_VIEWDBOBJECTS_H
|
||||
#define BLACKGUI_VIEWDBOBJECTS_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "viewbase.h"
|
||||
#include <QMenu>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
//! Base class for views with DB objects
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType> class CViewWithDbObjects :
|
||||
public CViewBase<ModelClass, ContainerType, ObjectType>
|
||||
{
|
||||
public:
|
||||
//! Get latest object
|
||||
ObjectType latestObject() const;
|
||||
|
||||
//! Get oldets object
|
||||
ObjectType oldestObject() const;
|
||||
|
||||
//! Select given DB keys
|
||||
void selectDbKeys(const QList<KeyType> &keys);
|
||||
|
||||
//! Remove keys
|
||||
int removeDbKeys(const QList<KeyType> &keys);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
explicit CViewWithDbObjects(QWidget *parent = nullptr);
|
||||
|
||||
//! \copydoc QWidget::customMenu
|
||||
virtual void customMenu(QMenu &menu) const override;
|
||||
|
||||
private slots:
|
||||
//! Highlight DB data
|
||||
void ps_toggleDbData();
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user