mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:30:06 +00:00
add more handling to ensure that MarkerModel stays up to date with MarkerManager
This commit is contained in:
parent
aabf4fcbb0
commit
aec937aa97
4 changed files with 38 additions and 0 deletions
|
|
@ -181,6 +181,8 @@ MarkerManager::MarkerManager() : p(std::make_unique<Impl>(this))
|
|||
// Read Marker settings on startup
|
||||
main::Application::WaitForInitialization();
|
||||
p->ReadMarkerSettings();
|
||||
|
||||
Q_EMIT MarkersInitialized(p->markerRecords_.size());
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
|
|
@ -219,6 +221,7 @@ void MarkerManager::set_marker(size_t index, const types::MarkerInfo& marker)
|
|||
std::shared_ptr<MarkerManager::Impl::MarkerRecord>& markerRecord =
|
||||
p->markerRecords_[index];
|
||||
markerRecord->markerInfo_ = marker;
|
||||
Q_EMIT MarkerChanged(index);
|
||||
Q_EMIT MarkersUpdated();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ public:
|
|||
static std::shared_ptr<MarkerManager> Instance();
|
||||
|
||||
signals:
|
||||
void MarkersInitialized(size_t count);
|
||||
void MarkersUpdated();
|
||||
void MarkerChanged(size_t index);
|
||||
void MarkerAdded();
|
||||
void MarkerRemoved(size_t index);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,11 +38,22 @@ public:
|
|||
MarkerModel::MarkerModel(QObject* parent) :
|
||||
QAbstractTableModel(parent), p(std::make_unique<Impl>())
|
||||
{
|
||||
|
||||
connect(p->markerManager_.get(),
|
||||
&manager::MarkerManager::MarkersInitialized,
|
||||
this,
|
||||
&MarkerModel::HandleMarkersInitialized);
|
||||
|
||||
connect(p->markerManager_.get(),
|
||||
&manager::MarkerManager::MarkerAdded,
|
||||
this,
|
||||
&MarkerModel::HandleMarkerAdded);
|
||||
|
||||
connect(p->markerManager_.get(),
|
||||
&manager::MarkerManager::MarkerChanged,
|
||||
this,
|
||||
&MarkerModel::HandleMarkerChanged);
|
||||
|
||||
connect(p->markerManager_.get(),
|
||||
&manager::MarkerManager::MarkerRemoved,
|
||||
this,
|
||||
|
|
@ -235,6 +246,17 @@ bool MarkerModel::setData(const QModelIndex& index,
|
|||
return result;
|
||||
}
|
||||
|
||||
void MarkerModel::HandleMarkersInitialized(size_t count)
|
||||
{
|
||||
QModelIndex topLeft = createIndex(0, kFirstColumn);
|
||||
QModelIndex bottomRight = createIndex(count - 1, kLastColumn);
|
||||
|
||||
beginInsertRows(QModelIndex(), 0, count - 1);
|
||||
endInsertRows();
|
||||
|
||||
Q_EMIT dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
void MarkerModel::HandleMarkerAdded()
|
||||
{
|
||||
const int newIndex = static_cast<int>(p->markerManager_->marker_count() - 1);
|
||||
|
|
@ -247,6 +269,15 @@ void MarkerModel::HandleMarkerAdded()
|
|||
Q_EMIT dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
void MarkerModel::HandleMarkerChanged(size_t index)
|
||||
{
|
||||
const int changedIndex = static_cast<int>(index);
|
||||
QModelIndex topLeft = createIndex(changedIndex, kFirstColumn);
|
||||
QModelIndex bottomRight = createIndex(changedIndex, kLastColumn);
|
||||
|
||||
Q_EMIT dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
void MarkerModel::HandleMarkerRemoved(size_t index)
|
||||
{
|
||||
const int removedIndex = static_cast<int>(index);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ public:
|
|||
|
||||
|
||||
public slots:
|
||||
void HandleMarkersInitialized(size_t count);
|
||||
void HandleMarkerAdded();
|
||||
void HandleMarkerChanged(size_t index);
|
||||
void HandleMarkerRemoved(size_t index);
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue