Skip to content

Commit

Permalink
Added batch scan options to ScanRegionDialog. Added ability to remove…
Browse files Browse the repository at this point in the history
… multiple scans at once
  • Loading branch information
Arthur Glowacki committed Dec 2, 2024
1 parent da38a6d commit 620f576
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 36 deletions.
47 changes: 33 additions & 14 deletions src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QMessageBox>
#include <QMenu>
#include <QTableWidget>
#include <QShortcut>
#include "core/defines.h"

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -45,7 +46,7 @@ void ScanQueueWidget::_createLayout()
_scan_queue_table_view = new QTableView();
_scan_queue_table_view->setModel(_scan_queue_table_model);
_scan_queue_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
_scan_queue_table_view->setSelectionMode(QAbstractItemView::SingleSelection);
_scan_queue_table_view->setSelectionMode(QAbstractItemView::ContiguousSelection);
_scan_queue_table_view->setDragEnabled(true);
_scan_queue_table_view->setAcceptDrops(true);
_scan_queue_table_view->setDragDropMode(QAbstractItemView::InternalMove);
Expand All @@ -58,6 +59,12 @@ void ScanQueueWidget::_createLayout()
&QTableView::customContextMenuRequested,
this,
&ScanQueueWidget::scanContextMenu);

QShortcut* del_shortcut = new QShortcut(QKeySequence(QKeySequence::Delete), _scan_queue_table_view);
connect(del_shortcut, &QShortcut::activated, this, &ScanQueueWidget::on_remove_scan);

QShortcut* backsp_shortcut = new QShortcut(QKeySequence(QKeySequence::Backspace), _scan_queue_table_view);
connect(backsp_shortcut, &QShortcut::activated, this, &ScanQueueWidget::on_remove_scan);
//_scan_queue_table_view->selectionModel()
// _scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);

Expand Down Expand Up @@ -93,10 +100,6 @@ void ScanQueueWidget::_createLayout()
_btn_add_scan = new QPushButton("Add Scan");
connect(_btn_add_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show);

_btn_add_batch_scan = new QPushButton("Add Batch Scan");
_btn_add_batch_scan->setEnabled(false);
connect(_btn_add_batch_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show);

_btn_set_history = new QPushButton("Set History Location");
connect(_btn_set_history, &QPushButton::pressed, this, &ScanQueueWidget::onSetHistory);

Expand Down Expand Up @@ -133,7 +136,6 @@ void ScanQueueWidget::_createLayout()
grid->addWidget(_btn_open_env,0,3);
grid->addWidget(_btn_close_env,0,4);
grid->addWidget(_btn_add_scan,0,6);
grid->addWidget(_btn_add_batch_scan,0,7);
grid->addWidget(_btn_set_history,0,8);
grid->addWidget(_btn_clear_history,0,9);
grid->addItem(new QSpacerItem(999,10), 0,10);
Expand Down Expand Up @@ -167,8 +169,12 @@ void ScanQueueWidget::scanContextMenu(const QPoint& pos)
QMenu menu(_scan_queue_table_view);
if (_scan_queue_table_view->selectionModel()->hasSelection())
{
menu.addAction(_move_scan_up);
menu.addAction(_move_scan_down);
auto selected = _scan_queue_table_view->selectionModel()->selectedIndexes();
if(selected.count() == 1)
{
menu.addAction(_move_scan_up);
menu.addAction(_move_scan_down);
}
menu.addAction(_remove_scan);

QAction* result = menu.exec(_scan_queue_table_view->viewport()->mapToGlobal(pos));
Expand All @@ -187,10 +193,13 @@ void ScanQueueWidget::on_move_scan_up()
if (_scan_queue_table_view->selectionModel()->hasSelection())
{
QModelIndexList selectedIndexes = _scan_queue_table_view->selectionModel()->selectedRows();
for (int i = selectedIndexes.count() - 1; i >= 0; i--)
if(selectedIndexes.count() == 1)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanUp(index.row() - _scan_queue_table_model->get_finished_idx());
for (int i = selectedIndexes.count() - 1; i >= 0; i--)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanUp(index.row() - _scan_queue_table_model->get_finished_idx());
}
}
}
}
Expand All @@ -202,10 +211,13 @@ void ScanQueueWidget::on_move_scan_down()
if (_scan_queue_table_view->selectionModel()->hasSelection())
{
QModelIndexList selectedIndexes = _scan_queue_table_view->selectionModel()->selectedRows();
for (int i = selectedIndexes.count() - 1; i >= 0; i--)
if(selectedIndexes.count() == 1)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanDown(index.row() - _scan_queue_table_model->get_finished_idx());
for (int i = selectedIndexes.count() - 1; i >= 0; i--)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanDown(index.row() - _scan_queue_table_model->get_finished_idx());
}
}
}
}
Expand Down Expand Up @@ -238,6 +250,13 @@ void ScanQueueWidget::on_remove_scan()

//---------------------------------------------------------------------------

void ScanQueueWidget::onQueueKeyPress(QKeyEvent* event)
{

}

//---------------------------------------------------------------------------

