Skip to content

Commit

Permalink
Avoid recursively updating item preview with display commands
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 23, 2024
1 parent df487eb commit 9f7c98c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) );
Expand Down
11 changes: 8 additions & 3 deletions src/item/itemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/item/itemdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9f7c98c

Please sign in to comment.