mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +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();
|
||||
}
|
||||
|
||||
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>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::remove(const ObjectType &object)
|
||||
{
|
||||
|
||||
@@ -213,6 +213,9 @@ namespace BlackGui
|
||||
//! Similar to ContainerType::insert here inserts at first position
|
||||
virtual void insert(const ObjectType &object);
|
||||
|
||||
//! Similar to ContainerType::insert here inserts at first position
|
||||
virtual void insert(const ContainerType &container);
|
||||
|
||||
//! Remove object
|
||||
virtual void remove(const ObjectType &object);
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace BlackGui
|
||||
|
||||
void CViewBaseNonTemplate::setFilterWidgetImpl(QWidget *filterWidget)
|
||||
{
|
||||
// dialog or filter widget
|
||||
if (this->m_filterWidget)
|
||||
{
|
||||
disconnect(this->m_filterWidget);
|
||||
@@ -191,8 +192,8 @@ namespace BlackGui
|
||||
items = menu.actions().size();
|
||||
if (this->m_menus.testFlag(MenuFilter))
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Filter", this, SLOT(ps_displayFilterDialog()), CShortcut::keyDisplayFilter());
|
||||
menu.addAction(BlackMisc::CIcons::tableSheet16(), "Remove Filter", this, SLOT(ps_removeFilter()));
|
||||
menu.addAction(CIcons::filter16(), "Filter", this, SLOT(ps_displayFilterDialog()), CShortcut::keyDisplayFilter());
|
||||
menu.addAction(CIcons::filter16(), "Remove Filter", this, SLOT(ps_removeFilter()));
|
||||
}
|
||||
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 (sm == SingleSelection)
|
||||
if (sm != MultiSelection)
|
||||
{
|
||||
QAction *a = menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
|
||||
a->setData("multi");
|
||||
a = menu.addAction(QIcon(), "Switch to extended selection", this, SLOT(ps_toggleSelectionMode()));
|
||||
a->setData("extended");
|
||||
a->setData(MultiSelection);
|
||||
}
|
||||
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()));
|
||||
a->setData("single");
|
||||
a->setData(SingleSelection);
|
||||
}
|
||||
}
|
||||
if (sm != NoSelection)
|
||||
@@ -319,7 +325,7 @@ namespace BlackGui
|
||||
return this->selectionModel()->selectedRows();
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::selectedRowsCount() const
|
||||
int CViewBaseNonTemplate::selectedRowCount() const
|
||||
{
|
||||
if (!this->hasSelection()) { return 0;}
|
||||
return this->selectedRows().count();
|
||||
@@ -327,12 +333,12 @@ namespace BlackGui
|
||||
|
||||
bool CViewBaseNonTemplate::hasSingleSelectedRow() const
|
||||
{
|
||||
return this->selectedRowsCount() == 1;
|
||||
return this->selectedRowCount() == 1;
|
||||
}
|
||||
|
||||
bool CViewBaseNonTemplate::hasMultipleSelectedRows() const
|
||||
{
|
||||
return this->selectedRowsCount() > 1;
|
||||
return this->selectedRowCount() > 1;
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::init()
|
||||
@@ -535,33 +541,15 @@ namespace BlackGui
|
||||
{
|
||||
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||
{
|
||||
if (this->selectionMode() == SingleSelection)
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (action && action->data().isValid() && action->data().canConvert<int>())
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (action && action->data().canConvert<QString>())
|
||||
{
|
||||
QString data(action->data().toString().toLower());
|
||||
if (data.startsWith('e'))
|
||||
{
|
||||
this->setSelectionMode(ExtendedSelection);
|
||||
}
|
||||
else if (data.startsWith('m'))
|
||||
{
|
||||
this->setSelectionMode(MultiSelection);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setSelectionMode(this->m_originalSelectionMode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setSelectionMode(this->m_originalSelectionMode);
|
||||
}
|
||||
SelectionMode sm = static_cast<SelectionMode>(action->data().toInt());
|
||||
this->setSelectionMode(sm);
|
||||
}
|
||||
else if (this->selectionMode() == MultiSelection || this->selectionMode() == ExtendedSelection)
|
||||
else
|
||||
{
|
||||
this->setSelectionMode(SingleSelection);
|
||||
this->setSelectionMode(this->m_originalSelectionMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -700,6 +688,14 @@ namespace BlackGui
|
||||
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>
|
||||
const ObjectType &CViewBase<ModelClass, ContainerType, ObjectType>::at(const QModelIndex &index) const
|
||||
{
|
||||
@@ -777,7 +773,7 @@ namespace BlackGui
|
||||
if (this->isEmpty()) { return 0; }
|
||||
|
||||
int currentRows = this->rowCount();
|
||||
if (currentRows == selectedRowsCount())
|
||||
if (currentRows == selectedRowCount())
|
||||
{
|
||||
this->clear();
|
||||
return currentRows;
|
||||
@@ -972,6 +968,7 @@ namespace BlackGui
|
||||
}
|
||||
else
|
||||
{
|
||||
// takes the filter and triggers the filtering
|
||||
IModelFilterProvider<ContainerType> *provider = dynamic_cast<IModelFilterProvider<ContainerType>*>(this->m_filterWidget);
|
||||
Q_ASSERT_X(provider, Q_FUNC_INFO, "Filter widget does not provide interface");
|
||||
if (!provider) { return false; }
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace BlackGui
|
||||
QModelIndexList selectedRows() const;
|
||||
|
||||
//! Number of selected rows
|
||||
int selectedRowsCount() const;
|
||||
int selectedRowCount() const;
|
||||
|
||||
//! Single selected row
|
||||
bool hasSingleSelectedRow() const;
|
||||
@@ -155,8 +155,11 @@ namespace BlackGui
|
||||
//! Filter dialog
|
||||
void setFilterDialog(BlackGui::Filters::CFilterDialog *filterDialog);
|
||||
|
||||
//! Filter widget if any
|
||||
QWidget *getFilterWidget() const { return m_filterWidget; }
|
||||
|
||||
//! Set filter widget
|
||||
void setFilterWidget(BlackGui::Filters::CFilterWidget *filterDialog);
|
||||
void setFilterWidget(BlackGui::Filters::CFilterWidget *filterWidget);
|
||||
|
||||
//! Set custom menu if applicable
|
||||
void setCustomMenu(BlackGui::IMenuDelegate *menu, bool nestPreviousMenu = true);
|
||||
@@ -244,6 +247,7 @@ namespace BlackGui
|
||||
|
||||
//! Method creating the menu
|
||||
//! \remarks override this method to contribute to the menu
|
||||
//! \sa CViewBaseNonTemplate::ps_customMenuRequested
|
||||
virtual void customMenu(QMenu &menu) const;
|
||||
|
||||
//! \copydoc QTableView::paintEvent
|
||||
@@ -288,24 +292,24 @@ namespace BlackGui
|
||||
//! Default file for load/save operations
|
||||
QString getDefaultFilename() const;
|
||||
|
||||
ResizeMode m_resizeMode = ResizingOnceSubset; //!< mode
|
||||
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
||||
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
|
||||
bool m_forceStretchLastColumnWhenResized = false; //!< a small table might (few columns) might to fail stretching, force again
|
||||
bool m_showingLoadIndicator = false; //!< showing loading indicator
|
||||
bool m_enabledLoadIndicator = true; //!< loading indicator enabled/disabled
|
||||
bool m_acceptClickSelection = false; //!< clicked
|
||||
bool m_acceptRowSelected = false; //!< selection changed
|
||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
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
|
||||
bool m_forceStretchLastColumnWhenResized = false; //!< a small table might (few columns) might to fail stretching, force again
|
||||
bool m_showingLoadIndicator = false; //!< showing loading indicator
|
||||
bool m_enabledLoadIndicator = true; //!< loading indicator enabled/disabled
|
||||
bool m_acceptClickSelection = false; //!< clicked
|
||||
bool m_acceptRowSelected = false; //!< selection changed
|
||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget or dialog
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
|
||||
protected slots:
|
||||
//! Helper method with template free signature serving as callback from threaded worker
|
||||
@@ -371,6 +375,7 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
//! Set the filter widget internally
|
||||
//! \remarks used for dialog and filter widget
|
||||
void setFilterWidgetImpl(QWidget *filterWidget);
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackGui::Views::CViewBaseNonTemplate::Menu)
|
||||
@@ -407,6 +412,9 @@ namespace BlackGui
|
||||
//! Insert
|
||||
void insert(const ObjectType &value, bool resize = true);
|
||||
|
||||
//! Insert
|
||||
void insert(const ContainerType &container, bool resize = true);
|
||||
|
||||
//! Value object at
|
||||
const ObjectType &at(const QModelIndex &index) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user