mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +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
|
||||
virtual ContainerType selectedObjects() const = 0;
|
||||
|
||||
//! Unselected objects
|
||||
//! \remark for filtered models this only returns the unselected filtered objects
|
||||
virtual ContainerType unselectedObjects() const = 0;
|
||||
|
||||
//! Select
|
||||
virtual void selectObjects(const ContainerType &selectedObjects) = 0;
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace BlackGui
|
||||
QTableView(parent)
|
||||
{
|
||||
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::doubleClicked, this, &CViewBaseNonTemplate::ps_doubleClicked);
|
||||
this->horizontalHeader()->setSortIndicatorShown(true);
|
||||
@@ -239,13 +239,13 @@ namespace BlackGui
|
||||
}
|
||||
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->setChecked(this->displayAutomatically());
|
||||
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:
|
||||
{
|
||||
if (m_filterWidget)
|
||||
@@ -306,7 +306,7 @@ namespace BlackGui
|
||||
if (m_showingLoadIndicator)
|
||||
{
|
||||
// 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)); }
|
||||
@@ -355,17 +355,17 @@ namespace BlackGui
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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->setChecked(autoResize);
|
||||
actionInteractiveResize->setEnabled(enabled);
|
||||
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::ps_toggleResizeMode);
|
||||
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::toggleResizeMode);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::resizeEvent(QResizeEvent *event)
|
||||
@@ -428,6 +428,20 @@ namespace BlackGui
|
||||
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)
|
||||
{
|
||||
if (!this->selectionModel()) { return; }
|
||||
@@ -449,6 +463,11 @@ namespace BlackGui
|
||||
return this->selectedRows().count();
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::unselectedRowCount() const
|
||||
{
|
||||
return this->rowCount() - this->selectedRowCount();
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
||||
{
|
||||
return this->selectedRowCount() == 1;
|
||||
@@ -581,11 +600,6 @@ namespace BlackGui
|
||||
emit this->requestNewBackendData();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_hideLoadIndicator()
|
||||
{
|
||||
this->hideLoadIndicator();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::onModelChanged()
|
||||
{
|
||||
this->updateSortIndicator();
|
||||
@@ -662,7 +676,7 @@ namespace BlackGui
|
||||
{
|
||||
if (!m_showingLoadIndicator) { return; }
|
||||
m_showingLoadIndicator = false;
|
||||
emit loadIndicatorVisibilityChanged(m_showingLoadIndicator);
|
||||
emit this->loadIndicatorVisibilityChanged(m_showingLoadIndicator);
|
||||
if (!m_loadIndicator) { return; }
|
||||
m_loadIndicator->stopAnimation(loadingId);
|
||||
}
|
||||
@@ -670,9 +684,9 @@ namespace BlackGui
|
||||
bool CViewBaseNonTemplate::isResizeConditionMet(int containerSize) const
|
||||
{
|
||||
if (m_resizeMode == ResizingAlways) { return true; }
|
||||
if (m_resizeMode == PresizeSubset) { return false; }
|
||||
if (m_resizeMode == ResizingOff) { return false; }
|
||||
if (m_resizeMode == ResizingOnce) { return m_resizeCount < 1; }
|
||||
if (m_resizeMode == PresizeSubset) { return false; }
|
||||
if (m_resizeMode == ResizingOff) { return false; }
|
||||
if (m_resizeMode == ResizingOnce) { return m_resizeCount < 1; }
|
||||
if (m_resizeMode == ResizingAuto)
|
||||
{
|
||||
if (reachedResizeThreshold(containerSize)) { return false; }
|
||||
@@ -715,7 +729,7 @@ namespace BlackGui
|
||||
this->setVisible(true);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_customMenuRequested(QPoint pos)
|
||||
void CViewBaseNonTemplate::customMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu;
|
||||
CMenuActions menuActions;
|
||||
@@ -737,32 +751,25 @@ namespace BlackGui
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_toggleResizeMode(bool checked)
|
||||
void CViewBaseNonTemplate::toggleResizeMode(bool checked)
|
||||
{
|
||||
if (checked)
|
||||
{
|
||||
m_resizeMode = ResizingAuto;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resizeMode = ResizingOff;
|
||||
}
|
||||
m_resizeMode = checked ? ResizingAuto : 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; }
|
||||
Q_ASSERT_X(a->isCheckable(), Q_FUNC_INFO, "object not checkable");
|
||||
m_displayAutomatically = a->isChecked();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_setSingleSelection()
|
||||
void CViewBaseNonTemplate::setSingleSelection()
|
||||
{
|
||||
this->setSelectionMode(SingleSelection);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_setExtendedSelection()
|
||||
void CViewBaseNonTemplate::setExtendedSelection()
|
||||
{
|
||||
if (this->allowsMultipleSelectedRows())
|
||||
{
|
||||
@@ -770,7 +777,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_setMultiSelection()
|
||||
void CViewBaseNonTemplate::setMultiSelection()
|
||||
{
|
||||
if (this->allowsMultipleSelectedRows())
|
||||
{
|
||||
@@ -784,7 +791,7 @@ namespace BlackGui
|
||||
this->removeSelectedRows();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_updatedIndicator()
|
||||
void CViewBaseNonTemplate::updatedIndicator()
|
||||
{
|
||||
this->update();
|
||||
}
|
||||
@@ -986,7 +993,20 @@ namespace BlackGui
|
||||
{
|
||||
if (!this->hasSelection()) { return ContainerType(); }
|
||||
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)
|
||||
{
|
||||
c.push_back(this->at(i));
|
||||
|
||||
@@ -202,12 +202,18 @@ namespace BlackGui
|
||||
//! Selected rows if any
|
||||
QModelIndexList selectedRows() const;
|
||||
|
||||
//! Unselected (not selected) rows if any
|
||||
virtual QModelIndexList unselectedRows() const;
|
||||
|
||||
//! Select given rows
|
||||
void selectRows(const QSet<int> &rows);
|
||||
|
||||
//! Number of selected rows
|
||||
int selectedRowCount() const;
|
||||
|
||||
//! Unselected row count
|
||||
int unselectedRowCount() const;
|
||||
|
||||
//! Single selected row
|
||||
bool hasSingleSelectedRow() const;
|
||||
|
||||
@@ -350,6 +356,9 @@ namespace BlackGui
|
||||
//! Hide loading indicator
|
||||
void hideLoadIndicator(int loadingId = -1);
|
||||
|
||||
//! Parameterless version of hideLoadIndicator
|
||||
void hideLoacIndicatorForced() { this->hideLoadIndicator(); }
|
||||
|
||||
//! Remove selected rows
|
||||
virtual int removeSelectedRows() = 0;
|
||||
|
||||
@@ -368,7 +377,7 @@ namespace BlackGui
|
||||
|
||||
//! Method creating 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);
|
||||
|
||||
//! \name Functions from QTableView
|
||||
@@ -493,9 +502,6 @@ namespace BlackGui
|
||||
//! Trigger reload from backend by signal requestNewBackendData()
|
||||
void ps_triggerReloadFromBackend();
|
||||
|
||||
//! Hide load indicator (no parameters)
|
||||
void ps_hideLoadIndicator();
|
||||
|
||||
//! Copy
|
||||
virtual void ps_copy() = 0;
|
||||
|
||||
@@ -512,32 +518,28 @@ namespace BlackGui
|
||||
virtual void ps_toggleHighlightDbData() {}
|
||||
|
||||
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
|
||||
void ps_removeSelectedRows();
|
||||
|
||||
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
|
||||
//! \remarks used for dialog and filter widget
|
||||
void setFilterWidgetImpl(QWidget *filterWidget);
|
||||
@@ -587,10 +589,11 @@ namespace BlackGui
|
||||
//! \copydoc BlackGui::Models::CListModelBase::containerOrFilteredContainer
|
||||
const ContainerType &containerOrFilteredContainer(bool *filtered = nullptr) const;
|
||||
|
||||
//! \name Selection model interface
|
||||
//! \name Selection model interface ISelectionModel
|
||||
//! @{
|
||||
virtual void selectObjects(const ContainerType &selectedObjects) override;
|
||||
virtual ContainerType selectedObjects() const override;
|
||||
virtual ContainerType unselectedObjects() const override;
|
||||
//! @}
|
||||
|
||||
//! First selected, the only one, or default
|
||||
|
||||
Reference in New Issue
Block a user