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:
Klaus Basan
2016-05-05 12:24:22 +02:00
parent 2da14e3b62
commit 1a62de8dc3
21 changed files with 175 additions and 62 deletions

View File

@@ -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
{