mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-24 18:04:14 +08:00
Some view/model improvements
* unselected functions as unselectedRowCount/unselectedRows ... * turned some private slots -> private functions
This commit is contained in:
@@ -26,6 +26,10 @@ namespace BlackGui
|
|||||||
//! Selected objects
|
//! Selected objects
|
||||||
virtual ContainerType selectedObjects() const = 0;
|
virtual ContainerType selectedObjects() const = 0;
|
||||||
|
|
||||||
|
//! Unselected objects
|
||||||
|
//! \remark for filtered models this only returns the unselected filtered objects
|
||||||
|
virtual ContainerType unselectedObjects() const = 0;
|
||||||
|
|
||||||
//! Select
|
//! Select
|
||||||
virtual void selectObjects(const ContainerType &selectedObjects) = 0;
|
virtual void selectObjects(const ContainerType &selectedObjects) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace BlackGui
|
|||||||
QTableView(parent)
|
QTableView(parent)
|
||||||
{
|
{
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::ps_customMenuRequested);
|
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::customMenuRequested);
|
||||||
connect(this, &QTableView::clicked, this, &CViewBaseNonTemplate::ps_clicked);
|
connect(this, &QTableView::clicked, this, &CViewBaseNonTemplate::ps_clicked);
|
||||||
connect(this, &QTableView::doubleClicked, this, &CViewBaseNonTemplate::ps_doubleClicked);
|
connect(this, &QTableView::doubleClicked, this, &CViewBaseNonTemplate::ps_doubleClicked);
|
||||||
this->horizontalHeader()->setSortIndicatorShown(true);
|
this->horizontalHeader()->setSortIndicatorShown(true);
|
||||||
@@ -239,13 +239,13 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
case MenuDisplayAutomatically:
|
case MenuDisplayAutomatically:
|
||||||
{
|
{
|
||||||
QAction *a = ma.addAction(CIcons::appMappings16(), "Automatically display (when loaded)", CMenuAction::pathViewUpdates(), { this, &CViewBaseNonTemplate::ps_toggleAutoDisplay });
|
QAction *a = ma.addAction(CIcons::appMappings16(), "Automatically display (when loaded)", CMenuAction::pathViewUpdates(), { this, &CViewBaseNonTemplate::toggleAutoDisplay });
|
||||||
a->setCheckable(true);
|
a->setCheckable(true);
|
||||||
a->setChecked(this->displayAutomatically());
|
a->setChecked(this->displayAutomatically());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MenuRemoveSelectedRows: { ma.addAction(CIcons::delete16(), "Remove selected rows", CMenuAction::pathViewAddRemove(), { this, &CViewBaseNonTemplate::ps_removeSelectedRows }, CShortcut::keyDelete()); break; }
|
case MenuRemoveSelectedRows: { ma.addAction(CIcons::delete16(), "Remove selected rows", CMenuAction::pathViewAddRemove(), { this, &CViewBaseNonTemplate::ps_removeSelectedRows }, CShortcut::keyDelete()); break; }
|
||||||
case MenuClear: { ma.addAction(CIcons::delete16(), "Clear", CMenuAction::pathViewAddRemove(), { this, &CViewBaseNonTemplate::ps_clear }); break; }
|
case MenuClear: { ma.addAction(CIcons::delete16(), "Clear", CMenuAction::pathViewAddRemove(), { this, &CViewBaseNonTemplate::clear }); break; }
|
||||||
case MenuFilter:
|
case MenuFilter:
|
||||||
{
|
{
|
||||||
if (m_filterWidget)
|
if (m_filterWidget)
|
||||||
@@ -306,7 +306,7 @@ namespace BlackGui
|
|||||||
if (m_showingLoadIndicator)
|
if (m_showingLoadIndicator)
|
||||||
{
|
{
|
||||||
// just in case, if this ever will be dangling
|
// just in case, if this ever will be dangling
|
||||||
menuActions.addAction(CIcons::preloader16(), "Hide load indicator", CMenuAction::pathViewUpdates(), nullptr, { this, &CViewBaseNonTemplate::ps_hideLoadIndicator });
|
menuActions.addAction(CIcons::preloader16(), "Hide load indicator", CMenuAction::pathViewUpdates(), nullptr, { this, &CViewBaseNonTemplate::hideLoacIndicatorForced });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_menus.testFlag(MenuClear)) { menuActions.addActions(this->initMenuActions(MenuClear)); }
|
if (m_menus.testFlag(MenuClear)) { menuActions.addActions(this->initMenuActions(MenuClear)); }
|
||||||
@@ -355,17 +355,17 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (sm != MultiSelection)
|
if (sm != MultiSelection)
|
||||||
{
|
{
|
||||||
menuActions.addAction("Switch to multi selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setMultiSelection });
|
menuActions.addAction("Switch to multi selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::setMultiSelection });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm != ExtendedSelection)
|
if (sm != ExtendedSelection)
|
||||||
{
|
{
|
||||||
menuActions.addAction("Switch to extended selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setExtendedSelection });
|
menuActions.addAction("Switch to extended selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::setExtendedSelection });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm != SingleSelection)
|
if (sm != SingleSelection)
|
||||||
{
|
{
|
||||||
menuActions.addAction("Switch to single selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::ps_setSingleSelection });
|
menuActions.addAction("Switch to single selection", CMenuAction::pathViewSelection(), nullptr, { this, &CViewBaseNonTemplate::setSingleSelection });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ namespace BlackGui
|
|||||||
actionInteractiveResize->setCheckable(true);
|
actionInteractiveResize->setCheckable(true);
|
||||||
actionInteractiveResize->setChecked(autoResize);
|
actionInteractiveResize->setChecked(autoResize);
|
||||||
actionInteractiveResize->setEnabled(enabled);
|
actionInteractiveResize->setEnabled(enabled);
|
||||||
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::ps_toggleResizeMode);
|
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::toggleResizeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::resizeEvent(QResizeEvent *event)
|
void CViewBaseNonTemplate::resizeEvent(QResizeEvent *event)
|
||||||
@@ -428,6 +428,20 @@ namespace BlackGui
|
|||||||
return this->selectionModel()->selectedRows();
|
return this->selectionModel()->selectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndexList CViewBaseNonTemplate::unselectedRows() const
|
||||||
|
{
|
||||||
|
QModelIndexList selected = this->selectedRows();
|
||||||
|
QModelIndexList unselected;
|
||||||
|
const int rows = this->rowCount();
|
||||||
|
for (int r = 0; r < rows; r++)
|
||||||
|
{
|
||||||
|
const QModelIndex mi = this->model()->index(r, 0);
|
||||||
|
if (selected.contains(mi)) { continue; }
|
||||||
|
unselected.push_back(mi);
|
||||||
|
}
|
||||||
|
return unselected;
|
||||||
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::selectRows(const QSet<int> &rows)
|
void CViewBaseNonTemplate::selectRows(const QSet<int> &rows)
|
||||||
{
|
{
|
||||||
if (!this->selectionModel()) { return; }
|
if (!this->selectionModel()) { return; }
|
||||||
@@ -449,6 +463,11 @@ namespace BlackGui
|
|||||||
return this->selectedRows().count();
|
return this->selectedRows().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CViewBaseNonTemplate::unselectedRowCount() const
|
||||||
|
{
|
||||||
|
return this->rowCount() - this->selectedRowCount();
|
||||||
|
}
|
||||||
|
|
||||||
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
||||||
{
|
{
|
||||||
return this->selectedRowCount() == 1;
|
return this->selectedRowCount() == 1;
|
||||||
@@ -581,11 +600,6 @@ namespace BlackGui
|
|||||||
emit this->requestNewBackendData();
|
emit this->requestNewBackendData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_hideLoadIndicator()
|
|
||||||
{
|
|
||||||
this->hideLoadIndicator();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CViewBaseNonTemplate::onModelChanged()
|
void CViewBaseNonTemplate::onModelChanged()
|
||||||
{
|
{
|
||||||
this->updateSortIndicator();
|
this->updateSortIndicator();
|
||||||
@@ -662,7 +676,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!m_showingLoadIndicator) { return; }
|
if (!m_showingLoadIndicator) { return; }
|
||||||
m_showingLoadIndicator = false;
|
m_showingLoadIndicator = false;
|
||||||
emit loadIndicatorVisibilityChanged(m_showingLoadIndicator);
|
emit this->loadIndicatorVisibilityChanged(m_showingLoadIndicator);
|
||||||
if (!m_loadIndicator) { return; }
|
if (!m_loadIndicator) { return; }
|
||||||
m_loadIndicator->stopAnimation(loadingId);
|
m_loadIndicator->stopAnimation(loadingId);
|
||||||
}
|
}
|
||||||
@@ -715,7 +729,7 @@ namespace BlackGui
|
|||||||
this->setVisible(true);
|
this->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_customMenuRequested(QPoint pos)
|
void CViewBaseNonTemplate::customMenuRequested(QPoint pos)
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
CMenuActions menuActions;
|
CMenuActions menuActions;
|
||||||
@@ -737,32 +751,25 @@ namespace BlackGui
|
|||||||
menu.exec(globalPos);
|
menu.exec(globalPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_toggleResizeMode(bool checked)
|
void CViewBaseNonTemplate::toggleResizeMode(bool checked)
|
||||||
{
|
{
|
||||||
if (checked)
|
m_resizeMode = checked ? ResizingAuto : ResizingOff;
|
||||||
{
|
|
||||||
m_resizeMode = ResizingAuto;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_resizeMode = ResizingOff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_toggleAutoDisplay()
|
void CViewBaseNonTemplate::toggleAutoDisplay()
|
||||||
{
|
{
|
||||||
QAction *a = qobject_cast<QAction *>(QObject::sender());
|
const QAction *a = qobject_cast<const QAction *>(QObject::sender());
|
||||||
if (!a) { return; }
|
if (!a) { return; }
|
||||||
Q_ASSERT_X(a->isCheckable(), Q_FUNC_INFO, "object not checkable");
|
Q_ASSERT_X(a->isCheckable(), Q_FUNC_INFO, "object not checkable");
|
||||||
m_displayAutomatically = a->isChecked();
|
m_displayAutomatically = a->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_setSingleSelection()
|
void CViewBaseNonTemplate::setSingleSelection()
|
||||||
{
|
{
|
||||||
this->setSelectionMode(SingleSelection);
|
this->setSelectionMode(SingleSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_setExtendedSelection()
|
void CViewBaseNonTemplate::setExtendedSelection()
|
||||||
{
|
{
|
||||||
if (this->allowsMultipleSelectedRows())
|
if (this->allowsMultipleSelectedRows())
|
||||||
{
|
{
|
||||||
@@ -770,7 +777,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_setMultiSelection()
|
void CViewBaseNonTemplate::setMultiSelection()
|
||||||
{
|
{
|
||||||
if (this->allowsMultipleSelectedRows())
|
if (this->allowsMultipleSelectedRows())
|
||||||
{
|
{
|
||||||
@@ -784,7 +791,7 @@ namespace BlackGui
|
|||||||
this->removeSelectedRows();
|
this->removeSelectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_updatedIndicator()
|
void CViewBaseNonTemplate::updatedIndicator()
|
||||||
{
|
{
|
||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
@@ -986,7 +993,20 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!this->hasSelection()) { return ContainerType(); }
|
if (!this->hasSelection()) { return ContainerType(); }
|
||||||
ContainerType c;
|
ContainerType c;
|
||||||
QModelIndexList indexes = this->selectedRows();
|
const QModelIndexList indexes = this->selectedRows();
|
||||||
|
for (const QModelIndex &i : indexes)
|
||||||
|
{
|
||||||
|
c.push_back(this->at(i));
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
|
ContainerType CViewBase<ModelClass, ContainerType, ObjectType>::unselectedObjects() const
|
||||||
|
{
|
||||||
|
if (!this->hasSelection()) { return this->containerOrFilteredContainer(); }
|
||||||
|
ContainerType c;
|
||||||
|
const QModelIndexList indexes = this->unselectedRows();
|
||||||
for (const QModelIndex &i : indexes)
|
for (const QModelIndex &i : indexes)
|
||||||
{
|
{
|
||||||
c.push_back(this->at(i));
|
c.push_back(this->at(i));
|
||||||
|
|||||||
@@ -202,12 +202,18 @@ namespace BlackGui
|
|||||||
//! Selected rows if any
|
//! Selected rows if any
|
||||||
QModelIndexList selectedRows() const;
|
QModelIndexList selectedRows() const;
|
||||||
|
|
||||||
|
//! Unselected (not selected) rows if any
|
||||||
|
virtual QModelIndexList unselectedRows() const;
|
||||||
|
|
||||||
//! Select given rows
|
//! Select given rows
|
||||||
void selectRows(const QSet<int> &rows);
|
void selectRows(const QSet<int> &rows);
|
||||||
|
|
||||||
//! Number of selected rows
|
//! Number of selected rows
|
||||||
int selectedRowCount() const;
|
int selectedRowCount() const;
|
||||||
|
|
||||||
|
//! Unselected row count
|
||||||
|
int unselectedRowCount() const;
|
||||||
|
|
||||||
//! Single selected row
|
//! Single selected row
|
||||||
bool hasSingleSelectedRow() const;
|
bool hasSingleSelectedRow() const;
|
||||||
|
|
||||||
@@ -350,6 +356,9 @@ namespace BlackGui
|
|||||||
//! Hide loading indicator
|
//! Hide loading indicator
|
||||||
void hideLoadIndicator(int loadingId = -1);
|
void hideLoadIndicator(int loadingId = -1);
|
||||||
|
|
||||||
|
//! Parameterless version of hideLoadIndicator
|
||||||
|
void hideLoacIndicatorForced() { this->hideLoadIndicator(); }
|
||||||
|
|
||||||
//! Remove selected rows
|
//! Remove selected rows
|
||||||
virtual int removeSelectedRows() = 0;
|
virtual int removeSelectedRows() = 0;
|
||||||
|
|
||||||
@@ -368,7 +377,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Method creating the menu
|
//! Method creating the menu
|
||||||
//! \remarks override this method to contribute to the menu
|
//! \remarks override this method to contribute to the menu
|
||||||
//! \sa BlackGui::Views::CViewBaseNonTemplate::ps_customMenuRequested
|
//! \sa BlackGui::Views::CViewBaseNonTemplate::customMenuRequested
|
||||||
virtual void customMenu(Menus::CMenuActions &menuActions);
|
virtual void customMenu(Menus::CMenuActions &menuActions);
|
||||||
|
|
||||||
//! \name Functions from QTableView
|
//! \name Functions from QTableView
|
||||||
@@ -493,9 +502,6 @@ namespace BlackGui
|
|||||||
//! Trigger reload from backend by signal requestNewBackendData()
|
//! Trigger reload from backend by signal requestNewBackendData()
|
||||||
void ps_triggerReloadFromBackend();
|
void ps_triggerReloadFromBackend();
|
||||||
|
|
||||||
//! Hide load indicator (no parameters)
|
|
||||||
void ps_hideLoadIndicator();
|
|
||||||
|
|
||||||
//! Copy
|
//! Copy
|
||||||
virtual void ps_copy() = 0;
|
virtual void ps_copy() = 0;
|
||||||
|
|
||||||
@@ -512,32 +518,28 @@ namespace BlackGui
|
|||||||
virtual void ps_toggleHighlightDbData() {}
|
virtual void ps_toggleHighlightDbData() {}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Custom menu was requested
|
|
||||||
void ps_customMenuRequested(QPoint pos);
|
|
||||||
|
|
||||||
//! Toggle the resize mode
|
|
||||||
void ps_toggleResizeMode(bool checked);
|
|
||||||
|
|
||||||
//! Indicator has been updated
|
|
||||||
void ps_updatedIndicator();
|
|
||||||
|
|
||||||
//! Toggle auto display flag
|
|
||||||
void ps_toggleAutoDisplay();
|
|
||||||
|
|
||||||
//! \name Change selection modes
|
|
||||||
//! @{
|
|
||||||
void ps_setMultiSelection();
|
|
||||||
void ps_setExtendedSelection();
|
|
||||||
void ps_setSingleSelection();
|
|
||||||
//! @}
|
|
||||||
|
|
||||||
//! Clear the model
|
|
||||||
virtual void ps_clear() { this->clear(); }
|
|
||||||
|
|
||||||
//! Remove selected rows
|
//! Remove selected rows
|
||||||
void ps_removeSelectedRows();
|
void ps_removeSelectedRows();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! \name Change selection modes @{
|
||||||
|
void setMultiSelection();
|
||||||
|
void setExtendedSelection();
|
||||||
|
void setSingleSelection();
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Toggle auto display flag
|
||||||
|
void toggleAutoDisplay();
|
||||||
|
|
||||||
|
//! Custom menu was requested
|
||||||
|
void customMenuRequested(QPoint pos);
|
||||||
|
|
||||||
|
//! Indicator has been updated
|
||||||
|
void updatedIndicator();
|
||||||
|
|
||||||
|
//! Toggle the resize mode
|
||||||
|
void toggleResizeMode(bool checked);
|
||||||
|
|
||||||
//! Set the filter widget internally
|
//! Set the filter widget internally
|
||||||
//! \remarks used for dialog and filter widget
|
//! \remarks used for dialog and filter widget
|
||||||
void setFilterWidgetImpl(QWidget *filterWidget);
|
void setFilterWidgetImpl(QWidget *filterWidget);
|
||||||
@@ -587,10 +589,11 @@ namespace BlackGui
|
|||||||
//! \copydoc BlackGui::Models::CListModelBase::containerOrFilteredContainer
|
//! \copydoc BlackGui::Models::CListModelBase::containerOrFilteredContainer
|
||||||
const ContainerType &containerOrFilteredContainer(bool *filtered = nullptr) const;
|
const ContainerType &containerOrFilteredContainer(bool *filtered = nullptr) const;
|
||||||
|
|
||||||
//! \name Selection model interface
|
//! \name Selection model interface ISelectionModel
|
||||||
//! @{
|
//! @{
|
||||||
virtual void selectObjects(const ContainerType &selectedObjects) override;
|
virtual void selectObjects(const ContainerType &selectedObjects) override;
|
||||||
virtual ContainerType selectedObjects() const override;
|
virtual ContainerType selectedObjects() const override;
|
||||||
|
virtual ContainerType unselectedObjects() const override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! First selected, the only one, or default
|
//! First selected, the only one, or default
|
||||||
|
|||||||
Reference in New Issue
Block a user