mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
refs #641, support for IOrderable in specialized views/models
* menu to order objects per drag and drop * changed model/views to specialized model/views
This commit is contained in:
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CAircraftModelView::CAircraftModelView(QWidget *parent) : CViewWithDbObjects(parent)
|
||||
CAircraftModelView::CAircraftModelView(QWidget *parent) : COrderableViewWithDbObjects(parent)
|
||||
{
|
||||
// default
|
||||
this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::OwnSimulatorModel, this));
|
||||
@@ -105,9 +105,10 @@ namespace BlackGui
|
||||
return m_menus.testFlag(MenuCanStashModels) && hasSelection();
|
||||
}
|
||||
|
||||
void CAircraftModelView::setImplementedMetaTypeIds()
|
||||
void CAircraftModelView::setAcceptedMetaTypeIds()
|
||||
{
|
||||
this->setAcceptedMetaTypeIds(
|
||||
Q_ASSERT(this->m_model);
|
||||
this->m_model->setAcceptedMetaTypeIds(
|
||||
{
|
||||
qMetaTypeId<CAirlineIcaoCode>(), qMetaTypeId<CAirlineIcaoCodeList>(),
|
||||
qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>(),
|
||||
@@ -176,7 +177,8 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!isDropAllowed()) { return; }
|
||||
|
||||
if (!this->isDropAllowed()) { return; }
|
||||
if (!event) { return; }
|
||||
const QMimeData *mime = event->mimeData();
|
||||
if (!mime) { return; }
|
||||
@@ -290,7 +292,7 @@ namespace BlackGui
|
||||
menu.addMenu(stashMenu);
|
||||
stashMenu->setIcon(CIcons::appDbStash16());
|
||||
}
|
||||
CViewWithDbObjects::customMenu(menu);
|
||||
COrderableViewWithDbObjects::customMenu(menu);
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelView::modifyLoadedJsonData(CAircraftModelList &models) const
|
||||
@@ -338,7 +340,7 @@ namespace BlackGui
|
||||
if (sim.isSingleSimulator()) { return ok; }
|
||||
return CStatusMessage(this, CStatusMessage::SeverityError, "data need to be from one simulator");
|
||||
}
|
||||
return CViewWithDbObjects::validateLoadedJsonData(models);
|
||||
return COrderableViewWithDbObjects::validateLoadedJsonData(models);
|
||||
}
|
||||
|
||||
void CAircraftModelView::jsonLoadedAndModelUpdated(const CAircraftModelList &models)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Aircraft view
|
||||
class BLACKGUI_EXPORT CAircraftModelView :
|
||||
public CViewWithDbObjects<Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>
|
||||
public COrderableViewWithDbObjects<Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace BlackGui
|
||||
bool hasSelectedModelsToStash() const;
|
||||
|
||||
//! Add the technically supported metatypes allowed for drag and drop
|
||||
void setImplementedMetaTypeIds();
|
||||
void setAcceptedMetaTypeIds();
|
||||
|
||||
//! Add my own filter dialog
|
||||
void addFilterDialog();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace BlackGui
|
||||
namespace Views
|
||||
{
|
||||
CDistributorView::CDistributorView(QWidget *parent) :
|
||||
CViewWithDbObjects(parent)
|
||||
COrderableViewWithDbObjects(parent)
|
||||
{
|
||||
this->standardInit(new CDistributorListModel(this));
|
||||
this->setMenu(MenuDefaultDbViews);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BlackGui
|
||||
{
|
||||
//! Distributors
|
||||
class BLACKGUI_EXPORT CDistributorView :
|
||||
public CViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>
|
||||
public COrderableViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
|
||||
@@ -94,7 +94,6 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CViewBaseNonTemplate::setFilterDialog(CFilterDialog *filterDialog)
|
||||
{
|
||||
this->setFilterWidgetImpl(filterDialog);
|
||||
@@ -303,25 +302,6 @@ namespace BlackGui
|
||||
QTableView::showEvent(event);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::allowDragDropValueObjects(bool allowDrag, bool allowDrop)
|
||||
{
|
||||
// see model for implementing logic of drag
|
||||
this->setAcceptDrops(allowDrop);
|
||||
this->setDragEnabled(allowDrag);
|
||||
this->setDropIndicatorShown(allowDrop);
|
||||
CDropBase::allowDrop(allowDrop);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::allowDrop(bool allow)
|
||||
{
|
||||
this->allowDragDropValueObjects(this->dragEnabled(), allow);
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::isDropAllowed() const
|
||||
{
|
||||
return this->acceptDrops();
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::getHorizontalHeaderFontHeight() const
|
||||
{
|
||||
QFontMetrics m(this->getHorizontalHeaderFont());
|
||||
@@ -518,10 +498,10 @@ namespace BlackGui
|
||||
this->setVisible(false);
|
||||
// magic trick from:
|
||||
// http://stackoverflow.com/q/3433664/356726
|
||||
const QRect vporig = this->viewport()->geometry();
|
||||
QRect vpnew = vporig;
|
||||
vpnew.setWidth(std::numeric_limits<int>::max());
|
||||
this->viewport()->setGeometry(vpnew);
|
||||
const QRect vpOriginal = this->viewport()->geometry();
|
||||
QRect vpNew = vpOriginal;
|
||||
vpNew.setWidth(std::numeric_limits<int>::max());
|
||||
this->viewport()->setGeometry(vpNew);
|
||||
|
||||
this->m_resizeCount++;
|
||||
this->resizeColumnsToContents(); // columns
|
||||
@@ -531,16 +511,10 @@ namespace BlackGui
|
||||
// re-stretch
|
||||
this->horizontalHeader()->setStretchLastSection(true);
|
||||
}
|
||||
|
||||
this->viewport()->setGeometry(vporig);
|
||||
this->viewport()->setGeometry(vpOriginal);
|
||||
this->setVisible(true);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::presizeOrFullResizeToContents()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_customMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu;
|
||||
@@ -601,14 +575,14 @@ namespace BlackGui
|
||||
|
||||
void CViewBaseNonTemplate::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
if (!event || !this->acceptDrop(event->mimeData())) { return; }
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
if (!event || !this->acceptDrop(event->mimeData())) { return; }
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
@@ -618,11 +592,6 @@ namespace BlackGui
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::dropEvent(QDropEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CViewBase<ModelClass, ContainerType, ObjectType>::CViewBase(QWidget *parent, ModelClass *model) : CViewBaseNonTemplate(parent), m_model(model)
|
||||
{
|
||||
@@ -646,7 +615,7 @@ namespace BlackGui
|
||||
|
||||
// we have data
|
||||
this->showLoadIndicator(container.size());
|
||||
bool reallyResize = resize && isResizeConditionMet(container.size()); // do we really perform resizing
|
||||
const bool reallyResize = resize && isResizeConditionMet(container.size()); // do we really perform resizing
|
||||
bool presize = (m_resizeMode == PresizeSubset) &&
|
||||
this->isEmpty() && // only when no data yet
|
||||
!reallyResize; // not when we resize later
|
||||
@@ -894,6 +863,47 @@ namespace BlackGui
|
||||
return this->m_model->rowCount() < 1;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
bool CViewBase<ModelClass, ContainerType, ObjectType>::isOrderable() const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->isOrderable();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::allowDragDrop(bool allowDrag, bool allowDrop)
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
|
||||
// see model for implementing logic of drag
|
||||
this->viewport()->setAcceptDrops(allowDrop);
|
||||
this->setDragEnabled(allowDrag);
|
||||
this->setDropIndicatorShown(allowDrop);
|
||||
this->m_model->allowDrop(allowDrop);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
bool CViewBase<ModelClass, ContainerType, ObjectType>::isDropAllowed() const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->isDropAllowed();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
bool CViewBase<ModelClass, ContainerType, ObjectType>::acceptDrop(const QMimeData *mimeData) const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
const bool a = this->m_model->acceptDrop(mimeData);
|
||||
return a;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
this->m_model->setSorting(propertyIndex, order);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
QJsonObject CViewBase<ModelClass, ContainerType, ObjectType>::toJson() const
|
||||
{
|
||||
@@ -936,6 +946,23 @@ namespace BlackGui
|
||||
return derivedModel()->hasFilter();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::addContainerTypesAsDropTypes(bool objectType, bool containerType)
|
||||
{
|
||||
if (objectType) { this->m_model->addAcceptedMetaTypeId(qMetaTypeId<ObjectType>()); }
|
||||
if (containerType) { this->m_model->addAcceptedMetaTypeId(qMetaTypeId<ContainerType>()); }
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::initAsOrderable()
|
||||
{
|
||||
Q_ASSERT_X(isOrderable(), Q_FUNC_INFO, "Model not orderable");
|
||||
this->allowDragDrop(true, true);
|
||||
this->setDragDropMode(InternalMove);
|
||||
this->setDropActions(Qt::MoveAction);
|
||||
this->addContainerTypesAsDropTypes(true, true);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::setSortIndicator()
|
||||
{
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackgui/menus/menudelegate.h"
|
||||
#include "blackgui/loadindicator.h"
|
||||
#include "blackgui/dropbase.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/worker.h"
|
||||
@@ -39,8 +38,7 @@ namespace BlackGui
|
||||
//! Non templated base class, allows Q_OBJECT and signals / slots to be used
|
||||
class BLACKGUI_EXPORT CViewBaseNonTemplate :
|
||||
public QTableView,
|
||||
public BlackGui::Components::CEnableForDockWidgetInfoArea,
|
||||
public BlackGui::CDropBase
|
||||
public BlackGui::Components::CEnableForDockWidgetInfoArea
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -79,6 +77,7 @@ namespace BlackGui
|
||||
MenuSave = 1 << 6, //!< save as JSON
|
||||
MenuLoad = 1 << 7, //!< load from JSON
|
||||
MenuToggleSelectionMode = 1 << 8, //!< allow to toggle selection mode
|
||||
MenuOrderable = 1 << 9, //!< items can be ordered (if container is BlackMisc::IOrderableList
|
||||
MenuStandard = MenuClear | MenuRemoveSelectedRows | MenuRefresh | MenuBackend |
|
||||
MenuDisplayAutomatically | MenuFilter | MenuSave | MenuLoad | MenuToggleSelectionMode,
|
||||
MenuLoadAndSave = MenuLoad | MenuSave,
|
||||
@@ -87,9 +86,9 @@ namespace BlackGui
|
||||
MenuDefaultDbViews = MenuToggleSelectionMode | MenuBackend,
|
||||
// special menus, should be in derived classes, but enums cannot be inherited
|
||||
// maybe shifted in the future to elsewhere
|
||||
MenuHighlightDbData = 1 << 9, //!< highlight DB data
|
||||
MenuHighlightStashed = 1 << 10, //!< highlight stashed models
|
||||
MenuCanStashModels = 1 << 11, //!< stash models
|
||||
MenuHighlightDbData = 1 << 10, //!< highlight DB data
|
||||
MenuHighlightStashed = 1 << 11, //!< highlight stashed models
|
||||
MenuCanStashModels = 1 << 12, //!< stash models
|
||||
MenuStashing = MenuHighlightStashed | MenuCanStashModels,
|
||||
};
|
||||
Q_DECLARE_FLAGS(Menu, MenuFlag)
|
||||
@@ -106,21 +105,27 @@ namespace BlackGui
|
||||
//! Empty?
|
||||
virtual bool isEmpty() const = 0 ;
|
||||
|
||||
//! Elements in container
|
||||
virtual int rowCount() const = 0;
|
||||
|
||||
//! Is the corresponding model orderable, BlackMisc::Models::CListModelBaseNonTemplate::isOrderable
|
||||
virtual bool isOrderable() const = 0;
|
||||
|
||||
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::setSorting
|
||||
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
|
||||
|
||||
//! Allow to drag and/or drop value objects
|
||||
virtual void allowDragDropValueObjects(bool allowDrag, bool allowDrop);
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop) = 0;
|
||||
|
||||
//! \copydoc CDropBase::allowDrop
|
||||
virtual void allowDrop(bool allow) override;
|
||||
//! Drop allowed?
|
||||
virtual bool isDropAllowed() const = 0;
|
||||
|
||||
//! \copydoc CDropBase::isDropAllowed
|
||||
virtual bool isDropAllowed() const override;
|
||||
//! Accept drop data?
|
||||
virtual bool acceptDrop(const QMimeData *mimeData) const = 0;
|
||||
|
||||
//! \copydoc Components::CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea
|
||||
virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override;
|
||||
|
||||
//! Elements in container
|
||||
virtual int rowCount() const = 0;
|
||||
|
||||
//! Resize mode
|
||||
ResizeMode getResizeMode() const { return m_resizeMode; }
|
||||
|
||||
@@ -278,23 +283,14 @@ namespace BlackGui
|
||||
//! \sa BlackGui::Views::CViewBaseNonTemplate::ps_customMenuRequested
|
||||
virtual void customMenu(QMenu &menu) const;
|
||||
|
||||
//! \copydoc QTableView::paintEvent
|
||||
//! \name Functions from QTableView
|
||||
//! @{
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::showEvent
|
||||
virtual void showEvent(QShowEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragEnterEvent
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragMoveEvent
|
||||
virtual void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dragLeaveEvent
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
|
||||
//! \copydoc QTableView::dropEvent
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
//! @}
|
||||
|
||||
//! Perform resizing / non slot method for template
|
||||
virtual void performModeBasedResizeToContent() = 0;
|
||||
@@ -341,7 +337,7 @@ namespace BlackGui
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget or dialog
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::Menus::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if needed
|
||||
|
||||
protected slots:
|
||||
//! Helper method with template free signature serving as callback from threaded worker
|
||||
@@ -428,9 +424,6 @@ namespace BlackGui
|
||||
//! Model
|
||||
const ModelClass *derivedModel() const { return this->m_model; }
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::clear
|
||||
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);
|
||||
@@ -459,12 +452,6 @@ namespace BlackGui
|
||||
//! Selected objects
|
||||
ContainerType selectedObjects() const;
|
||||
|
||||
//! \name Slot overrides from base class
|
||||
//! @{
|
||||
virtual int removeSelectedRows() override;
|
||||
virtual void presizeOrFullResizeToContents() override;
|
||||
//! @}
|
||||
|
||||
//! Update selected objects
|
||||
int updateSelected(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
@@ -495,15 +482,27 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(copy);
|
||||
}
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::rowCount
|
||||
//! \name Slot overrides from base class
|
||||
//! @{
|
||||
virtual int removeSelectedRows() override;
|
||||
virtual void presizeOrFullResizeToContents() override;
|
||||
//! @}
|
||||
|
||||
//! \name BlackGui::Views::CViewBaseNonTemplate implementations
|
||||
//! @{
|
||||
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||
virtual int rowCount() const override;
|
||||
virtual bool isEmpty() const override;
|
||||
virtual bool isOrderable() const override;
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop) override;
|
||||
virtual bool isDropAllowed() const override;
|
||||
virtual bool acceptDrop(const QMimeData *mimeData) const override;
|
||||
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
//! @}
|
||||
|
||||
//! Column count
|
||||
int columnCount() const;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::isEmpty
|
||||
virtual bool isEmpty() const override;
|
||||
|
||||
//! Convert to JSON
|
||||
QJsonObject toJson() const;
|
||||
|
||||
@@ -522,6 +521,15 @@ namespace BlackGui
|
||||
//! Has filter set?
|
||||
bool hasFilter() const;
|
||||
|
||||
//! Add the object and container type as accepted drop types CDropBase::addAcceptedMetaTypeId
|
||||
void addContainerTypesAsDropTypes(bool objectType = true, bool containerType = true);
|
||||
|
||||
//! Init so items can be ordered
|
||||
void initAsOrderable();
|
||||
|
||||
//! Drop actions
|
||||
void setDropActions(Qt::DropActions dropActions) { Q_ASSERT(this->m_model); this->m_model->setDropActions(dropActions); }
|
||||
|
||||
protected:
|
||||
ModelClass *m_model = nullptr; //!< corresponding model
|
||||
|
||||
@@ -534,14 +542,12 @@ namespace BlackGui
|
||||
//! Standard initialization
|
||||
void standardInit(ModelClass *model = nullptr);
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::reachedResizeThreshold
|
||||
//! \name base class implementations
|
||||
//! @{
|
||||
virtual bool reachedResizeThreshold(int containrerSize = -1) const override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::performModeBasedResizeToContent
|
||||
virtual void performModeBasedResizeToContent() override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::performUpdateContainer
|
||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) override;
|
||||
//! @}
|
||||
|
||||
//! Modify JSON data loaded in BlackGui::Views::CViewBaseNonTemplate::ps_loadJson
|
||||
virtual BlackMisc::CStatusMessage modifyLoadedJsonData(ContainerType &data) const;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include "viewdbobjects.h"
|
||||
#include "blackgui/models/allmodels.h"
|
||||
#include <QAction>
|
||||
#include <QWidgetAction>
|
||||
#include <QLineEdit>
|
||||
#include <QIntValidator>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui;
|
||||
@@ -84,7 +87,7 @@ namespace BlackGui
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(QMenu &menu) const
|
||||
{
|
||||
if (this->m_menus.testFlag(CViewBase<ModelClass, ContainerType, ObjectType>::MenuHighlightDbData))
|
||||
if (this->m_menus.testFlag(CViewBaseNonTemplate::MenuHighlightDbData))
|
||||
{
|
||||
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB data", this, &CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleHighlightDbData);
|
||||
a->setCheckable(true);
|
||||
@@ -100,14 +103,91 @@ namespace BlackGui
|
||||
this->derivedModel()->setHighlightDbData(!h);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::COrderableViewWithDbObjects(QWidget *parent) :
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::CViewWithDbObjects(parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(QMenu &menu) const
|
||||
{
|
||||
if (this->m_menus.testFlag(CViewBaseNonTemplate::MenuOrderable) && this->hasSelection())
|
||||
{
|
||||
const int maxOrder = this->rowCount() - 1;
|
||||
QMenu *menuOrder = menu.addMenu(CIcons::arrowMediumEast16(), "Order");
|
||||
|
||||
QLineEdit *leOrder = new QLineEdit(&menu);
|
||||
leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
||||
const QIntValidator *v = new QIntValidator(0, maxOrder, leOrder);
|
||||
leOrder->setValidator(v);
|
||||
QWidgetAction *orderAction = new QWidgetAction(&menu);
|
||||
orderAction->setDefaultWidget(leOrder);
|
||||
menuOrder->addAction(orderAction);
|
||||
QObject::connect(leOrder, &QLineEdit::returnPressed, this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToLineEdit);
|
||||
|
||||
menuOrder->addAction(CIcons::arrowMediumNorth16(), "To top", this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToTop);
|
||||
menuOrder->addAction(CIcons::arrowMediumSouth16(), "To bottom", this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToBottom);
|
||||
menuOrder->addAction(CIcons::arrowMediumWest16(), "Freeze current order", this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_freezeCurrentOrder);
|
||||
menu.addSeparator();
|
||||
}
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(menu);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::moveSelectedItems(int order)
|
||||
{
|
||||
if (this->isEmpty()) { return; }
|
||||
const ContainerType objs(this->selectedObjects());
|
||||
if (objs.isEmpty()) { return; }
|
||||
this->m_model->moveItems(objs, order);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToTop()
|
||||
{
|
||||
this->moveSelectedItems(0);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToBottom()
|
||||
{
|
||||
int c = this->model()->rowCount() - 1;
|
||||
if (c >= 0)
|
||||
{
|
||||
this->moveSelectedItems(c);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToLineEdit()
|
||||
{
|
||||
if (this->isEmpty()) { return; }
|
||||
QLineEdit *le = qobject_cast<QLineEdit *>(QObject::sender());
|
||||
if (!le || le->text().isEmpty()) { return; }
|
||||
const int order = le->text().toInt();
|
||||
this->moveSelectedItems(order);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_freezeCurrentOrder()
|
||||
{
|
||||
ContainerType objects = this->container();
|
||||
objects.freezeOrder();
|
||||
this->updateContainerAsync(objects, false);
|
||||
}
|
||||
|
||||
// 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>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>;
|
||||
template class CViewWithDbObjects<BlackGui::Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>;
|
||||
template class COrderableViewWithDbObjects<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor, QString>;
|
||||
template class COrderableViewWithDbObjects<BlackGui::Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel, int>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -51,6 +51,37 @@ namespace BlackGui
|
||||
//! \copydoc BlackGui::Views::CViewBase::ps_toggleHighlightDbData
|
||||
virtual void ps_toggleHighlightDbData() override;
|
||||
};
|
||||
|
||||
//! Base class for views with DB objects
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType> class COrderableViewWithDbObjects :
|
||||
public CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>
|
||||
{
|
||||
protected:
|
||||
//! Constructor
|
||||
explicit COrderableViewWithDbObjects(QWidget *parent = nullptr);
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
||||
virtual void customMenu(QMenu &menu) const override;
|
||||
|
||||
//! Move selected items
|
||||
void moveSelectedItems(int order);
|
||||
|
||||
protected slots:
|
||||
//! Order to top
|
||||
void ps_orderToTop();
|
||||
|
||||
//! Order to bottom
|
||||
void ps_orderToBottom();
|
||||
|
||||
//! Order to line edit
|
||||
void ps_orderToLineEdit();
|
||||
|
||||
//! Current order set as order
|
||||
void ps_freezeCurrentOrder();
|
||||
|
||||
private:
|
||||
QList<QAction *> m_menuActions;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user