mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #614, allow to resize view by presize algorithm
This commit is contained in:
@@ -94,6 +94,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CViewBaseNonTemplate::setFilterDialog(CFilterDialog *filterDialog)
|
||||
{
|
||||
this->setFilterWidgetImpl(filterDialog);
|
||||
@@ -250,7 +251,7 @@ namespace BlackGui
|
||||
if (menu.actions().size() > items) { menu.addSeparator(); }
|
||||
|
||||
// resizing
|
||||
menu.addAction(BlackMisc::CIcons::resize16(), "Full resize", this, &CViewBaseNonTemplate::fullResizeToContents);
|
||||
menu.addAction(BlackMisc::CIcons::resize16(), "Resize", this, &CViewBaseNonTemplate::presizeOrFullResizeToContents);
|
||||
|
||||
// resize to content might decrease performance,
|
||||
// so I only allow changing to "content resizing" if size matches
|
||||
@@ -535,6 +536,11 @@ namespace BlackGui
|
||||
this->setVisible(true);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::presizeOrFullResizeToContents()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::ps_customMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu;
|
||||
@@ -650,7 +656,7 @@ namespace BlackGui
|
||||
// when we will not resize, we might presize
|
||||
if (presizeThresholdReached)
|
||||
{
|
||||
const int presizeRandomElements = container.size() > 1000 ? container.size() / 100 : container.size() / 40;
|
||||
const int presizeRandomElements = this->getPresizeRandomElementsSize(container.size());
|
||||
if (presizeRandomElements > 0)
|
||||
{
|
||||
this->m_model->update(container.sampleElements(presizeRandomElements), false);
|
||||
@@ -677,6 +683,13 @@ namespace BlackGui
|
||||
return c;
|
||||
}
|
||||
|
||||
int CViewBaseNonTemplate::getPresizeRandomElementsSize(int containerSize) const
|
||||
{
|
||||
containerSize = containerSize >= 0 ? containerSize : this->rowCount();
|
||||
const int presizeRandomElements = containerSize > 1000 ? containerSize / 100 : containerSize / 40;
|
||||
return presizeRandomElements;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
BlackMisc::CWorker *CViewBase<ModelClass, ContainerType, ObjectType>::updateContainerAsync(const ContainerType &container, bool sort, bool resize)
|
||||
{
|
||||
@@ -839,6 +852,27 @@ namespace BlackGui
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::presizeOrFullResizeToContents()
|
||||
{
|
||||
const int rc = this->rowCount();
|
||||
if (rc > ResizeSubsetThreshold)
|
||||
{
|
||||
const int presizeRandomElements = this->getPresizeRandomElementsSize(rc);
|
||||
if (presizeRandomElements > 0)
|
||||
{
|
||||
const ContainerType containerBackup(this->container());
|
||||
this->m_model->update(containerBackup.sampleElements(presizeRandomElements), false);
|
||||
this->fullResizeToContents();
|
||||
this->m_model->update(containerBackup, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->fullResizeToContents();
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
int CViewBase<ModelClass, ContainerType, ObjectType>::rowCount() const
|
||||
{
|
||||
|
||||
@@ -118,6 +118,9 @@ namespace BlackGui
|
||||
//! \copydoc Components::CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea
|
||||
virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override;
|
||||
|
||||
//! Elements in container
|
||||
virtual int rowCount() const = 0;
|
||||
|
||||
//! Resize mode
|
||||
ResizeMode getResizeMode() const { return m_resizeMode; }
|
||||
|
||||
@@ -246,6 +249,9 @@ namespace BlackGui
|
||||
//! Full resizing to content, might be slow
|
||||
virtual void fullResizeToContents();
|
||||
|
||||
//! Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize
|
||||
virtual void presizeOrFullResizeToContents() = 0;
|
||||
|
||||
//! Init as interactive, as this allows manually resizing
|
||||
void rowsResizeModeToInteractive();
|
||||
|
||||
@@ -305,6 +311,9 @@ namespace BlackGui
|
||||
//! Resize or skip resize?
|
||||
virtual bool isResizeConditionMet(int containerSize = -1) const;
|
||||
|
||||
//! Calculate presize count
|
||||
int getPresizeRandomElementsSize(int containerSize = -1) const;
|
||||
|
||||
//! Center / re-center load indicator
|
||||
void centerLoadIndicator();
|
||||
|
||||
@@ -450,9 +459,11 @@ namespace BlackGui
|
||||
//! Selected objects
|
||||
ContainerType selectedObjects() const;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::removeSelectedRows
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
//! \name Slot overrides from base class
|
||||
//! @{
|
||||
virtual int removeSelectedRows() override;
|
||||
virtual void presizeOrFullResizeToContents() override;
|
||||
//! @}
|
||||
|
||||
//! Update selected objects
|
||||
int updateSelected(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
@@ -484,8 +495,8 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(copy);
|
||||
}
|
||||
|
||||
//! Row count
|
||||
int rowCount() const;
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::rowCount
|
||||
virtual int rowCount() const override;
|
||||
|
||||
//! Column count
|
||||
int columnCount() const;
|
||||
@@ -544,37 +555,17 @@ namespace BlackGui
|
||||
|
||||
// --------------------------------------------- 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
|
||||
//! \name Slot overrides from base class
|
||||
//! @{
|
||||
virtual bool ps_filterDialogFinished(int status) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_filterWidgetChangedFilter(bool)
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual bool ps_filterWidgetChangedFilter(bool enabled) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_removeFilter
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_removeFilter() override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_clicked
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_clicked(const QModelIndex &index) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_doubleClicked
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_doubleClicked(const QModelIndex &index) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_rowSelected
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_rowSelected(const QModelIndex &index) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_loadJson
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual BlackMisc::CStatusMessage ps_loadJson() override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_saveJson
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual BlackMisc::CStatusMessage ps_saveJson() const override;
|
||||
//! @}
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user