mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #568, improved validation and handling
* invalid models can be highlighted on stash * selection mode can be toggled between single/multi selection (where applicable) * color for highlighting can be set * finetuning of menus
This commit is contained in:
@@ -56,10 +56,10 @@ namespace BlackGui
|
||||
this->m_menus = MenuBackend;
|
||||
break;
|
||||
case CAircraftModelListModel::VPilotRuleModel:
|
||||
this->m_menus = MenuRefresh | MenuStashing | MenuHighlightDbData;
|
||||
this->m_menus = MenuRefresh | MenuStashing | MenuToggleSelectionMode;
|
||||
break;
|
||||
case CAircraftModelListModel::OwnSimulatorModelMapping:
|
||||
this->m_menus = MenuDisplayAutomatically | MenuStashing | MenuHighlightDbData;
|
||||
this->m_menus = MenuDisplayAutomatically | MenuStashing | MenuHighlightDbData | MenuToggleSelectionMode;
|
||||
break;
|
||||
case CAircraftModelListModel::OwnSimulatorModel:
|
||||
default:
|
||||
@@ -91,7 +91,7 @@ namespace BlackGui
|
||||
|
||||
bool CAircraftModelView::hasSelectedModelsToStash() const
|
||||
{
|
||||
return m_menus.testFlag(MenuStashModels) && hasSelection();
|
||||
return m_menus.testFlag(MenuCanStashModels) && hasSelection();
|
||||
}
|
||||
|
||||
void CAircraftModelView::setImplementedMetaTypeIds()
|
||||
@@ -123,6 +123,26 @@ namespace BlackGui
|
||||
return delta;
|
||||
}
|
||||
|
||||
void CAircraftModelView::setHighlightModelStrings(const QStringList &highlightModels)
|
||||
{
|
||||
this->derivedModel()->setHighlightModelStrings(highlightModels);
|
||||
}
|
||||
|
||||
void CAircraftModelView::setHighlightModelStrings(bool highlight)
|
||||
{
|
||||
this->derivedModel()->setHighlightModelStrings(highlight);
|
||||
}
|
||||
|
||||
void CAircraftModelView::setHighlightModelStringsColor(const QBrush &brush)
|
||||
{
|
||||
this->derivedModel()->setHighlightModelStringsColor(brush);
|
||||
}
|
||||
|
||||
bool CAircraftModelView::highlightModelsStrings() const
|
||||
{
|
||||
return this->derivedModel()->highlightModelStrings();
|
||||
}
|
||||
|
||||
void CAircraftModelView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!isDropAllowed()) { return; }
|
||||
@@ -215,34 +235,43 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelView::customMenu(QMenu &menu) const
|
||||
{
|
||||
bool added = false;
|
||||
if (this->m_menus.testFlag(MenuStashModels))
|
||||
if (this->m_menus.testFlag(MenuCanStashModels))
|
||||
{
|
||||
menu.addAction(CIcons::appDbStash16(), "Stash", this, SLOT(ps_requestStash()));
|
||||
QAction *a = menu.addAction(CIcons::appDbStash16(), "Stashing clears selection", this, SLOT(ps_stashingClearsSelection()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(m_stashingClearsSelection);
|
||||
added = true;
|
||||
}
|
||||
if (this->m_menus.testFlag(MenuHighlightStashed))
|
||||
{
|
||||
// this function requires someone provides the model strings to be highlighted
|
||||
// this function requires that someone provides the model strings to be highlighted
|
||||
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight stashed", this, SLOT(ps_toggleHighlightStashedModels()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(this->derivedModel()->highlightDbData());
|
||||
added = true;
|
||||
}
|
||||
if (added) { menu.addSeparator(); }
|
||||
if (this->m_menus.testFlag(MenuHighlightInvalid))
|
||||
{
|
||||
// this function requires that someone provides the model strings to be highlighted
|
||||
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight invalid models", this, SLOT(ps_to));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(this->derivedModel()->highlightDbData());
|
||||
}
|
||||
CViewWithDbObjects::customMenu(menu);
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightStashedModels()
|
||||
{
|
||||
bool h = derivedModel()->highlightGivenModelStrings();
|
||||
derivedModel()->setHighlightModelsStrings(!h);
|
||||
bool h = derivedModel()->highlightModelStrings();
|
||||
derivedModel()->setHighlightModelStrings(!h);
|
||||
emit toggledHighlightStashedModels();
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toogleHighlightInvalidModels()
|
||||
{
|
||||
bool h = this->highlightModelsStrings();
|
||||
this->setHighlightModelStrings(!h);
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_stashingClearsSelection()
|
||||
{
|
||||
this->m_stashingClearsSelection = !this->m_stashingClearsSelection;
|
||||
@@ -250,7 +279,7 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelView::ps_requestStash()
|
||||
{
|
||||
if (!m_menus.testFlag(MenuStashModels)) { return; }
|
||||
if (!m_menus.testFlag(MenuCanStashModels)) { return; }
|
||||
if (!this->hasSelection()) { return; }
|
||||
emit requestStash(this->selectedObjects());
|
||||
if (this->m_stashingClearsSelection)
|
||||
|
||||
@@ -55,6 +55,18 @@ namespace BlackGui
|
||||
//! Remove models with model strings
|
||||
int removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
|
||||
|
||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::setHighlightModelStrings(const QStringList &)
|
||||
void setHighlightModelStrings(const QStringList &highlightModels);
|
||||
|
||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::setHighlightModelsStrings(bool)
|
||||
void setHighlightModelStrings(bool highlight);
|
||||
|
||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::setHighlightModelStringsColor
|
||||
void setHighlightModelStringsColor(const QBrush &brush);
|
||||
|
||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::highlightModelsStrings
|
||||
bool highlightModelsStrings() const;
|
||||
|
||||
signals:
|
||||
//! Request to stash if applicable
|
||||
void requestStash(const BlackMisc::Simulation::CAircraftModelList &models);
|
||||
@@ -76,6 +88,9 @@ namespace BlackGui
|
||||
//! Highlight stashed models
|
||||
void ps_toggleHighlightStashedModels();
|
||||
|
||||
//! Toggle highlight invalid models
|
||||
void ps_toogleHighlightInvalidModels();
|
||||
|
||||
//! Toggle if stashing unselects
|
||||
void ps_stashingClearsSelection();
|
||||
|
||||
|
||||
@@ -163,6 +163,9 @@ namespace BlackGui
|
||||
// delegate?
|
||||
if (this->m_menu) { this->m_menu->customMenu(menu); }
|
||||
|
||||
// separator
|
||||
if (!menu.isEmpty() && ((this->m_menus & MenuStandard) > 0)) { menu.addSeparator(); }
|
||||
|
||||
// standard menus
|
||||
int items = menu.actions().size();
|
||||
if (this->m_menus.testFlag(MenuRefresh)) { menu.addAction(BlackMisc::CIcons::refresh16(), "Update", this, SIGNAL(requestUpdate())); }
|
||||
@@ -192,13 +195,28 @@ namespace BlackGui
|
||||
if (menu.actions().size() > items) { menu.addSeparator(); }
|
||||
|
||||
// selection menus
|
||||
items = menu.actions().size();
|
||||
SelectionMode sm = this->selectionMode();
|
||||
if (sm == MultiSelection || sm == ExtendedSelection)
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::empty16(), "Select all", this, SLOT(selectAll()), Qt::CTRL + Qt::Key_A);
|
||||
menu.addAction(QIcon(), "Select all", this, SLOT(selectAll()), Qt::CTRL + Qt::Key_A);
|
||||
}
|
||||
menu.addAction(BlackMisc::CIcons::empty16(), "Clear selection", this, SLOT(clearSelection()), CShortcut::keyClearSelection());
|
||||
menu.addSeparator();
|
||||
if ((this->m_originalSelectionMode == MultiSelection || this->m_originalSelectionMode == ExtendedSelection) && this->m_menus.testFlag(MenuToggleSelectionMode))
|
||||
{
|
||||
if (sm == SingleSelection)
|
||||
{
|
||||
menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
|
||||
}
|
||||
else if (sm == MultiSelection || sm == ExtendedSelection)
|
||||
{
|
||||
menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode()));
|
||||
}
|
||||
}
|
||||
if (sm != NoSelection)
|
||||
{
|
||||
menu.addAction(QIcon(), "Clear selection", this, SLOT(clearSelection()), CShortcut::keyClearSelection());
|
||||
}
|
||||
if (menu.actions().size() > items) { menu.addSeparator(); }
|
||||
|
||||
// load/save
|
||||
items = menu.actions().size();
|
||||
@@ -507,6 +525,21 @@ namespace BlackGui
|
||||
this->m_displayAutomatically = a->isChecked();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_toggleSelectionMode()
|
||||
{
|
||||
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||
{
|
||||
if (this->selectionMode() == SingleSelection)
|
||||
{
|
||||
this->setSelectionMode(this->m_originalSelectionMode);
|
||||
}
|
||||
else if (this->selectionMode() == MultiSelection)
|
||||
{
|
||||
this->setSelectionMode(SingleSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_removeSelectedRows()
|
||||
{
|
||||
if (!m_enableDeleteSelectedRows) { return; }
|
||||
|
||||
@@ -77,14 +77,18 @@ namespace BlackGui
|
||||
MenuFilter = 1 << 5, ///< filter can be opened
|
||||
MenuSave = 1 << 6, ///< save as JSON
|
||||
MenuLoad = 1 << 7, ///< load from JSON
|
||||
MenuToggleSelectionMode = 1 << 8, ///< allow to toggle selection mode
|
||||
MenuStandard = MenuClear | MenuRemoveSelectedRows | MenuRefresh | MenuBackend |
|
||||
MenuDisplayAutomatically | MenuFilter | MenuSave | MenuLoad | MenuToggleSelectionMode,
|
||||
MenuLoadAndSave = MenuLoad | MenuSave,
|
||||
MenuDefault = MenuClear | MenuDisplayAutomatically,
|
||||
MenuDefault = MenuClear | MenuDisplayAutomatically | MenuToggleSelectionMode,
|
||||
// special menus, should be in derived classes, but enums cannot be inherited
|
||||
// maybe shifted in the future to elsewhere
|
||||
MenuHighlightDbData = 1 << 8, ///< highlight DB data
|
||||
MenuHighlightStashed = 1 << 9, ///< highlight stashed models
|
||||
MenuStashModels = 1 << 10, ///< stash models
|
||||
MenuStashing = MenuHighlightStashed | MenuStashModels,
|
||||
MenuHighlightDbData = 1 << 9, ///< highlight DB data
|
||||
MenuHighlightStashed = 1 << 10, ///< highlight stashed models
|
||||
MenuCanStashModels = 1 << 11, ///< stash models
|
||||
MenuStashing = MenuHighlightStashed | MenuCanStashModels,
|
||||
MenuHighlightInvalid = 1 << 12 ///< highlight invalid models
|
||||
};
|
||||
Q_DECLARE_FLAGS(Menu, MenuFlag)
|
||||
|
||||
@@ -284,8 +288,9 @@ namespace BlackGui
|
||||
//! Default file for load/save operations
|
||||
QString getDefaultFilename() const;
|
||||
|
||||
ResizeMode m_resizeMode = ResizingOnceSubset; //!< mode
|
||||
ResizeMode m_resizeMode = ResizingOnceSubset; //!< mode
|
||||
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
||||
SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set
|
||||
int m_resizeCount = 0; //!< flag / counter, how many resize activities
|
||||
int m_skipResizeThreshold = 40; //!< when to skip resize (rows count)
|
||||
int m_resizeAutoNthTime = 1; //!< with ResizeAuto, resize every n-th time
|
||||
@@ -355,6 +360,9 @@ namespace BlackGui
|
||||
//! Toggle auto display flag
|
||||
void ps_toggleAutoDisplay();
|
||||
|
||||
//! Toogle between single and multi selection
|
||||
void ps_toggleSelectionMode();
|
||||
|
||||
//! Clear the model
|
||||
virtual void ps_clear() { this->clear(); }
|
||||
|
||||
|
||||
@@ -84,17 +84,13 @@ namespace BlackGui
|
||||
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))
|
||||
{
|
||||
if (!menu.isEmpty())
|
||||
{
|
||||
menu.addSeparator();
|
||||
}
|
||||
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB data", this, SLOT(ps_toggleHighlightDbData()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(this->derivedModel()->highlightDbData());
|
||||
}
|
||||
CViewBase<ModelClass, ContainerType, ObjectType>::customMenu(menu);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
|
||||
Reference in New Issue
Block a user