diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index f85eedbe5..bc718d69d 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -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); } diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 69c7134a4..9fb9ad394 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -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); diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index cbb386492..c26bd02cf 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -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(); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 456ef05bf..c7233e0c3 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -24,6 +24,7 @@ #include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/statusmessagelist.h" +#include "blackmisc/digestsignal.h" #include #include @@ -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 m_modelModifyDialog; //!< dialog when modifying models BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules BlackMisc::CData 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(); diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 93cd6b617..dc99804f5 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -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); diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index d0a2b1cfd..bf6f12192 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -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); diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 2743a8093..83852dc8f 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -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); diff --git a/src/blackgui/components/usercomponent.cpp b/src/blackgui/components/usercomponent.cpp index bccbdf23f..a4fbb20fc 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -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); } diff --git a/src/blackgui/dropbase.cpp b/src/blackgui/dropbase.cpp index 2980f67f9..ccf93adbf 100644 --- a/src/blackgui/dropbase.cpp +++ b/src/blackgui/dropbase.cpp @@ -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; } diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 7cfa054fc..c36b96ea0 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -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 @@ -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 @@ -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 @@ -469,7 +472,7 @@ namespace BlackGui this->updateFilteredContainer(); this->endResetModel(); } - this->emitRowCountChanged(); + this->emitModelDataChanged(); } template @@ -486,7 +489,7 @@ namespace BlackGui this->updateFilteredContainer(); this->endResetModel(); } - this->emitRowCountChanged(); + this->emitModelDataChanged(); } template @@ -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 @@ -559,13 +562,31 @@ namespace BlackGui } template - void CListModelBase::emitRowCountChanged() + void CListModelBase::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 + void CListModelBase::ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) + { + // underlying base class changed + Q_UNUSED(topLeft); + Q_UNUSED(bottomRight); + Q_UNUSED(roles); + this->emitModelDataChanged(); + } + + template + void CListModelBase::ps_onChangedDigest() + { + const int n = this->containerOrFilteredContainer().size(); + emit this->changedDigest(); + emit this->modelDataChangedDigest(n, this->hasFilter()); + } + template void CListModelBase::moveItems(const ContainerType &items, int position) { diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h index ec9ba8499..252eaf215 100644 --- a/src/blackgui/models/listmodelbase.h +++ b/src/blackgui/models/listmodelbase.h @@ -17,6 +17,7 @@ #include "blackgui/models/modelfilter.h" #include "blackgui/dropbase.h" #include "blackmisc/worker.h" +#include "blackmisc/digestsignal.h" #include #include #include @@ -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 &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 &roles) override; + virtual void ps_onChangedDigest() override; + //! @} //! Update filtered container void updateFilteredContainer(); //! Row count changed - void emitRowCountChanged(); + void emitModelDataChanged(); std::unique_ptr > m_filter; //!< Used filter ContainerType m_container; //!< used container diff --git a/src/blackgui/models/listmodeldbobjects.cpp b/src/blackgui/models/listmodeldbobjects.cpp index db24b23a6..b028dac98 100644 --- a/src/blackgui/models/listmodeldbobjects.cpp +++ b/src/blackgui/models/listmodeldbobjects.cpp @@ -72,10 +72,20 @@ namespace BlackGui { order = container[position].getOrder(); } + this->setSortColumnToOrder(); container.moveTo(items, order); + + // update container this->updateContainerMaybeAsync(container); } + template + void COrderableListModelDbObjects::setSortColumnToOrder() + { + // force sorted by order, otherwise display looks confusing + this->setSorting(IOrderable::IndexOrder); + } + template int COrderableListModelDbObjects::update(const ContainerType &container, bool sort) { diff --git a/src/blackgui/models/listmodeldbobjects.h b/src/blackgui/models/listmodeldbobjects.h index 5f1619dba..e17b57070 100644 --- a/src/blackgui/models/listmodeldbobjects.h +++ b/src/blackgui/models/listmodeldbobjects.h @@ -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); diff --git a/src/blackgui/views/aircraftmodelview.cpp b/src/blackgui/views/aircraftmodelview.cpp index 2488db211..a1d9f0ac8 100644 --- a/src/blackgui/views/aircraftmodelview.cpp +++ b/src/blackgui/views/aircraftmodelview.cpp @@ -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(); diff --git a/src/blackgui/views/aircraftmodelview.h b/src/blackgui/views/aircraftmodelview.h index 19346d3f3..81e2b9a83 100644 --- a/src/blackgui/views/aircraftmodelview.h +++ b/src/blackgui/views/aircraftmodelview.h @@ -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 diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 6243dd4d0..3f72f73a6 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -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 + void CViewBase::updateSortIndicator() + { + if (this->derivedModel()->hasValidSortColumn()) + { + const int index = this->derivedModel()->getSortColumn(); + Qt::SortOrder order = this->derivedModel()->getSortOrder(); + this->horizontalHeader()->setSortIndicator(index, order); + } + } + template CStatusMessage CViewBase::modifyLoadedJsonData(ContainerType &data) const { diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 77bbd31bc..fd913da67 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -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 diff --git a/src/blackgui/views/viewdbobjects.h b/src/blackgui/views/viewdbobjects.h index 049427b45..82cfe3ccd 100644 --- a/src/blackgui/views/viewdbobjects.h +++ b/src/blackgui/views/viewdbobjects.h @@ -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 COrderableViewWithDbObjects : public CViewWithDbObjects { diff --git a/src/blackmisc/digestsignal.h b/src/blackmisc/digestsignal.h index c040b4622..e854258e8 100644 --- a/src/blackmisc/digestsignal.h +++ b/src/blackmisc/digestsignal.h @@ -18,8 +18,7 @@ namespace BlackMisc { - - //! Receive 1..n signal, collect them over time, and resend afer n milliseconds + //! Receive 1..n signals, collect them over time, and resend afer n milliseconds class BLACKMISC_EXPORT CDigestSignal : public QObject { Q_OBJECT diff --git a/src/blackmisc/orderablelist.h b/src/blackmisc/orderablelist.h index 1f5a0d541..3698c8110 100644 --- a/src/blackmisc/orderablelist.h +++ b/src/blackmisc/orderablelist.h @@ -18,6 +18,7 @@ namespace BlackMisc { //! List of orderable IOrderable objects + //! \remark Orerable objects shall implement BlackMisc::IOrderable template class IOrderableList { @@ -71,8 +72,8 @@ namespace BlackMisc extern template class BLACKMISC_EXPORT_TEMPLATE IOrderableList; extern template class BLACKMISC_EXPORT_TEMPLATE IOrderableList; - //! \endcond + } //namespace #endif //guard diff --git a/src/blackmisc/simulation/aircraftmodellist.h b/src/blackmisc/simulation/aircraftmodellist.h index db6efa280..f1121b5d9 100644 --- a/src/blackmisc/simulation/aircraftmodellist.h +++ b/src/blackmisc/simulation/aircraftmodellist.h @@ -26,9 +26,9 @@ namespace BlackMisc { //! Value object encapsulating a list of aircraft models class BLACKMISC_EXPORT CAircraftModelList : - public CSequence, - public IDatastoreObjectList, - public IOrderableList, + public BlackMisc::CSequence, + public BlackMisc::IDatastoreObjectList, + public BlackMisc::IOrderableList, public BlackMisc::Mixin::MetaType { public: