Skip to content

Commit

Permalink
Merge pull request #2254 from SCIInstitute/2241-table-copy
Browse files Browse the repository at this point in the history
Address #2241 - Ability to copy table values from difference to predicted scalar table in 'samples' table of Analysis
  • Loading branch information
akenmorris committed May 16, 2024
2 parents cb0e08f + 1a1a35c commit d847e72
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
48 changes: 46 additions & 2 deletions Studio/Analysis/AnalysisTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <jkqtplotter/jkqtplotter.h>
#include <ui_AnalysisTool.h>

#include <QClipboard>
#include <QMenu>

#include "ParticleAreaPanel.h"
#include "ShapeScalarPanel.h"

Expand Down Expand Up @@ -80,8 +83,6 @@ AnalysisTool::AnalysisTool(Preferences& prefs) : preferences_(prefs) {
ui_->tabWidget->tabBar()->setElideMode(Qt::TextElideMode::ElideNone);
#endif

stats_ready_ = false;

connect(ui_->view_header, &QPushButton::clicked, ui_->view_open_button, &QPushButton::toggle);
connect(ui_->metrics_header, &QPushButton::clicked, ui_->metrics_open_button, &QPushButton::toggle);
connect(ui_->surface_header, &QPushButton::clicked, ui_->surface_open_button, &QPushButton::toggle);
Expand Down Expand Up @@ -179,6 +180,14 @@ AnalysisTool::AnalysisTool(Preferences& prefs) : preferences_(prefs) {
&AnalysisTool::handle_samples_predicted_scalar_options);
connect(ui_->show_absolute_difference, &QPushButton::clicked, this,
&AnalysisTool::handle_samples_predicted_scalar_options);

// add a right click menu to the samples table allowing the user to copy the table to the clipboard
ui_->samples_table->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui_->samples_table, &QTableWidget::customContextMenuRequested, this,
&AnalysisTool::samples_table_context_menu);

// disable editing of the table
ui_->samples_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -1890,6 +1899,41 @@ void AnalysisTool::handle_samples_predicted_scalar_options() {
Q_EMIT update_view();
}

//---------------------------------------------------------------------------
void AnalysisTool::samples_table_context_menu() {
QMenu menu;
QAction* action = menu.addAction("Copy to Clipboard");
connect(action, &QAction::triggered, this, &AnalysisTool::samples_table_copy_to_clipboard);
menu.exec(QCursor::pos());
}

//---------------------------------------------------------------------------
void AnalysisTool::samples_table_copy_to_clipboard() {
QTableWidget* table = ui_->samples_table;
QString text;
// start with headers
for (int i = 0; i < table->columnCount(); i++) {
text += table->horizontalHeaderItem(i)->text();
if (i < table->columnCount() - 1) {
text += ",";
}
}
text += "\n";
for (int i = 0; i < table->rowCount(); i++) {
for (int j = 0; j < table->columnCount(); j++) {
auto item = table->item(i, j);
if (item) {
text += item->text();
}
if (j < table->columnCount() - 1) {
text += ",";
}
}
text += "\n";
}
QApplication::clipboard()->setText(text);
}

//---------------------------------------------------------------------------
void AnalysisTool::reconstruction_method_changed() {
ui_->reconstruction_options->setVisible(ui_->distance_transform_radio_button->isChecked());
Expand Down
3 changes: 3 additions & 0 deletions Studio/Analysis/AnalysisTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class AnalysisTool : public QWidget {

void handle_samples_predicted_scalar_options();

void samples_table_context_menu();
void samples_table_copy_to_clipboard();

Q_SIGNALS:

void update_view();
Expand Down

0 comments on commit d847e72

Please sign in to comment.