From f8774540f2189f79fcbce4b76c3c839b88d641e6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 2 Aug 2014 22:19:55 +0200 Subject: [PATCH] Some refactoring for model base / view base * update by int index (row) * updateContainer renaming --- src/blackgui/components/aircraftcomponent.cpp | 4 ++-- src/blackgui/components/atcstationcomponent.cpp | 4 ++-- src/blackgui/components/cockpitv1component.cpp | 6 +++--- src/blackgui/components/settingscomponent.cpp | 4 ++-- src/blackgui/components/usercomponent.cpp | 4 ++-- src/blackgui/models/listmodelbase.h | 6 ++++++ src/blackgui/views/viewbase.h | 11 +++++++++-- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index 91fbdb823..656655567 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -35,11 +35,11 @@ namespace BlackGui if (this->getIContextNetwork()->isConnected()) { - this->ui->tvp_AircraftsInRange->update(this->getIContextNetwork()->getAircraftsInRange()); + this->ui->tvp_AircraftsInRange->updateContainer(this->getIContextNetwork()->getAircraftsInRange()); } if (this->getIContextSimulator()->isConnected()) { - this->ui->tvp_AirportsInRange->update(this->getIContextSimulator()->getAirportsInRange()); + this->ui->tvp_AirportsInRange->updateContainer(this->getIContextSimulator()->getAirportsInRange()); } } } diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 8d6662f6a..a7ec968ea 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -72,7 +72,7 @@ namespace BlackGui if (this->m_timestampOnlineStationsChanged.isNull() || this->m_timestampLastReadOnlineStations.isNull() || (this->m_timestampOnlineStationsChanged > this->m_timestampLastReadOnlineStations)) { - this->ui->tvp_AtcStationsOnline->update(this->getIContextNetwork()->getAtcStationsOnline()); + this->ui->tvp_AtcStationsOnline->updateContainer(this->getIContextNetwork()->getAtcStationsOnline()); this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc(); this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations; } @@ -97,7 +97,7 @@ namespace BlackGui } else { - this->ui->tvp_AtcStationsBooked->update(this->getIContextNetwork()->getAtcStationsBooked()); + this->ui->tvp_AtcStationsBooked->updateContainer(this->getIContextNetwork()->getAtcStationsBooked()); this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc(); } } diff --git a/src/blackgui/components/cockpitv1component.cpp b/src/blackgui/components/cockpitv1component.cpp index 05ad7df56..c75536b81 100644 --- a/src/blackgui/components/cockpitv1component.cpp +++ b/src/blackgui/components/cockpitv1component.cpp @@ -341,7 +341,7 @@ namespace BlackGui if (room1.isConnected()) { this->ui->le_CockpitVoiceRoomCom1->setStyleSheet("background: green"); - if (this->getIContextAudio()) this->ui->tvp_CockpitVoiceRoom1->update(this->getIContextAudio()->getCom1RoomUsers()); + if (this->getIContextAudio()) this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getCom1RoomUsers()); } else { @@ -379,12 +379,12 @@ namespace BlackGui { if (!this->getIContextAudio()) return; if (!this->ui->le_CockpitVoiceRoomCom1->text().trimmed().isEmpty()) - this->ui->tvp_CockpitVoiceRoom1->update(this->getIContextAudio()->getCom1RoomUsers()); + this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getCom1RoomUsers()); else this->ui->tvp_CockpitVoiceRoom1->clear(); if (!this->ui->le_CockpitVoiceRoomCom2->text().trimmed().isEmpty()) - this->ui->tvp_CockpitVoiceRoom2->update(this->getIContextAudio()->getCom2RoomUsers()); + this->ui->tvp_CockpitVoiceRoom2->updateContainer(this->getIContextAudio()->getCom2RoomUsers()); else this->ui->tvp_CockpitVoiceRoom2->clear(); } diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index 45665f28f..ce54ec428 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -106,10 +106,10 @@ namespace BlackGui // update servers this->ui->tvp_SettingsTnServers->setSelectedServer(nws.getCurrentTrafficNetworkServer()); - this->ui->tvp_SettingsTnServers->update(nws.getTrafficNetworkServers()); + this->ui->tvp_SettingsTnServers->updateContainer(nws.getTrafficNetworkServers()); // update hot keys - this->ui->tvp_SettingsMiscHotkeys->update(this->getIContextSettings()->getHotkeys()); + this->ui->tvp_SettingsMiscHotkeys->updateContainer(this->getIContextSettings()->getHotkeys()); // fake setting for sound notifications this->ui->cb_SettingsAudioPlayNotificationSounds->setChecked(true); diff --git a/src/blackgui/components/usercomponent.cpp b/src/blackgui/components/usercomponent.cpp index 0ef325eec..1f2a4df50 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -34,8 +34,8 @@ namespace BlackGui if (this->getIContextNetwork()->isConnected()) { - this->ui->tvp_Clients->update(this->getIContextNetwork()->getOtherClients()); - this->ui->tvp_AllUsers->update(this->getIContextNetwork()->getUsers()); + this->ui->tvp_Clients->updateContainer(this->getIContextNetwork()->getOtherClients()); + this->ui->tvp_AllUsers->updateContainer(this->getIContextNetwork()->getUsers()); } } } diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h index 67f8e999a..90476b894 100644 --- a/src/blackgui/models/listmodelbase.h +++ b/src/blackgui/models/listmodelbase.h @@ -126,6 +126,12 @@ namespace BlackGui //! Update single element virtual void update(const QModelIndex &index, const ObjectType &object); + //! Update single element + virtual void update(int rowIndex, const ObjectType &object) + { + this->update(this->index(rowIndex), object); + } + //! Object at row position virtual const ObjectType &at(const QModelIndex &index) const { diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 62202739b..696ddc79e 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -47,8 +47,8 @@ namespace BlackGui //! Clear void clear() { Q_ASSERT(this->m_model); this->m_model->clear(); } - //! Update - template int update(const ContainerType &container, bool resize = true) + //! Update whole container + template int updateContainer(const ContainerType &container, bool resize = true) { Q_ASSERT(this->m_model); int c = this->m_model->update(container); @@ -82,6 +82,13 @@ namespace BlackGui return this->m_model->rowCount(); } + //! Column count + int columnCount() const + { + Q_ASSERT(this->m_model); + return this->m_model->columnCount(); + } + //! Any data? bool isEmpty() const {