void ScanQueueWidget::updateQueuedItems(std::vector<BlueskyPlan> &finished_plans, std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan)
{
_scan_queue_table_model->setAllData(finished_plans, queued_plans, running_plan);
Expand Down
4 changes: 2 additions & 2 deletions src/mvc/ScanQueueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public slots:

void on_remove_scan();

void onQueueKeyPress(QKeyEvent*);

protected:

/**
Expand Down Expand Up @@ -105,8 +107,6 @@ public slots:

QPushButton* _btn_add_scan;

QPushButton* _btn_add_batch_scan;

QPushButton* _btn_set_history;

QPushButton* _btn_clear_history;
Expand Down
89 changes: 73 additions & 16 deletions src/mvc/ScanRegionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ void ScanRegionDialog::_createLayout()
_scan_options = new QTableView();
_scan_options->setModel(_scan_table_model);

_btn_update = new QPushButton("Update");
_chk_batch_scan = new QCheckBox("Set Batch Scan");
connect(_chk_batch_scan, &QCheckBox::checkStateChanged, this, &ScanRegionDialog::onBatchScanChanged);

_cb_batch_prop = new QComboBox();
_batch_start = new QLineEdit("Start Value");
_batch_end = new QLineEdit("End Value");
_batch_num = new QLineEdit("Number Iter");

_cb_batch_prop->setEnabled(false);
_batch_start->setEnabled(false);
_batch_end->setEnabled(false);
_batch_num->setEnabled(false);

_btn_update_and_queue = new QPushButton("Add To Queue");
_btn_cancel = new QPushButton("Cancel");
connect(_btn_update, &QPushButton::pressed, this, &ScanRegionDialog::onUpdate);
connect(_btn_update_and_queue, &QPushButton::pressed, this, &ScanRegionDialog::onUpdateAndQueue);
connect(_btn_cancel, &QPushButton::pressed, this, &ScanRegionDialog::close);

Expand All @@ -59,15 +70,22 @@ void ScanRegionDialog::_createLayout()
type_layout->addWidget(new QLabel("Scan Type: "));
type_layout->addWidget(_scan_type);

QHBoxLayout* batch_layout = new QHBoxLayout();
batch_layout->addWidget(_chk_batch_scan);
batch_layout->addWidget(_cb_batch_prop);
batch_layout->addWidget(_batch_start);
batch_layout->addWidget(_batch_end);
batch_layout->addWidget(_batch_num);


QHBoxLayout* button_layout = new QHBoxLayout();
button_layout->addWidget(_btn_update);
button_layout->addWidget(_btn_update_and_queue);
button_layout->addWidget(_btn_cancel);


main_layout->addItem(name_layout);
main_layout->addItem(type_layout);
main_layout->addWidget(_scan_options);
main_layout->addItem(batch_layout);
main_layout->addItem(button_layout);

setLayout(main_layout);
Expand Down Expand Up @@ -104,20 +122,31 @@ void ScanRegionDialog::updateProps(QList<gstar::AnnotationProperty*> &anno_list)

//---------------------------------------------------------------------------

void ScanRegionDialog::onUpdate()
{
//emit ScanUpdated();
close();
}

//---------------------------------------------------------------------------

void ScanRegionDialog::onUpdateAndQueue()
{
BlueskyPlan plan;
plan.type = _scan_type->currentText();
_scan_table_model->getCurrentParams(plan);
emit ScanUpdated(plan);
if(_chk_batch_scan->checkState() == Qt::Checked)
{
float start = _batch_start->text().toFloat();
float end = _batch_end->text().toFloat();
int num = _batch_num->text().toInt();
float inc = ( (end - start) + 1 )/ (float)num;
for(int i=0; i<num; i++)
{
BlueskyPlan plan;
plan.type = _scan_type->currentText();
_scan_table_model->getCurrentParams(plan);
plan.parameters[_cb_batch_prop->currentText()].default_val = QString::number(start);
emit ScanUpdated(plan);
start += inc;
}
}
else
{
BlueskyPlan plan;
plan.type = _scan_type->currentText();
_scan_table_model->getCurrentParams(plan);
emit ScanUpdated(plan);
}
close();
}

Expand All @@ -130,9 +159,37 @@ void ScanRegionDialog::scanChanged(const QString &scan_name)
if(_avail_scans->count(scan_name) > 0)
{
_scan_table_model->setAllData(_avail_scans->at(scan_name));
_cb_batch_prop->clear();
BlueskyPlan plan = _avail_scans->at(scan_name);
for(auto itr : plan.parameters)
{
_cb_batch_prop->addItem(itr.first);
}
}
}
}

//---------------------------------------------------------------------------

void ScanRegionDialog::onBatchScanChanged(Qt::CheckState state)
{

if(state == Qt::Checked)
{
_cb_batch_prop->setEnabled(true);
_batch_start->setEnabled(true);
_batch_end->setEnabled(true);
_batch_num->setEnabled(true);

}
else
{
_cb_batch_prop->setEnabled(false);
_batch_start->setEnabled(false);
_batch_end->setEnabled(false);
_batch_num->setEnabled(false);
}
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
17 changes: 13 additions & 4 deletions src/mvc/ScanRegionDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QLineEdit>
#include <QPushButton>
#include <QComboBox>
#include <QCheckBox>
#include <QStringListModel>
#include <QListWidgetItem>
#include <QTableView>
Expand Down Expand Up @@ -53,12 +54,12 @@ class ScanRegionDialog : public QDialog

public slots:

void onUpdate();

void onUpdateAndQueue();

void scanChanged(const QString &);

void onBatchScanChanged(Qt::CheckState);

protected:

void _createLayout();
Expand All @@ -67,15 +68,23 @@ public slots:
QLineEdit *_scan_name;

QComboBox *_scan_type;
QPushButton *_btn_update;

QComboBox *_cb_batch_prop;

QPushButton *_btn_update_and_queue;

QPushButton *_btn_cancel;

QTableView* _scan_options;

QLineEdit *_batch_start;

QLineEdit *_batch_end;

QLineEdit *_batch_num;

QCheckBox* _chk_batch_scan;

ScanTableModel *_scan_table_model;

QLabel* _lbl_region_name;
Expand Down

0 comments on commit 620f576

Please sign in to comment.