Skip to content

Commit

Permalink
plugins/TableView: Improve performance by removing useless processing
Browse files Browse the repository at this point in the history
Visible rows and columns of the table are already resized to their content
each time the table is painted so there is no need to do that processing
each time the underlying model changes.

This greatly improve performance when a large number of graph elements have
their properties modified, using a Python script for instance, as each table
row were resized to their content previoulsy.
  • Loading branch information
anlambert committed Nov 22, 2024
1 parent 6adb171 commit c112776
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
14 changes: 0 additions & 14 deletions plugins/view/TableView/TableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ void TableView::readSettings() {
sortModel->setSourceModel(_model);
_ui->table->setModel(sortModel);
connect(_model, &QAbstractItemModel::columnsInserted, this, &TableView::columnsInserted);
connect(_model, &QAbstractItemModel::dataChanged, this, &TableView::dataChanged);
filterChanged();
}

Expand All @@ -284,19 +283,6 @@ void TableView::readSettings() {
_ui->columnsFilterEdit->setText("");
}

void TableView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
auto *model = static_cast<QAbstractItemModel *>(sender());

for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
auto *pi = model->headerData(topLeft.column(), Qt::Horizontal, Model::PropertyRole)
.value<PropertyInterface *>();

if (pi->getTypename() == "string" && pi->getName() != "viewTexture" &&
pi->getName() != "viewFont")
_ui->table->resizeRowToContents(i);
}
}

void TableView::columnsInserted(const QModelIndex &, int start, int end) {
auto *model = static_cast<QAbstractItemModel *>(sender());

Expand Down
3 changes: 1 addition & 2 deletions plugins/view/TableView/TableView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2022 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand Down Expand Up @@ -83,7 +83,6 @@ protected slots:
void columnsInserted(const QModelIndex &, int, int);
void showCustomContextMenu(const QPoint &pos);
void showHorizontalHeaderCustomContextMenu(const QPoint &pos);
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void setZoomLevel(int);
};

Expand Down

0 comments on commit c112776

Please sign in to comment.