From 9f7c98cd653860bb7950c4ca2214aefbf43aa856 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Sat, 23 Nov 2024 11:17:59 +0100 Subject: [PATCH] Avoid recursively updating item preview with display commands --- src/gui/mainwindow.cpp | 1 + src/item/itemdelegate.cpp | 11 ++++++++--- src/item/itemdelegate.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 343288733d..73ed049a1d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -572,6 +572,7 @@ MainWindow::MainWindow(const ClipboardBrowserSharedPtr &sharedData, QWidget *par ui->dockWidgetItemPreview->setFocusProxy(ui->scrollAreaItemPreview); ui->dockWidgetItemPreview->hide(); + ui->scrollAreaItemPreview->viewport()->setObjectName("item_preview"); WindowGeometryGuard::create(this); restoreState( mainWindowState(objectName()) ); diff --git a/src/item/itemdelegate.cpp b/src/item/itemdelegate.cpp index 5e411988a3..9aa01d63ec 100644 --- a/src/item/itemdelegate.cpp +++ b/src/item/itemdelegate.cpp @@ -117,6 +117,13 @@ void ItemDelegate::rowsMoved(const QModelIndex &, int sourceStart, int sourceEnd } QWidget *ItemDelegate::createPreview(const QVariantMap &data, QWidget *parent) +{ + auto widget = createPreviewNoEmit(data, parent); + emit itemWidgetCreated(PersistentDisplayItem(this, data, widget)); + return widget; +} + +QWidget *ItemDelegate::createPreviewNoEmit(const QVariantMap &data, QWidget *parent) { const bool antialiasing = m_sharedData->theme.isAntialiasingEnabled(); ItemWidget *itemWidget = @@ -131,8 +138,6 @@ QWidget *ItemDelegate::createPreview(const QVariantMap &data, QWidget *parent) parent->setFocusProxy( itemWidget->widget() ); - emit itemWidgetCreated(PersistentDisplayItem(this, data, itemWidget->widget())); - return itemWidget->widget(); } @@ -173,7 +178,7 @@ void ItemDelegate::updateWidget(QObject *widget, const QVariantMap &data) if (!scrollArea) return; - auto newPreview = createPreview(data, scrollArea); + auto newPreview = createPreviewNoEmit(data, scrollArea); scrollArea->setWidget(newPreview); newPreview->show(); return; diff --git a/src/item/itemdelegate.h b/src/item/itemdelegate.h index 077eb3e510..74b9fb1b4e 100644 --- a/src/item/itemdelegate.h +++ b/src/item/itemdelegate.h @@ -127,6 +127,8 @@ class ItemDelegate final : public QItemDelegate QSize size = QSize(0, defaultItemHeight); }; + QWidget *createPreviewNoEmit(const QVariantMap &data, QWidget *parent); + void setIndexWidget(const QModelIndex &index, ItemWidget *w); /// Updates style for selected/unselected widgets.