gui: lock arch when accessing/building treemodel

This commit is contained in:
Sergiusz Bazanski 2018-08-01 03:26:27 +01:00
parent 9fb9eab6c9
commit f9d30bcdea
3 changed files with 23 additions and 3 deletions

View File

@ -215,7 +215,11 @@ void DesignWidget::newContext(Context *ctx)
highlightSelected.clear(); highlightSelected.clear();
this->ctx = ctx; this->ctx = ctx;
treeModel->loadContext(ctx); {
std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
std::lock_guard<std::mutex> lock(ctx->mutex);
treeModel->loadContext(ctx);
}
updateTree(); updateTree();
} }
@ -235,7 +239,11 @@ void DesignWidget::updateTree()
} }
} }
treeModel->updateCellsNets(ctx); {
std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
std::lock_guard<std::mutex> lock(ctx->mutex);
treeModel->updateCellsNets(ctx);
}
} }
QtProperty *DesignWidget::addTopLevelProperty(const QString &id) QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
{ {
@ -735,6 +743,9 @@ void DesignWidget::onSearchInserted()
if (currentIndex >= currentSearchIndexes.size()) if (currentIndex >= currentSearchIndexes.size())
currentIndex = 0; currentIndex = 0;
} else { } else {
std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
std::lock_guard<std::mutex> lock(ctx->mutex);
currentSearch = searchEdit->text(); currentSearch = searchEdit->text();
currentSearchIndexes = treeModel->search(searchEdit->text()); currentSearchIndexes = treeModel->search(searchEdit->text());
currentIndex = 0; currentIndex = 0;

View File

@ -146,6 +146,7 @@ void Model::loadContext(Context *ctx)
{ {
if (!ctx) if (!ctx)
return; return;
ctx_ = ctx;
beginResetModel(); beginResetModel();
@ -273,6 +274,12 @@ Qt::ItemFlags Model::flags(const QModelIndex &index) const
void Model::fetchMore(const QModelIndex &parent) void Model::fetchMore(const QModelIndex &parent)
{ {
if (ctx_ == nullptr)
return;
std::lock_guard<std::mutex> lock_ui(ctx_->ui_mutex);
std::lock_guard<std::mutex> lock(ctx_->mutex);
nodeFromIndex(parent)->fetchMore(); nodeFromIndex(parent)->fetchMore();
} }
@ -284,7 +291,6 @@ bool Model::canFetchMore(const QModelIndex &parent) const
QList<QModelIndex> Model::search(QString text) QList<QModelIndex> Model::search(QString text)
{ {
const int limit = 500; const int limit = 500;
QList<Item*> list; QList<Item*> list;
cell_root_->search(list, text, limit); cell_root_->search(list, text, limit);
net_root_->search(list, text, limit); net_root_->search(list, text, limit);

View File

@ -355,6 +355,9 @@ class ElementXYRoot : public Item
class Model : public QAbstractItemModel class Model : public QAbstractItemModel
{ {
private:
Context *ctx_ = nullptr;
public: public:
using BelXYRoot = ElementXYRoot<BelId>; using BelXYRoot = ElementXYRoot<BelId>;
using WireXYRoot = ElementXYRoot<WireId>; using WireXYRoot = ElementXYRoot<WireId>;