Skip to content

Commit

Permalink
Added move up, down and remove scan context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Sep 23, 2024
1 parent ac8a875 commit 36d4157
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/mvc/BlueskyComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,38 @@ class BlueskyComm : public QThread
return ret;
}

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

bool removePlan(QString &msg, int row)
{
bool ret = false;
if(_zmq_comm_socket == nullptr)
{
return ret;
}
zmq::message_t message;

QJsonObject params;
params["pos"] = row;
QByteArray msg_arr = gen_send_mesg2("queue_item_remove", params);
_zmq_comm_socket->send(msg_arr.data(), msg_arr.length());

_zmq_comm_socket->recv(&message);
QJsonObject reply = QJsonDocument::fromJson(QString::fromUtf8((char*)message.data(), message.size()).toUtf8()).object();
if(reply.contains("success"))
{
if(reply["success"].toString() == "true")
{
ret = true;
}
}
if(reply.contains("msg"))
{
msg = reply["msg"].toString();
}
return ret;
}

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

bool get_avail_scans(std::map<QString, BlueskyPlan> &plans, QString &msg)
Expand Down
44 changes: 44 additions & 0 deletions src/mvc/LiveMapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void LiveMapsElementsWidget::createLayout()
connect(_scan_queue_widget, &ScanQueueWidget::onStartQueue, this, &LiveMapsElementsWidget::callStartQueue);
connect(_scan_queue_widget, &ScanQueueWidget::onStopQueue, this, &LiveMapsElementsWidget::callStopQueue);
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanRow, this, &LiveMapsElementsWidget::callMoveScanRow);
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanUp, this, &LiveMapsElementsWidget::callMoveScanUp);
connect(_scan_queue_widget, &ScanQueueWidget::onMoveScanDown, this, &LiveMapsElementsWidget::callMoveScanDown);
connect(_scan_queue_widget, &ScanQueueWidget::onRemoveScan, this, &LiveMapsElementsWidget::callRemoveScan);

_tab_widget = new QTabWidget();
_tab_widget->addTab(_mapsElementsWidget, "Counts");
Expand Down Expand Up @@ -449,3 +452,44 @@ void LiveMapsElementsWidget::callMoveScanRow(int srcRow, int destRow)
}

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

void LiveMapsElementsWidget::callMoveScanUp(int row)
{
if(row > 0)
{
callMoveScanRow(row, row-1);
}
}

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

void LiveMapsElementsWidget::callMoveScanDown(int row)
{

callMoveScanRow(row, row+1);

}

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

void LiveMapsElementsWidget::callRemoveScan(int row)
{
QString msg;
if(_qserverComm == nullptr)
{
updateIp();
}
if (false == _qserverComm->removePlan(msg, row))
{

}
else
{

}

_scan_queue_widget->newDataArrived( msg );
getQueuedScans();
}

//---------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/mvc/LiveMapsElementsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public slots:
void callStopQueue();

void callMoveScanRow(int, int);

void callMoveScanUp(int);

void callMoveScanDown(int);

void callRemoveScan(int);

void queueScan(const BlueskyPlan& plan);

Expand Down
105 changes: 105 additions & 0 deletions src/mvc/ScanQueueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <QLabel>
#include <QHeaderView>
#include <QDockWidget>
#include <QMessageBox>
#include <QMenu>
#include "core/defines.h"

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -55,6 +57,12 @@ void ScanQueueWidget::_createLayout()
_scan_queue_table_view->setDragDropOverwriteMode(false);
_scan_queue_table_view->setDropIndicatorShown(true);
_scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
_scan_queue_table_view->setContextMenuPolicy(Qt::CustomContextMenu);
connect(_scan_queue_table_view,
&QTableView::customContextMenuRequested,
this,
&ScanQueueWidget::scanContextMenu);
//_scan_queue_table_view->selectionModel()
// _scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::Interactive);


Expand Down Expand Up @@ -86,6 +94,27 @@ void ScanQueueWidget::_createLayout()
_btn_close_env->setToolTip("Close Environment");
connect(_btn_close_env, &QPushButton::pressed, this, &ScanQueueWidget::onCloseEnv);


_move_scan_up = new QAction("Move Scan Up", this);
connect(_move_scan_up,
&QAction::triggered,
this,
&ScanQueueWidget::on_move_scan_up);

_move_scan_down = new QAction("Move Scan Down", this);
connect(_move_scan_down,
&QAction::triggered,
this,
&ScanQueueWidget::on_move_scan_down);

_remove_scan = new QAction("Remove Scan", this);
connect(_remove_scan,
&QAction::triggered,
this,
&ScanQueueWidget::on_remove_scan);



QGridLayout *grid = new QGridLayout();
grid->addWidget(_btn_play, 0,0);
grid->addWidget(_btn_stop,0,1);
Expand Down Expand Up @@ -118,6 +147,82 @@ void ScanQueueWidget::_createLayout()

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

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);
menu.addAction(_remove_scan);

QAction* result = menu.exec(_scan_queue_table_view->viewport()->mapToGlobal(pos));
if (result == nullptr)
{
//m_selectionModel->clearSelection();
}

}
}

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

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--)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanUp(index.row());
}
}
}

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

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--)
{
QModelIndex index = selectedIndexes[i];
emit onMoveScanDown(index.row());
}
}
}

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

void ScanQueueWidget::on_remove_scan()
{
if (_scan_queue_table_view->selectionModel()->hasSelection())
{
QModelIndexList selectedIndexes = _scan_queue_table_view->selectionModel()->selectedRows();

//display message box
QMessageBox msgBox;
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
msgBox.setText("Are you sure you want to delete the selected items?");
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
{
for (int i = selectedIndexes.count() - 1; i >= 0; i--)
{
QModelIndex index = selectedIndexes[i];
emit onRemoveScan(index.row());
}
}

}
}

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

void ScanQueueWidget::updateQueuedItems( std::vector<BlueskyPlan> &queued_plans, BlueskyPlan &running_plan)
{
_scan_queue_table_model->setAllData(queued_plans);
Expand Down
19 changes: 19 additions & 0 deletions src/mvc/ScanQueueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ class ScanQueueWidget : public QWidget

void onMoveScanRow(int, int);

void onMoveScanUp(int);

void onMoveScanDown(int);

void onRemoveScan(int);

public slots:
void newDataArrived(const QString &);

void scanContextMenu(const QPoint &);

void on_move_scan_up();

void on_move_scan_down();

void on_remove_scan();

protected:

/**
Expand Down Expand Up @@ -81,6 +95,11 @@ public slots:

QPushButton* _btn_close_env;

QAction* _move_scan_up;

QAction* _move_scan_down;

QAction* _remove_scan;
};


Expand Down

0 comments on commit 36d4157

Please sign in to comment.