refs #568, allow to stash from DB data view (model view)

* added required signal slots
* moved models for stashing into aircraft model view
* allow to unselect when stashed
* fixed DB object highlighting and resize row height automatically
This commit is contained in:
Klaus Basan
2016-01-09 03:37:07 +01:00
parent 0326356f43
commit 11ee49a382
12 changed files with 209 additions and 106 deletions

View File

@@ -36,7 +36,7 @@ namespace BlackGui
this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::OwnSimulatorModel, this));
// shortcut
new QShortcut(CShortcut::keyStash(), this, SLOT(ps_stashShortcut()), nullptr, Qt::WidgetShortcut);
new QShortcut(CShortcut::keyStash(), this, SLOT(ps_requestStash()), nullptr, Qt::WidgetShortcut);
// default mode
CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode();
@@ -56,12 +56,10 @@ namespace BlackGui
this->m_menus = MenuBackend;
break;
case CAircraftModelListModel::VPilotRuleModel:
this->m_menus = MenuRefresh | MenuHighlightDbData;;
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
this->m_menus = MenuRefresh | MenuStashing | MenuHighlightDbData;
break;
case CAircraftModelListModel::OwnSimulatorModelMapping:
this->m_menus = MenuDisplayAutomatically | MenuHighlightDbData;
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
this->m_menus = MenuDisplayAutomatically | MenuStashing | MenuHighlightDbData;
break;
case CAircraftModelListModel::OwnSimulatorModel:
default:
@@ -93,7 +91,7 @@ namespace BlackGui
bool CAircraftModelView::hasSelectedModelsToStash() const
{
return m_allowStash && hasSelection();
return m_menus.testFlag(MenuStashModels) && hasSelection();
}
void CAircraftModelView::setImplementedMetaTypeIds()
@@ -215,26 +213,50 @@ namespace BlackGui
} // valid mime?
}
void CAircraftModelView::customMenu(QMenu &menu) const
{
bool added = false;
if (this->m_menus.testFlag(MenuStashModels))
{
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
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(); }
CViewWithDbObjects::customMenu(menu);
}
void CAircraftModelView::ps_toggleHighlightStashedModels()
{
bool h = derivedModel()->highlightGivenModelStrings();
derivedModel()->setHighlightModelsStrings(!h);
emit toggledHighlightStashedModels();
}
void CAircraftModelView::ps_stashShortcut()
void CAircraftModelView::ps_stashingClearsSelection()
{
if (!m_allowStash) { return; }
emit requestStash();
this->m_stashingClearsSelection = !this->m_stashingClearsSelection;
}
void CAircraftModelView::CHighlightStashedModelsMenu::customMenu(QMenu &menu) const
void CAircraftModelView::ps_requestStash()
{
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
Q_ASSERT_X(mv, Q_FUNC_INFO, "no view");
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight stashed models", mv, SLOT(ps_toggleHighlightStashedModels()));
a->setCheckable(true);
a->setChecked(mv->derivedModel()->highlightGivenModelStrings());
this->nestedCustomMenu(menu);
if (!m_menus.testFlag(MenuStashModels)) { return; }
if (!this->hasSelection()) { return; }
emit requestStash(this->selectedObjects());
if (this->m_stashingClearsSelection)
{
this->clearSelection();
}
}
} // namespace
} // namespace

View File

@@ -43,9 +43,6 @@ namespace BlackGui
//! Apply to selected objects
int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
//! Allow to stash
void setAllowStash(bool stash) { m_allowStash = stash; }
//! Has any models to stash and it is allowed to stash
bool hasSelectedModelsToStash() const;
@@ -60,7 +57,10 @@ namespace BlackGui
signals:
//! Request to stash if applicable
void requestStash();
void requestStash(const BlackMisc::Simulation::CAircraftModelList &models);
//! Highligh stashed models has been toggled
void toggledHighlightStashedModels();
//! Request further handling of drops I cannot handle on my own
void requestHandlingOfStashDrop(const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcao);
@@ -69,26 +69,21 @@ namespace BlackGui
//! \copydoc QTableView::dropEvent
virtual void dropEvent(QDropEvent *event) override;
//! \copydoc CViewBaseNonTemplate::customMenu
virtual void customMenu(QMenu &menu) const override;
private slots:
//! Highlight stashed models
void ps_toggleHighlightStashedModels();
//! Toggle if stashing unselects
void ps_stashingClearsSelection();
//! Stash shortcut pressed
void ps_stashShortcut();
void ps_requestStash();
private:
bool m_allowStash = false; //!< allow to stash
//! Custom menu for the models which have been loaded
class CHighlightStashedModelsMenu : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CHighlightStashedModelsMenu(CAircraftModelView *parent, bool separatorAtEnd) : IMenuDelegate(parent, separatorAtEnd) {}
//! \copydoc IMenuDelegate::customMenu
virtual void customMenu(QMenu &menu) const override;
};
bool m_stashingClearsSelection = true; //!< stashing unselects
};
} // ns
} // ns

