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