From f9d30bcdea72e4860361d8ab350282703dc3bfcf Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Wed, 1 Aug 2018 03:26:27 +0100 Subject: gui: lock arch when accessing/building treemodel --- gui/designwidget.cc | 15 +++++++++++++-- gui/treemodel.cc | 8 +++++++- gui/treemodel.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gui/designwidget.cc b/gui/designwidget.cc index c75991eb..34e358ae 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -215,7 +215,11 @@ void DesignWidget::newContext(Context *ctx) highlightSelected.clear(); this->ctx = ctx; - treeModel->loadContext(ctx); + { + std::lock_guard lock_ui(ctx->ui_mutex); + std::lock_guard lock(ctx->mutex); + treeModel->loadContext(ctx); + } updateTree(); } @@ -235,7 +239,11 @@ void DesignWidget::updateTree() } } - treeModel->updateCellsNets(ctx); + { + std::lock_guard lock_ui(ctx->ui_mutex); + std::lock_guard lock(ctx->mutex); + treeModel->updateCellsNets(ctx); + } } QtProperty *DesignWidget::addTopLevelProperty(const QString &id) { @@ -735,6 +743,9 @@ void DesignWidget::onSearchInserted() if (currentIndex >= currentSearchIndexes.size()) currentIndex = 0; } else { + std::lock_guard lock_ui(ctx->ui_mutex); + std::lock_guard lock(ctx->mutex); + currentSearch = searchEdit->text(); currentSearchIndexes = treeModel->search(searchEdit->text()); currentIndex = 0; diff --git a/gui/treemodel.cc b/gui/treemodel.cc index 4fc3d4f5..bf7d81a3 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -146,6 +146,7 @@ void Model::loadContext(Context *ctx) { if (!ctx) return; + ctx_ = ctx; beginResetModel(); @@ -273,6 +274,12 @@ Qt::ItemFlags Model::flags(const QModelIndex &index) const void Model::fetchMore(const QModelIndex &parent) { + if (ctx_ == nullptr) + return; + + std::lock_guard lock_ui(ctx_->ui_mutex); + std::lock_guard lock(ctx_->mutex); + nodeFromIndex(parent)->fetchMore(); } @@ -284,7 +291,6 @@ bool Model::canFetchMore(const QModelIndex &parent) const QList Model::search(QString text) { const int limit = 500; - QList list; cell_root_->search(list, text, limit); net_root_->search(list, text, limit); diff --git a/gui/treemodel.h b/gui/treemodel.h index 15370658..1d25dde4 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -355,6 +355,9 @@ class ElementXYRoot : public Item class Model : public QAbstractItemModel { + private: + Context *ctx_ = nullptr; + public: using BelXYRoot = ElementXYRoot; using WireXYRoot = ElementXYRoot; -- cgit v1.2.3