View File

@@ -208,24 +208,30 @@ namespace BlackGui
// resizing
menu.addAction(BlackMisc::CIcons::resize16(), "Full resize", this, SLOT(fullResizeToContents()));
if (m_rowResizeMode == Interactive)
{
menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows to content", this, SLOT(rowsResizeModeToContent()));
}
else
{
menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows interactive", this, SLOT(rowsResizeModeToInteractive()));
}
// resize to content might decrease performance,
// so I only allow changing to "content resizing" if size matches
bool enabled = !this->reachedResizeThreshold();
bool autoResize = this->m_resizeMode == ResizingAuto;
// when not auto let set how we want to resize rows
if (m_rowResizeMode == Interactive)
{
QAction *a = menu.addAction(BlackMisc::CIcons::resizeVertical16(), " Resize rows to content (auto)", this, SLOT(rowsResizeModeToContent()));
a->setEnabled(enabled && !autoResize);
}
else
{
QAction *a = menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows interactive", this, SLOT(rowsResizeModeToInteractive()));
a->setEnabled(!autoResize);
}
QAction *actionInteractiveResize = new QAction(&menu);
actionInteractiveResize->setObjectName(this->objectName().append("ActionResizing"));
actionInteractiveResize->setIconText("Resize (auto)");
actionInteractiveResize->setIcon(CIcons::viewMultiColumn());
actionInteractiveResize->setCheckable(true);
actionInteractiveResize->setChecked(this->m_resizeMode == ResizingAuto);
actionInteractiveResize->setChecked(autoResize);
actionInteractiveResize->setEnabled(enabled);
menu.addAction(actionInteractiveResize);
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::ps_toggleResizeMode);

View File

@@ -77,10 +77,14 @@ namespace BlackGui
MenuFilter = 1 << 5, ///< filter can be opened
MenuSave = 1 << 6, ///< save as JSON
MenuLoad = 1 << 7, ///< load from JSON
MenuLoadAndSave = MenuLoad | MenuSave,
MenuLoadAndSave = MenuLoad | MenuSave,
MenuDefault = MenuClear | MenuDisplayAutomatically,
// special menu, should be in derived class but enums cannot be derived
MenuHighlightDbData = 1 << 8, ///< highlight DB data
// 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,
};
Q_DECLARE_FLAGS(Menu, MenuFlag)
@@ -332,6 +336,12 @@ namespace BlackGui
//! Save JSON called by shortcut
virtual void ps_saveJsonShortcut();
// ------------ slots of CViewDbObjects ----------------
// need to be declared here and overridden, as this is the only part with valid Q_OBJECT
//! Highlight DB data
virtual void ps_toggleHighlightDbData() {}
private slots:
//! Custom menu was requested
void ps_customMenuRequested(QPoint pos);
@@ -480,6 +490,8 @@ namespace BlackGui
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::performUpdateContainer
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) override;
// --------------------------------------------- SLOTS start here -----------------------------------------
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_filterDialogFinished
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
virtual bool ps_filterDialogFinished(int status) override;

View File

@@ -70,21 +70,35 @@ namespace BlackGui
return delta;
}
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
int CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::replaceOrAddObjectsByKey(const ContainerType &container)
{
if (container.isEmpty()) { return 0; }
ContainerType copy(this->container());
int c = copy.replaceOrAddObjectsByKey(container);
if (c == 0) { return 0; }
this->updateContainerMaybeAsync(copy);
return c;
}
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()));
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());
}
}
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleDbData()
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleHighlightDbData()
{
bool h = this->derivedModel()->highlightDbData();
this->derivedModel()->setHighlightDbData(!h);

View File

@@ -37,6 +37,9 @@ namespace BlackGui
//! Remove keys
int removeDbKeys(const QList<KeyType> &keys);
//! Update or insert data (based on DB key)
int replaceOrAddObjectsByKey(const ContainerType &container);
protected:
//! Constructor
explicit CViewWithDbObjects(QWidget *parent = nullptr);
@@ -44,9 +47,9 @@ namespace BlackGui
//! \copydoc QWidget::customMenu
virtual void customMenu(QMenu &menu) const override;
private slots:
//! Highlight DB data
void ps_toggleDbData();
protected slots:
//! \copydoc CViewBaseNonTemplate::ps_toggleHighlightDbData
virtual void ps_toggleHighlightDbData() override;
};
} // namespace
} // namespace