Skip to content

Commit

Permalink
clear selection upon window close
Browse files Browse the repository at this point in the history
  • Loading branch information
r3yc0n1c committed Apr 2, 2024
1 parent abb43ca commit 8aec5de
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,28 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)
selAllActionRightTreewidget->setShortcutContext(
Qt::ShortcutContext::WidgetWithChildrenShortcut);

// Connect Copy actions
connect(copyActionLeftTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->leftTreeWidget); });

connect(copyActionRightTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->rightTreeWidget); });

// Connect select sll actions
connect(selAllActionLeftTreewidget, &QAction::triggered, this,
[this]() { ui->leftTreeWidget->selectAll(); });

connect(selAllActionRightTreewidget, &QAction::triggered, this,
[this]() { ui->rightTreeWidget->selectAll(); });

// Connect selection handles
connect(ui->leftTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this,
[this]() { ui->rightTreeWidget->clearSelection(); });
connect(ui->rightTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this,
[this]() { ui->leftTreeWidget->clearSelection(); });
connect(this, &VersionInfoDialog::finished, this, &VersionInfoDialog::clearSelectionOnClose);

// Add actions to context menu
ui->leftTreeWidget->addAction(copyActionLeftTreewidget);
ui->leftTreeWidget->addAction(selAllActionLeftTreewidget);

Expand All @@ -61,6 +71,18 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

VersionInfoDialog::~VersionInfoDialog() {}

void VersionInfoDialog::clearSelectionOnClose()
{
ui->leftTreeWidget->clearSelection();
ui->rightTreeWidget->clearSelection();

// remove default "current" item selection after dialog close
auto model = ui->leftTreeWidget->model();
ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1));
model = ui->rightTreeWidget->model();
ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1));
}

void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
{
QString vinfo, row;
Expand All @@ -79,6 +101,27 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
clipboard->setText(vinfo.trimmed());
}

/*
void VersionInfoDialog::leftTreeWidgetItemSelectionChanged()
{
auto index = ui->leftTreeWidget->currentIndex();
if (!ui->leftTreeWidget->selectionModel()->hasSelection() || !index.isValid()) {
return;
}
ui->leftTreeWidget->clearSelection();
}
void VersionInfoDialog::rightTreeWidgetItemSelectionChanged()
{
auto index = ui->rightTreeWidget->currentIndex();
if (!ui->rightTreeWidget->selectionModel()->hasSelection() || !index.isValid()) {
return;
}
if (ui->rightTreeWidget->selectionModel()->hasSelection())
ui->rightTreeWidget->clearSelection();
}
*/

void VersionInfoDialog::fillVersionInfo()
{
RzCoreLocked core(Core());
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class VersionInfoDialog : public QDialog

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);
void clearSelectionOnClose();

protected:
QAction *copyActionLeftTreewidget = nullptr;
Expand Down

0 comments on commit 8aec5de

Please sign in to comment.