mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +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:
@@ -40,10 +40,10 @@ namespace BlackGui
|
||||
this->ui->tvp_AircraftInRange->setAircraftMode(CSimulatedAircraftListModel::InfoMode);
|
||||
this->ui->tvp_AircraftInRange->configureMenu(true, false, false);
|
||||
|
||||
connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::modelDataChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget);
|
||||
connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestHighlightInSimulator, this, &CAircraftComponent::ps_onMenuHighlightInSimulator);
|
||||
connect(this->ui->tvp_AirportsInRange, &CSimulatedAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AirportsInRange, &CSimulatedAircraftView::modelDataChanged, this, &CAircraftComponent::ps_onRowCountChanged);
|
||||
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::ps_connectionStatusChanged);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,14 +61,14 @@ namespace BlackGui
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::modelDataChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::modelDataChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::ps_setComFrequency);
|
||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget);
|
||||
|
||||
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
|
||||
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
|
||||
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::modelDataChanged, this, &CAtcStationComponent::ps_onCountChanged);
|
||||
|
||||
connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
|
||||
|
||||
|
||||
@@ -68,17 +68,17 @@ namespace BlackGui
|
||||
connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel);
|
||||
|
||||
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
|
||||
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged);
|
||||
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged);
|
||||
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels);
|
||||
connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
|
||||
|
||||
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
|
||||
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
|
||||
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
|
||||
connect(ui->comp_StashAircraft->view(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest);
|
||||
connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelsChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged);
|
||||
connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished);
|
||||
|
||||
connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged);
|
||||
connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged);
|
||||
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged);
|
||||
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged);
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace BlackGui
|
||||
{
|
||||
this->m_vPilot1stInit = false;
|
||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
|
||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged);
|
||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged);
|
||||
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
|
||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels);
|
||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
|
||||
@@ -466,6 +466,11 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_onStashedModelsChanged()
|
||||
{
|
||||
emit this->ps_digestStashedModelsChanged();
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_onStashedModelsChangedDigest()
|
||||
{
|
||||
const bool hlvp = this->ui->tvp_AircraftModelsForVPilot->derivedModel()->highlightModelStrings();
|
||||
const bool hlom = this->ui->comp_OwnAircraftModels->view()->derivedModel()->highlightModelStrings();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
#include "blackmisc/network/entityflags.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/digestsignal.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
|
||||
@@ -164,6 +165,9 @@ namespace BlackGui
|
||||
//! Tab index has been changed
|
||||
void tabIndexChanged(int index);
|
||||
|
||||
//! \private Just needed to trigger CDbMappingComponent::ps_onStashedModelsChangedDigest
|
||||
void ps_digestStashedModelsChanged();
|
||||
|
||||
private slots:
|
||||
//! Load the vPilot rules
|
||||
void ps_loadVPilotData();
|
||||
@@ -180,6 +184,9 @@ namespace BlackGui
|
||||
//! Stashed models changed
|
||||
void ps_onStashedModelsChanged();
|
||||
|
||||
//! Stashed models changed
|
||||
void ps_onStashedModelsChangedDigest();
|
||||
|
||||
//! Tab index changed
|
||||
void ps_tabIndexChanged(int index);
|
||||
|
||||
@@ -243,10 +250,12 @@ namespace BlackGui
|
||||
QScopedPointer<CDbModelMappingModifyComponent> m_modelModifyDialog; //!< dialog when modifying models
|
||||
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
||||
BlackMisc::CData<BlackCore::Data::AuthenticatedDbUser> m_swiftDbUser {this, &CDbMappingComponent::ps_userChanged};
|
||||
bool m_vPilot1stInit = true;
|
||||
bool m_withVPilot = false;
|
||||
BlackMisc::CDigestSignal m_dsStashedModelsChanged { this, &CDbMappingComponent::ps_digestStashedModelsChanged, &CDbMappingComponent::ps_onStashedModelsChangedDigest, 750, 25 };
|
||||
bool m_vPilot1stInit = true; //!< vPilot extensions initaliazed?
|
||||
bool m_withVPilot = false; //!< use vPilot extensions
|
||||
bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model
|
||||
|
||||
|
||||
//! Init vPilot if rights and suitable
|
||||
void initVPilotLoading();
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace BlackGui
|
||||
connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
|
||||
connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
|
||||
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::rowCountChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_modelChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace BlackGui
|
||||
connect(this->ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::ps_onValidatePressed);
|
||||
connect(this->ui->pb_Publish, &QPushButton::pressed, this, &CDbStashComponent::ps_onPublishPressed);
|
||||
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged, this, &CDbStashComponent::stashedModelsChanged);
|
||||
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbStashComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelDataChanged, this, &CDbStashComponent::ps_onRowCountChanged);
|
||||
|
||||
// copy over buttons
|
||||
connect(this->ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected);
|
||||
|
||||
@@ -51,11 +51,11 @@ namespace BlackGui
|
||||
this->ui->tvp_SimulatedAircraft->setResizeMode(CAircraftModelView::ResizingOnce);
|
||||
|
||||
connect(this->ui->tvp_AircraftModels, &CAircraftModelView::requestUpdate, this, &CMappingComponent::ps_onModelsUpdateRequested);
|
||||
connect(this->ui->tvp_AircraftModels, &CAircraftModelView::rowCountChanged, this, &CMappingComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AircraftModels, &CAircraftModelView::modelDataChanged, this, &CMappingComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_AircraftModels, &CAircraftModelView::clicked, this, &CMappingComponent::ps_onModelSelectedInView);
|
||||
connect(this->ui->tvp_AircraftModels, &CAircraftModelView::requestNewBackendData, this, &CMappingComponent::ps_onMenuRequestModelReload);
|
||||
|
||||
connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::rowCountChanged, this, &CMappingComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::modelDataChanged, this, &CMappingComponent::ps_onRowCountChanged);
|
||||
connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::clicked, this, &CMappingComponent::ps_onAircraftSelectedInView);
|
||||
connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestUpdate, this, &CMappingComponent::ps_onSimulatedAircraftUpdateRequested);
|
||||
connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestTextMessageWidget, this, &CMappingComponent::requestTextMessageWidget);
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace BlackGui
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->tabBar()->setExpanding(false);
|
||||
connect(this->ui->tvp_AllUsers, &CUserView::rowCountChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_Clients, &CClientView::rowCountChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_AllUsers, &CUserView::modelDataChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
connect(this->ui->tvp_Clients, &CClientView::modelDataChanged, this, &CUserComponent::ps_onCountChanged);
|
||||
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CUserComponent::ps_connectionStatusChanged);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace BlackGui
|
||||
Q_ASSERT_X(!this->m_acceptedMetaTypes.isEmpty(), Q_FUNC_INFO, "no accepted meta type ids");
|
||||
if (m_acceptedMetaTypes.isEmpty()) { return false; }
|
||||
if (!m_allowDrop || !CGuiUtility::hasSwiftVariantMimeType(mime)) { return false; }
|
||||
int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
|
||||
const int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
|
||||
if (metaTypeId == QMetaType::UnknownType) { return false; }
|
||||
bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
||||
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
||||
return accept;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,19 +157,19 @@ namespace BlackGui
|
||||
return m_modelDestroyed;
|
||||
}
|
||||
|
||||
void CListModelBaseNonTemplate::sendDataChanged(int startRowIndex, int endRowIndex)
|
||||
void CListModelBaseNonTemplate::emitDataChanged(int startRowIndex, int endRowIndex)
|
||||
{
|
||||
BLACK_VERIFY_X(startRowIndex <= endRowIndex, Q_FUNC_INFO, "check rows");
|
||||
BLACK_VERIFY_X(startRowIndex >= 0 && endRowIndex >= 0, Q_FUNC_INFO, "check rows");
|
||||
|
||||
int columns = columnCount();
|
||||
int rows = rowCount();
|
||||
const int columns = columnCount();
|
||||
const int rows = rowCount();
|
||||
if (columns < 1) { return; }
|
||||
if (startRowIndex < 0) { startRowIndex = 0; }
|
||||
if (endRowIndex >= rows) { endRowIndex = rows - 1; }
|
||||
const QModelIndex topLeft(createIndex(startRowIndex, 0));
|
||||
const QModelIndex bottomRight(createIndex(endRowIndex, columns - 1));
|
||||
emit dataChanged(topLeft, bottomRight);
|
||||
emit this->dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
int CListModelBaseNonTemplate::ps_updateContainer(const CVariant &variant, bool sort)
|
||||
@@ -182,6 +182,9 @@ namespace BlackGui
|
||||
{
|
||||
// non unique default name, set translation context as default
|
||||
this->setObjectName(translationContext);
|
||||
|
||||
// connect
|
||||
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::ps_onDataChanged);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -288,7 +291,7 @@ namespace BlackGui
|
||||
this->m_container[index.row()] = obj;
|
||||
const CVariant co = CVariant::from(obj);
|
||||
emit objectChanged(co, propertyIndex);
|
||||
emit dataChanged(topLeft, bottomRight);
|
||||
emit this->dataChanged(topLeft, bottomRight);
|
||||
this->updateFilteredContainer();
|
||||
return true;
|
||||
}
|
||||
@@ -326,9 +329,9 @@ namespace BlackGui
|
||||
this->endResetModel();
|
||||
|
||||
int newSize = this->m_container.size();
|
||||
// I have to update with same size because cannot tell what data are changed
|
||||
this->emitRowCountChanged();
|
||||
Q_UNUSED(oldSize);
|
||||
// I have to update even with same size because I cannot tell what/if data are changed
|
||||
this->emitModelDataChanged();
|
||||
return newSize;
|
||||
}
|
||||
|
||||
@@ -400,7 +403,7 @@ namespace BlackGui
|
||||
this->beginResetModel();
|
||||
this->updateFilteredContainer();
|
||||
this->endResetModel();
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -417,7 +420,7 @@ namespace BlackGui
|
||||
this->beginResetModel();
|
||||
this->updateFilteredContainer();
|
||||
this->endResetModel();
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -453,7 +456,7 @@ namespace BlackGui
|
||||
this->m_container.push_back(object);
|
||||
endInsertRows();
|
||||
this->updateFilteredContainer();
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -469,7 +472,7 @@ namespace BlackGui
|
||||
this->updateFilteredContainer();
|
||||
this->endResetModel();
|
||||
}
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -486,7 +489,7 @@ namespace BlackGui
|
||||
this->updateFilteredContainer();
|
||||
this->endResetModel();
|
||||
}
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -499,7 +502,7 @@ namespace BlackGui
|
||||
int newSize = this->m_container.size();
|
||||
if (oldSize != newSize)
|
||||
{
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
if (this->hasFilter())
|
||||
{
|
||||
this->beginResetModel();
|
||||
@@ -516,7 +519,7 @@ namespace BlackGui
|
||||
this->m_container.clear();
|
||||
this->m_containerFiltered.clear();
|
||||
endResetModel();
|
||||
this->emitRowCountChanged();
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -559,13 +562,31 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitRowCountChanged()
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::emitModelDataChanged()
|
||||
{
|
||||
int n = this->containerOrFilteredContainer().size();
|
||||
emit this->rowCountChanged(n, this->hasFilter());
|
||||
const int n = this->containerOrFilteredContainer().size();
|
||||
emit this->modelDataChanged(n, this->hasFilter());
|
||||
emit this->changed();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
// underlying base class changed
|
||||
Q_UNUSED(topLeft);
|
||||
Q_UNUSED(bottomRight);
|
||||
Q_UNUSED(roles);
|
||||
this->emitModelDataChanged();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::ps_onChangedDigest()
|
||||
{
|
||||
const int n = this->containerOrFilteredContainer().size();
|
||||
emit this->changedDigest();
|
||||
emit this->modelDataChangedDigest(n, this->hasFilter());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::moveItems(const ContainerType &items, int position)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackgui/dropbase.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/digestsignal.h"
|
||||
#include <QStandardItemModel>
|
||||
#include <QThread>
|
||||
#include <memory>
|
||||
@@ -98,7 +99,7 @@ namespace BlackGui
|
||||
|
||||
//! Send signal that data have been changed.
|
||||
//! \note Meant for scenarios where the container is directly updated and a subsequent signal is required
|
||||
void sendDataChanged(int startRowIndex, int endRowIndex);
|
||||
void emitDataChanged(int startRowIndex, int endRowIndex);
|
||||
|
||||
//! Convert to JSON
|
||||
virtual QJsonObject toJson() const = 0;
|
||||
@@ -110,12 +111,18 @@ namespace BlackGui
|
||||
//! Asynchronous update finished
|
||||
void asyncUpdateFinished();
|
||||
|
||||
//! Number of elements changed
|
||||
void rowCountChanged(int count, bool withFilter);
|
||||
//! Data changed
|
||||
void modelDataChanged(int count, bool withFilter);
|
||||
|
||||
//! Data changed, digest version
|
||||
void modelDataChangedDigest(int count, bool withFilter);
|
||||
|
||||
//! Model has been changed
|
||||
void changed();
|
||||
|
||||
//! Model has been changed, digest signal
|
||||
void changedDigest();
|
||||
|
||||
//! Template free information, that object changed
|
||||
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
||||
|
||||
@@ -125,6 +132,12 @@ namespace BlackGui
|
||||
//! \param sort
|
||||
int ps_updateContainer(const BlackMisc::CVariant &variant, bool sort);
|
||||
|
||||
//! Feedback when QStandardItemModel::dataChanged was called
|
||||
virtual void ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) = 0;
|
||||
|
||||
//! Digest signal
|
||||
virtual void ps_onChangedDigest() = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
//! \param translationContext I18N context
|
||||
@@ -136,9 +149,12 @@ namespace BlackGui
|
||||
|
||||
CColumns m_columns; //!< columns metadata
|
||||
int m_sortedColumn; //!< current sort column
|
||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||
bool m_modelDestroyed = false; //!< model is about to be destroyed
|
||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||
|
||||
private:
|
||||
BlackMisc::CDigestSignal m_dsModelsChanged { this, &CListModelBaseNonTemplate::changed, &CListModelBaseNonTemplate::ps_onChangedDigest, 500, 10 };
|
||||
};
|
||||
|
||||
//! List model
|
||||
@@ -196,7 +212,8 @@ namespace BlackGui
|
||||
//! Update single element
|
||||
virtual void update(int rowIndex, const ObjectType &object);
|
||||
|
||||
//! Move items to position
|
||||
//! Move items to position, normally called from dropMimeData
|
||||
//! \sa dropMimeData
|
||||
virtual void moveItems(const ContainerType &items, int position);
|
||||
|
||||
//! Object at row position
|
||||
@@ -233,7 +250,7 @@ namespace BlackGui
|
||||
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
|
||||
{
|
||||
int c = m_container.removeIf(BlackMisc::Predicates::MemberEqual(k0, v0, keysValues...));
|
||||
if (c > 0) { this->emitRowCountChanged();}
|
||||
if (c > 0) { this->emitModelDataChanged();}
|
||||
this->updateFilteredContainer();
|
||||
return c;
|
||||
}
|
||||
@@ -257,14 +274,18 @@ namespace BlackGui
|
||||
//! Constructor
|
||||
CListModelBase(const QString &translationContext, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::performUpdateContainer
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) override;
|
||||
virtual void ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector<int> &roles) override;
|
||||
virtual void ps_onChangedDigest() override;
|
||||
//! @}
|
||||
|
||||
//! Update filtered container
|
||||
void updateFilteredContainer();
|
||||
|
||||
//! Row count changed
|
||||
void emitRowCountChanged();
|
||||
void emitModelDataChanged();
|
||||
|
||||
std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter
|
||||
ContainerType m_container; //!< used container
|
||||
|
||||
@@ -72,10 +72,20 @@ namespace BlackGui
|
||||
{
|
||||
order = container[position].getOrder();
|
||||
}
|
||||
this->setSortColumnToOrder();
|
||||
container.moveTo(items, order);
|
||||
|
||||
// update container
|
||||
this->updateContainerMaybeAsync(container);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
void COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::setSortColumnToOrder()
|
||||
{
|
||||
// force sorted by order, otherwise display looks confusing
|
||||
this->setSorting(IOrderable::IndexOrder);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, typename KeyType, bool UseCompare>
|
||||
int COrderableListModelDbObjects<ObjectType, ContainerType, KeyType, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,9 @@ namespace BlackGui
|
||||
virtual void moveItems(const ContainerType &items, int position) override;
|
||||
//! @}
|
||||
|
||||
//! Sort order to order property BlackMisc::IOrderable::IndexOrder
|
||||
void setSortColumnToOrder();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
COrderableListModelDbObjects(const QString &translationContext, QObject *parent = nullptr);
|
||||
|
||||
@@ -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