mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
refs #576, tweaking view base
* renaming in view base (similar to Qt name rowCount) * insert function for whole container
This commit is contained in:
@@ -434,6 +434,23 @@ namespace BlackGui
|
|||||||
this->emitRowCountChanged();
|
this->emitRowCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
|
void CListModelBase<ObjectType, ContainerType, UseCompare>::insert(const ContainerType &container)
|
||||||
|
{
|
||||||
|
if (container.isEmpty()) { return; }
|
||||||
|
beginInsertRows(QModelIndex(), 0, 0);
|
||||||
|
this->m_container.insert(container);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
if (this->hasFilter())
|
||||||
|
{
|
||||||
|
this->beginResetModel();
|
||||||
|
this->updateFilteredContainer();
|
||||||
|
this->endResetModel();
|
||||||
|
}
|
||||||
|
this->emitRowCountChanged();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::remove(const ObjectType &object)
|
void CListModelBase<ObjectType, ContainerType, UseCompare>::remove(const ObjectType &object)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -213,6 +213,9 @@ namespace BlackGui
|
|||||||
//! Similar to ContainerType::insert here inserts at first position
|
//! Similar to ContainerType::insert here inserts at first position
|
||||||
virtual void insert(const ObjectType &object);
|
virtual void insert(const ObjectType &object);
|
||||||
|
|
||||||
|
//! Similar to ContainerType::insert here inserts at first position
|
||||||
|
virtual void insert(const ContainerType &container);
|
||||||
|
|
||||||
//! Remove object
|
//! Remove object
|
||||||
virtual void remove(const ObjectType &object);
|
virtual void remove(const ObjectType &object);
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CViewBaseNonTemplate::setFilterWidgetImpl(QWidget *filterWidget)
|
void CViewBaseNonTemplate::setFilterWidgetImpl(QWidget *filterWidget)
|
||||||
{
|
{
|
||||||
|
// dialog or filter widget
|
||||||
if (this->m_filterWidget)
|
if (this->m_filterWidget)
|
||||||
{
|
{
|
||||||
disconnect(this->m_filterWidget);
|
disconnect(this->m_filterWidget);
|
||||||
@@ -191,8 +192,8 @@ namespace BlackGui
|
|||||||
items = menu.actions().size();
|
items = menu.actions().size();
|
||||||
if (this->m_menus.testFlag(MenuFilter))
|
if (this->m_menus.testFlag(MenuFilter))
|
||||||
{
|
{
|
||||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Filter", this, SLOT(ps_displayFilterDialog()), CShortcut::keyDisplayFilter());
|
menu.addAction(CIcons::filter16(), "Filter", this, SLOT(ps_displayFilterDialog()), CShortcut::keyDisplayFilter());
|
||||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Remove Filter", this, SLOT(ps_removeFilter()));
|
menu.addAction(CIcons::filter16(), "Remove Filter", this, SLOT(ps_removeFilter()));
|
||||||
}
|
}
|
||||||
if (menu.actions().size() > items) { menu.addSeparator(); }
|
if (menu.actions().size() > items) { menu.addSeparator(); }
|
||||||
|
|
||||||
@@ -205,17 +206,22 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
if ((this->m_originalSelectionMode == MultiSelection || this->m_originalSelectionMode == ExtendedSelection) && this->m_menus.testFlag(MenuToggleSelectionMode))
|
if ((this->m_originalSelectionMode == MultiSelection || this->m_originalSelectionMode == ExtendedSelection) && this->m_menus.testFlag(MenuToggleSelectionMode))
|
||||||
{
|
{
|
||||||
if (sm == SingleSelection)
|
if (sm != MultiSelection)
|
||||||
{
|
{
|
||||||
QAction *a = menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
|
QAction *a = menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
|
||||||
a->setData("multi");
|
a->setData(MultiSelection);
|
||||||
a = menu.addAction(QIcon(), "Switch to extended selection", this, SLOT(ps_toggleSelectionMode()));
|
|
||||||
a->setData("extended");
|
|
||||||
}
|
}
|
||||||
else if (sm == MultiSelection || sm == ExtendedSelection)
|
|
||||||
|
if (sm != ExtendedSelection)
|
||||||
|
{
|
||||||
|
QAction *a = menu.addAction(QIcon(), "Switch to extended selection", this, SLOT(ps_toggleSelectionMode()));
|
||||||
|
a->setData(ExtendedSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sm != SingleSelection)
|
||||||
{
|
{
|
||||||
QAction *a = menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode()));
|
QAction *a = menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode()));
|
||||||
a->setData("single");
|
a->setData(SingleSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sm != NoSelection)
|
if (sm != NoSelection)
|
||||||
@@ -319,7 +325,7 @@ namespace BlackGui
|
|||||||
return this->selectionModel()->selectedRows();
|
return this->selectionModel()->selectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CViewBaseNonTemplate::selectedRowsCount() const
|
int CViewBaseNonTemplate::selectedRowCount() const
|
||||||
{
|
{
|
||||||
if (!this->hasSelection()) { return 0;}
|
if (!this->hasSelection()) { return 0;}
|
||||||
return this->selectedRows().count();
|
return this->selectedRows().count();
|
||||||
@@ -327,12 +333,12 @@ namespace BlackGui
|
|||||||
|
|
||||||
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
||||||
{
|
{
|
||||||
return this->selectedRowsCount() == 1;
|
return this->selectedRowCount() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CViewBaseNonTemplate::hasMultipleSelectedRows() const
|
bool CViewBaseNonTemplate::hasMultipleSelectedRows() const
|
||||||
{
|
{
|
||||||
return this->selectedRowsCount() > 1;
|
return this->selectedRowCount() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::init()
|
void CViewBaseNonTemplate::init()
|
||||||
@@ -534,36 +540,18 @@ namespace BlackGui
|
|||||||
void CViewBaseNonTemplate::ps_toggleSelectionMode()
|
void CViewBaseNonTemplate::ps_toggleSelectionMode()
|
||||||
{
|
{
|
||||||
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||||
{
|
|
||||||
if (this->selectionMode() == SingleSelection)
|
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
if (action && action->data().canConvert<QString>())
|
if (action && action->data().isValid() && action->data().canConvert<int>())
|
||||||
{
|
{
|
||||||
QString data(action->data().toString().toLower());
|
SelectionMode sm = static_cast<SelectionMode>(action->data().toInt());
|
||||||
if (data.startsWith('e'))
|
this->setSelectionMode(sm);
|
||||||
{
|
|
||||||
this->setSelectionMode(ExtendedSelection);
|
|
||||||
}
|
|
||||||
else if (data.startsWith('m'))
|
|
||||||
{
|
|
||||||
this->setSelectionMode(MultiSelection);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->setSelectionMode(this->m_originalSelectionMode);
|
this->setSelectionMode(this->m_originalSelectionMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
this->setSelectionMode(this->m_originalSelectionMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this->selectionMode() == MultiSelection || this->selectionMode() == ExtendedSelection)
|
|
||||||
{
|
|
||||||
this->setSelectionMode(SingleSelection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CViewBaseNonTemplate::ps_removeSelectedRows()
|
void CViewBaseNonTemplate::ps_removeSelectedRows()
|
||||||
@@ -700,6 +688,14 @@ namespace BlackGui
|
|||||||
if (resize) { this->performModeBasedResizeToContent(); }
|
if (resize) { this->performModeBasedResizeToContent(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
|
void CViewBase<ModelClass, ContainerType, ObjectType>::insert(const ContainerType &container, bool resize)
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->m_model);
|
||||||
|
this->m_model->insert(container);
|
||||||
|
if (resize) { this->performModeBasedResizeToContent(); }
|
||||||
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType>
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
const ObjectType &CViewBase<ModelClass, ContainerType, ObjectType>::at(const QModelIndex &index) const
|
const ObjectType &CViewBase<ModelClass, ContainerType, ObjectType>::at(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
@@ -777,7 +773,7 @@ namespace BlackGui
|
|||||||
if (this->isEmpty()) { return 0; }
|
if (this->isEmpty()) { return 0; }
|
||||||
|
|
||||||
int currentRows = this->rowCount();
|
int currentRows = this->rowCount();
|
||||||
if (currentRows == selectedRowsCount())
|
if (currentRows == selectedRowCount())
|
||||||
{
|
{
|
||||||
this->clear();
|
this->clear();
|
||||||
return currentRows;
|
return currentRows;
|
||||||
@@ -972,6 +968,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// takes the filter and triggers the filtering
|
||||||
IModelFilterProvider<ContainerType> *provider = dynamic_cast<IModelFilterProvider<ContainerType>*>(this->m_filterWidget);
|
IModelFilterProvider<ContainerType> *provider = dynamic_cast<IModelFilterProvider<ContainerType>*>(this->m_filterWidget);
|
||||||
Q_ASSERT_X(provider, Q_FUNC_INFO, "Filter widget does not provide interface");
|
Q_ASSERT_X(provider, Q_FUNC_INFO, "Filter widget does not provide interface");
|
||||||
if (!provider) { return false; }
|
if (!provider) { return false; }
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace BlackGui
|
|||||||
QModelIndexList selectedRows() const;
|
QModelIndexList selectedRows() const;
|
||||||
|
|
||||||
//! Number of selected rows
|
//! Number of selected rows
|
||||||
int selectedRowsCount() const;
|
int selectedRowCount() const;
|
||||||
|
|
||||||
//! Single selected row
|
//! Single selected row
|
||||||
bool hasSingleSelectedRow() const;
|
bool hasSingleSelectedRow() const;
|
||||||
@@ -155,8 +155,11 @@ namespace BlackGui
|
|||||||
//! Filter dialog
|
//! Filter dialog
|
||||||
void setFilterDialog(BlackGui::Filters::CFilterDialog *filterDialog);
|
void setFilterDialog(BlackGui::Filters::CFilterDialog *filterDialog);
|
||||||
|
|
||||||
|
//! Filter widget if any
|
||||||
|
QWidget *getFilterWidget() const { return m_filterWidget; }
|
||||||
|
|
||||||
//! Set filter widget
|
//! Set filter widget
|
||||||
void setFilterWidget(BlackGui::Filters::CFilterWidget *filterDialog);
|
void setFilterWidget(BlackGui::Filters::CFilterWidget *filterWidget);
|
||||||
|
|
||||||
//! Set custom menu if applicable
|
//! Set custom menu if applicable
|
||||||
void setCustomMenu(BlackGui::IMenuDelegate *menu, bool nestPreviousMenu = true);
|
void setCustomMenu(BlackGui::IMenuDelegate *menu, bool nestPreviousMenu = true);
|
||||||
@@ -244,6 +247,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 CViewBaseNonTemplate::ps_customMenuRequested
|
||||||
virtual void customMenu(QMenu &menu) const;
|
virtual void customMenu(QMenu &menu) const;
|
||||||
|
|
||||||
//! \copydoc QTableView::paintEvent
|
//! \copydoc QTableView::paintEvent
|
||||||
@@ -302,7 +306,7 @@ namespace BlackGui
|
|||||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||||
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
||||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
QWidget *m_filterWidget = nullptr; //!< filter widget or dialog
|
||||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
BlackGui::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 neeeded
|
||||||
@@ -371,6 +375,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! Set the filter widget internally
|
//! Set the filter widget internally
|
||||||
|
//! \remarks used for dialog and filter widget
|
||||||
void setFilterWidgetImpl(QWidget *filterWidget);
|
void setFilterWidgetImpl(QWidget *filterWidget);
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackGui::Views::CViewBaseNonTemplate::Menu)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackGui::Views::CViewBaseNonTemplate::Menu)
|
||||||
@@ -407,6 +412,9 @@ namespace BlackGui
|
|||||||
//! Insert
|
//! Insert
|
||||||
void insert(const ObjectType &value, bool resize = true);
|
void insert(const ObjectType &value, bool resize = true);
|
||||||
|
|
||||||
|
//! Insert
|
||||||
|
void insert(const ContainerType &container, bool resize = true);
|
||||||
|
|
||||||
//! Value object at
|
//! Value object at
|
||||||
const ObjectType &at(const QModelIndex &index) const;
|
const ObjectType &at(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user