From 4e86cb6f4d3fddf282ed892850713ba554f015f0 Mon Sep 17 00:00:00 2001 From: DimDone Date: Fri, 26 Jul 2024 05:02:36 +0400 Subject: [PATCH] Added copy action to list of attributes --- src/admc/tabs/attributes_tab.cpp | 23 ++++++++++++++++++++++- src/admc/tabs/attributes_tab.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/admc/tabs/attributes_tab.cpp b/src/admc/tabs/attributes_tab.cpp index fbd59210..2b0e9250 100644 --- a/src/admc/tabs/attributes_tab.cpp +++ b/src/admc/tabs/attributes_tab.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include QString attribute_type_display_string(const AttributeType type); @@ -98,6 +100,8 @@ AttributesTabEdit::AttributesTabEdit(QTreeView *view_arg, QPushButton *filter_bu this, &AttributesTabEdit::update_edit_and_view_buttons); update_edit_and_view_buttons(); + view->installEventFilter(this); + connect( view, &QAbstractItemView::doubleClicked, this, &AttributesTabEdit::on_double_click); @@ -147,7 +151,6 @@ QList AttributesTabEdit::get_selected_row() const { void AttributesTabEdit::update_edit_and_view_buttons() { const QList selected_row = get_selected_row(); - const bool no_selection = selected_row.isEmpty(); if (no_selection) { edit_button->setVisible(true); @@ -175,6 +178,24 @@ void AttributesTabEdit::update_edit_and_view_buttons() { } } +void AttributesTabEdit::copy_action(){ + const QList selected_row = get_selected_row(); + QApplication::clipboard()->setText(selected_row[AttributesColumn_Value]->text()); +} + +bool AttributesTabEdit::eventFilter(QObject *watched, QEvent *event){ + if (watched == view && event->type() == 82){ + QMenu menu; + QAction* saveAction = menu.addAction("Копировать"); + connect( + saveAction, &QAction::triggered, + this, &AttributesTabEdit::copy_action); + menu.exec(QCursor::pos()); + return true; + } + return QObject::eventFilter(watched, event); +} + void AttributesTabEdit::on_double_click() { const QList selected_row = get_selected_row(); const QString attribute = selected_row[AttributesColumn_Name]->text(); diff --git a/src/admc/tabs/attributes_tab.h b/src/admc/tabs/attributes_tab.h index 2306a7d5..57c4aea8 100644 --- a/src/admc/tabs/attributes_tab.h +++ b/src/admc/tabs/attributes_tab.h @@ -90,6 +90,8 @@ private: void edit_attribute(); void view_attribute(); void on_load_optional(); + bool eventFilter(QObject *watched, QEvent *event); + void copy_action(); void load_optional_attribute_values(AdInterface &ad); void load_row(const QList &row, const QString &attribute, const QList &values); QList get_selected_row() const;