Skip to content

Commit

Permalink
GSvar: added context menu to tab bar
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-sturm committed Jan 20, 2025
1 parent 64c6a35 commit 55e6561
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
64 changes: 38 additions & 26 deletions src/GSvar/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ MainWindow::MainWindow(QWidget *parent)
ui_.splitter_2->setStretchFactor(0, 10);
ui_.splitter_2->setStretchFactor(1, 1);
connect(ui_.tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
connect(ui_.tabs, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(tabContextMenu(QPoint)));

// add rna menu
rna_menu_btn_ = new QToolButton();
Expand Down Expand Up @@ -2368,10 +2369,7 @@ void MainWindow::openProcessedSampleTab(QString ps_name)
connect(widget, SIGNAL(clearMainTableSomReport(QString)), this, SLOT(clearSomaticReportSettings(QString)));
connect(widget, SIGNAL(addModelessDialog(QSharedPointer<QDialog>, bool)), this, SLOT(addModelessDialog(QSharedPointer<QDialog>, bool)));
int index = openTab(QIcon(":/Icons/NGSD_sample.png"), ps_name, type, widget);
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + ps_id);
}
ui_.tabs->tabBar()->setTabData(index, ps_id);
}
catch (Exception& e)
{
Expand All @@ -2398,10 +2396,7 @@ void MainWindow::openRunTab(QString run_name)
SequencingRunWidget* widget = new SequencingRunWidget(this, run_id);
connect(widget, SIGNAL(addModelessDialog(QSharedPointer<QDialog>, bool)), this, SLOT(addModelessDialog(QSharedPointer<QDialog>, bool)));
int index = openTab(QIcon(":/Icons/NGSD_run.png"), run_name, type, widget);
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + run_id);
}
ui_.tabs->tabBar()->setTabData(index, run_id);
}

void MainWindow::openGeneTab(QString symbol)
Expand All @@ -2418,10 +2413,7 @@ void MainWindow::openGeneTab(QString symbol)

GeneWidget* widget = new GeneWidget(this, symbol.toUtf8());
int index = openTab(QIcon(":/Icons/NGSD_gene.png"), symbol, type, widget);
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + QString::number(NGSD().geneId(symbol.toUtf8())));
}
ui_.tabs->tabBar()->setTabData(index, QString::number(NGSD().geneId(symbol.toUtf8())));
}

void MainWindow::openVariantTab(Variant variant)
Expand All @@ -2439,12 +2431,7 @@ void MainWindow::openVariantTab(Variant variant)
//open tab
VariantWidget* widget = new VariantWidget(variant, this);
int index = openTab(QIcon(":/Icons/NGSD_variant.png"), name, type, widget);

//add database id
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + v_id);
}
ui_.tabs->tabBar()->setTabData(index, v_id);
}
catch(Exception& e)
{
Expand All @@ -2468,10 +2455,7 @@ void MainWindow::openProcessingSystemTab(QString system_name)

ProcessingSystemWidget* widget = new ProcessingSystemWidget(this, sys_id);
int index = openTab(QIcon(":/Icons/NGSD_processing_system.png"), name, type, widget);
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + QString::number(sys_id));
}
ui_.tabs->tabBar()->setTabData(index, QString::number(sys_id));
}

void MainWindow::openProjectTab(QString name)
Expand All @@ -2481,10 +2465,7 @@ void MainWindow::openProjectTab(QString name)

ProjectWidget* widget = new ProjectWidget(this, name);
int index = openTab(QIcon(":/Icons/NGSD_project.png"), name, type, widget);
if (Settings::boolean("debug_mode_enabled"))
{
ui_.tabs->setTabToolTip(index, "NGSD ID: " + NGSD().getValue("SELECT id FROM project WHERE name=:0", true, name).toString());
}
ui_.tabs->tabBar()->setTabData(index, NGSD().getValue("SELECT id FROM project WHERE name=:0", true, name).toString());
}

int MainWindow::openTab(QIcon icon, QString name, TabType type, QWidget* widget)
Expand Down Expand Up @@ -2552,6 +2533,37 @@ bool MainWindow::focusTab(TabType type, QString name)
return false;
}

void MainWindow::tabContextMenu(QPoint pos)
{
int index = ui_.tabs->tabBar()->tabAt(pos);
QString data = ui_.tabs->tabBar()->tabData(index).toString();

// create menu
QMenu menu(ui_.tabs);
QAction* a_copy_text = menu.addAction("Copy text");
a_copy_text->setEnabled(index!=-1);
QAction* a_copy_id = menu.addAction("Copy NGSD id");
a_copy_id->setEnabled(index!=-1 && !data.isEmpty());

// execute menu
QAction* action = menu.exec(ui_.tabs->mapToGlobal(pos));
if (action == nullptr) return;

// execute
if (action==a_copy_text)
{
QApplication::clipboard()->setText(ui_.tabs->tabText(index));
}
else if (action==a_copy_id)
{
QApplication::clipboard()->setText(data);
}
else
{
THROW(ProgrammingException, "Invalid menu action in context menu selected!")
}
}

void MainWindow::on_actionChangeLog_triggered()
{
QDesktopServices::openUrl(QUrl("https://github.com/imgag/ngs-bits/tree/master/doc/GSvar/changelog.md"));
Expand Down
2 changes: 2 additions & 0 deletions src/GSvar/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ public slots:
void closeTab(int index);
///Focus tab based on type and name. Returns if a tab was found and focused.
bool focusTab(TabType type, QString name);
///Show context menu of tab
void tabContextMenu(QPoint pos);

///Edits the variant configuration for the variant with the given index
void editVariantReportConfiguration(int index);
Expand Down
3 changes: 3 additions & 0 deletions src/GSvar/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
</property>
<item>
<widget class="QTabWidget" name="tabs">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
Expand Down
2 changes: 1 addition & 1 deletion src/cppNGSD/NGSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3842,7 +3842,7 @@ const TableInfo& NGSD::tableInfo(const QString& table, bool use_cache) const
if (table=="processing_system" && info.name=="adapter2_p7") info.type_constraints.regexp = QRegularExpression("^[ACGTN]*$");
if (table=="processed_sample" && info.name=="lane") info.type_constraints.regexp = QRegularExpression("^[1-8](,[1-8])*$");
if (table=="user" && info.name=="user_id") info.type_constraints.regexp = QRegularExpression("^[A-Za-z0-9_]+$");
if (table=="study" && info.name=="name") info.type_constraints.regexp = QRegularExpression("^[A-Za-z0-9_ -]+$");
if (table=="study" && info.name=="name") info.type_constraints.regexp = QRegularExpression("^[A-Za-z0-9_ -\\.]+$");
}
else
{
Expand Down

0 comments on commit 55e6561

Please sign in to comment.