mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 05:28:09 +08:00
refs #641, improvements/fixes of orderable lists / models / views
* set sort order automatically to IndexOrder when changing order of items * call onChanged when model is changed and then update view (needed when model is changed directly, not via view) * support for digest signal so redundant updates can be avoided * renamed rowCountChanged (signal) to modelDataChanged - detecting row count changes only was useless * updated Doxygen / fixed typos
This commit is contained in:
@@ -178,7 +178,14 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
|
||||
// moves from myself are ignored
|
||||
// depends on isDropAllowed() / acceptDrop() if this function is called
|
||||
Qt::DropAction action = event->dropAction();
|
||||
if (action == Qt::MoveAction)
|
||||
{
|
||||
COrderableViewWithDbObjects::dropEvent(event);
|
||||
return;
|
||||
}
|
||||
if (!this->isDropAllowed()) { return; }
|
||||
if (!event) { return; }
|
||||
const QMimeData *mime = event->mimeData();
|
||||
|
||||
@@ -106,6 +106,7 @@ namespace BlackGui
|
||||
|
||||
protected:
|
||||
//! \copydoc QTableView::dropEvent
|
||||
//! \sa BlackGui::Models::CListModelBase::dropMimeData
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
//! \name View base class overrides
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace BlackGui
|
||||
{
|
||||
bool s = connect(filterWidget, &CFilterWidget::changeFilter, this, &CViewBaseNonTemplate::ps_filterWidgetChangedFilter);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "filter connect");
|
||||
s = connect(this, &CViewBaseNonTemplate::rowCountChanged, filterWidget, &CFilterWidget::onRowCountChanged);
|
||||
s = connect(this, &CViewBaseNonTemplate::modelDataChanged, filterWidget, &CFilterWidget::onRowCountChanged);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "filter connect");
|
||||
Q_UNUSED(s);
|
||||
}
|
||||
@@ -437,6 +437,11 @@ namespace BlackGui
|
||||
this->ps_saveJson();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::onModelChanged()
|
||||
{
|
||||
this->updateSortIndicator();
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::rowsResizeModeToInteractive()
|
||||
{
|
||||
const int height = this->verticalHeader()->minimumSectionSize();
|
||||
@@ -625,7 +630,7 @@ namespace BlackGui
|
||||
this->setSortingEnabled(true);
|
||||
if (model)
|
||||
{
|
||||
this->setModel(this->m_model);
|
||||
this->standardInit(model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,7 +664,7 @@ namespace BlackGui
|
||||
this->fullResizeToContents();
|
||||
}
|
||||
}
|
||||
int c = this->m_model->update(container, sort);
|
||||
const int c = this->m_model->update(container, sort);
|
||||
|
||||
// resize after real update according to mode
|
||||
if (presizeThresholdReached)
|
||||
@@ -675,6 +680,7 @@ namespace BlackGui
|
||||
// small amount of data not covered before
|
||||
this->fullResizeToContents();
|
||||
}
|
||||
this->updateSortIndicator(); // make sure sort indicator represents sort order
|
||||
this->hideLoadIndicator();
|
||||
return c;
|
||||
}
|
||||
@@ -804,7 +810,7 @@ namespace BlackGui
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
this->derivedModel()->sendDataChanged(firstUpdatedRow, lastUpdatedRow);
|
||||
this->derivedModel()->emitDataChanged(firstUpdatedRow, lastUpdatedRow);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@@ -1008,10 +1014,22 @@ namespace BlackGui
|
||||
Q_ASSERT_X(model || this->m_model, Q_FUNC_INFO, "Missing model");
|
||||
if (model)
|
||||
{
|
||||
if (model == this->m_model) { return; }
|
||||
if (this->m_model)
|
||||
{
|
||||
this->m_model->disconnect();
|
||||
}
|
||||
|
||||
this->m_model = model;
|
||||
connect(this->m_model, &ModelClass::rowCountChanged, this, &CViewBase::rowCountChanged);
|
||||
connect(this->m_model, &ModelClass::objectChanged, this, &CViewBase::objectChanged);
|
||||
connect(this->m_model, &ModelClass::changed, this, &CViewBase::modelChanged);
|
||||
bool c = connect(this->m_model, &ModelClass::modelDataChanged, this, &CViewBase::modelDataChanged);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
c = connect(this->m_model, &ModelClass::objectChanged, this, &CViewBase::objectChanged);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
c = connect(this->m_model, &ModelClass::changed, this, &CViewBase::modelChanged);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
c = connect(this->m_model, &ModelClass::changed, this, &CViewBase::onModelChanged);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
|
||||
this->setModel(this->m_model); // via QTableView
|
||||
@@ -1047,6 +1065,17 @@ namespace BlackGui
|
||||
return this->updateContainer(c, sort, resize);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::updateSortIndicator()
|
||||
{
|
||||
if (this->derivedModel()->hasValidSortColumn())
|
||||
{
|
||||
const int index = this->derivedModel()->getSortColumn();
|
||||
Qt::SortOrder order = this->derivedModel()->getSortOrder();
|
||||
this->horizontalHeader()->setSortIndicator(index, order);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::modifyLoadedJsonData(ContainerType &data) const
|
||||
{
|
||||
|
||||
@@ -228,8 +228,8 @@ namespace BlackGui
|
||||
//! Asynchronous update finished
|
||||
void asyncUpdateFinished();
|
||||
|
||||
//! Number of elements changed
|
||||
void rowCountChanged(int count, bool withFilter);
|
||||
//! Model data changed
|
||||
void modelDataChanged(int count, bool withFilter);
|
||||
|
||||
//! Model bas been changed (means data in view have been changed)
|
||||
void modelChanged();
|
||||
@@ -270,6 +270,9 @@ namespace BlackGui
|
||||
//! \param processEvents force event processing to display indicator by updating GUI
|
||||
void showLoadIndicator(int containerSizeDependent = -1, bool processEvents = true);
|
||||
|
||||
//! Underlying model changed
|
||||
void onModelChanged();
|
||||
|
||||
//! Hide loading indicator
|
||||
void hideLoadIndicator();
|
||||
|
||||
@@ -324,6 +327,9 @@ namespace BlackGui
|
||||
//! Init menu actions
|
||||
BlackGui::Menus::CMenuActions initMenuActions(MenuFlag menu);
|
||||
|
||||
//! Set the sort indicator to the current sort column
|
||||
virtual void updateSortIndicator() = 0;
|
||||
|
||||
QString m_saveFileName; //!< save file name (JSON)
|
||||
ResizeMode m_resizeMode = PresizeSubset; //!< mode
|
||||
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
||||
@@ -533,7 +539,7 @@ namespace BlackGui
|
||||
//! Add the object and container type as accepted drop types CDropBase::addAcceptedMetaTypeId
|
||||
void addContainerTypesAsDropTypes(bool objectType = true, bool containerType = true);
|
||||
|
||||
//! Init so items can be ordered
|
||||
//! Init so items can be ordered, includes enabling drag and drop
|
||||
void initAsOrderable();
|
||||
|
||||
//! Drop actions
|
||||
@@ -556,6 +562,7 @@ namespace BlackGui
|
||||
virtual bool reachedResizeThreshold(int containrerSize = -1) const override;
|
||||
virtual void performModeBasedResizeToContent() override;
|
||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) override;
|
||||
virtual void updateSortIndicator() override;
|
||||
//! @}
|
||||
|
||||
//! Modify JSON data loaded in BlackGui::Views::CViewBaseNonTemplate::ps_loadJson
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace BlackGui
|
||||
virtual void ps_toggleHighlightDbData() override;
|
||||
};
|
||||
|
||||
//! Base class for views with DB objects
|
||||
//! Base class for views with DB objects also orderable (based on BlackMisc::IOrderableList )
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType> class COrderableViewWithDbObjects :
|
||||
public CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user