Skip to content

Commit

Permalink
Added modify button for scan regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Jul 2, 2024
1 parent 6a1a08d commit 91599fe
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 61 deletions.
23 changes: 12 additions & 11 deletions src/gstar/AbstractImageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,22 +724,23 @@ void AbstractImageWidget::treeDoubleClicked(const QModelIndex& index)

if (item != nullptr)
{
QDialog* custom_dialog = item->get_custom_dialog();
if(custom_dialog != nullptr)
QVariant data = item->data(0, index.column());
if (data.type() == QVariant::Color)
{
custom_dialog->show();
QColor color = QColorDialog::getColor(data.toString(), this);
if (color.isValid())
{
item->setData(index, color);
}
}
else
else if (data.type() == QVariant::Icon)
{
QVariant data = item->data(0, index.column());
if (data.type() == QVariant::Color)
QDialog* custom_dialog = item->get_custom_dialog();
if(custom_dialog != nullptr)
{
QColor color = QColorDialog::getColor(data.toString(), this);
if (color.isValid())
{
item->setData(index, color);
}
custom_dialog->show();
}

}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/gstar/Annotation/AbstractGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ Qt::ItemFlags AbstractGraphicsItem::displayFlags(int row, int column) const
switch(t)
{
case QVariant::Color:
case QVariant::Icon:
flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
break;
case QVariant::Bool:
Expand Down
31 changes: 31 additions & 0 deletions src/gstar/Annotation/ScanRegionGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ using namespace gstar;
ScanRegionGraphicsItem::ScanRegionGraphicsItem(AbstractGraphicsItem* parent)
: UProbeRegionGraphicsItem(parent)
{

connect(&_scan_dialog, &ScanRegionDialog::ScanUpdated, this, &ScanRegionGraphicsItem::onScanUpdated);

prependProperty(new AnnotationProperty("Edit", QIcon(":/images/compose.png")));
/*
m_mouseOverPixelCoordModel = nullptr;
m_lightToMicroCoordModel = nullptr;
Expand Down Expand Up @@ -60,6 +64,7 @@ ScanRegionGraphicsItem::ScanRegionGraphicsItem(AbstractGraphicsItem* parent)
initialScale();
updateStringSize();
*/

}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -108,6 +113,15 @@ ScanRegionGraphicsItem::ScanRegionGraphicsItem(QMap<QString, QString>& marker,

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

const QString ScanRegionGraphicsItem::displayName() const
{

return QString("Scan");

}

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

ScanRegionGraphicsItem* ScanRegionGraphicsItem::cloneRegion()
{
ScanRegionGraphicsItem* newRegion = new ScanRegionGraphicsItem();
Expand All @@ -117,6 +131,23 @@ ScanRegionGraphicsItem* ScanRegionGraphicsItem::cloneRegion()

return newRegion;
}

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

QDialog* ScanRegionGraphicsItem::get_custom_dialog()
{
_scan_dialog.updateProps(m_data);
return &_scan_dialog;
}

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

void ScanRegionGraphicsItem::onScanUpdated()
{

setPropertyValue(DEF_STR_DISPLAY_NAME, _scan_dialog.getScanName());

}
/*
//---------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion src/gstar/Annotation/ScanRegionGraphicsItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace gstar
class ScanRegionGraphicsItem : public UProbeRegionGraphicsItem
{

Q_OBJECT

public:

/**
Expand Down Expand Up @@ -61,7 +63,9 @@ class ScanRegionGraphicsItem : public UProbeRegionGraphicsItem
*/
virtual ScanRegionGraphicsItem* cloneRegion();

virtual QDialog* get_custom_dialog() { return &_scan_dialog; }
virtual QDialog* get_custom_dialog();

const QString displayName() const;
/*
QRectF boundingRect() const;
Expand Down Expand Up @@ -143,6 +147,11 @@ class ScanRegionGraphicsItem : public UProbeRegionGraphicsItem
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
*/

public slots:

void onScanUpdated();

private:
ScanRegionDialog _scan_dialog;

Expand Down
6 changes: 5 additions & 1 deletion src/gstar/AnnotationTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ QVariant AnnotationTreeModel::data(const QModelIndex& index, int role) const
{
return QColor(var.toString());
}
else if (var.type() == QVariant::Icon)
{
return var.value<QIcon>();
}
}
else if ( role == Qt::CheckStateRole )
{
Expand All @@ -198,7 +202,7 @@ QVariant AnnotationTreeModel::data(const QModelIndex& index, int role) const
//this stops the color variants from displaying the color as
// a hex value in the tree
QVariant var = item->data(index.row(), index.column());
if (var.type() == QVariant::Color || var.type() == QVariant::Bool)
if (var.type() == QVariant::Color || var.type() == QVariant::Bool || var.type() == QVariant::Icon )
{
return QVariant();
}
Expand Down
90 changes: 58 additions & 32 deletions src/mvc/ScanRegionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,72 @@ ScanRegionDialog::~ScanRegionDialog()

void ScanRegionDialog::_createLayout()
{
rowLabel = new QLabel("Rows");
colLabel = new QLabel("Cols");
sbRow = new QSpinBox();
sbCol = new QSpinBox();

sbRow->setMinimum(1);
sbRow->setMaximum(6);
sbRow->setSingleStep(1);
sbRow->setValue(1);

sbCol->setMinimum(1);
sbCol->setMaximum(6);
sbCol->setSingleStep(1);
sbCol->setValue(1);

updateBtn = new QPushButton("Update");
cancelBtn = new QPushButton("Cancel");
connect(updateBtn, SIGNAL(pressed()), this, SLOT(onUpdate()));
connect(cancelBtn, SIGNAL(pressed()), this, SLOT(close()));

QGridLayout *mainLayout = new QGridLayout;
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
mainLayout->addWidget(rowLabel, 0, 0);
mainLayout->addWidget(colLabel, 0, 1);
mainLayout->addWidget(sbRow, 1, 0);
mainLayout->addWidget(sbCol, 1, 1);
mainLayout->addWidget(updateBtn, 2, 0);
mainLayout->addWidget(cancelBtn, 2, 1);
mainLayout->setRowStretch(3, 1);

setLayout(mainLayout);

_scan_name = new QLineEdit(" ");

_scan_type = new QComboBox();

_scan_options = new QListWidget();

_btn_update = new QPushButton("Update");
_btn_update_and_queue = new QPushButton("Update and Queue");
_btn_cancel = new QPushButton("Cancel");
connect(_btn_update, SIGNAL(pressed()), this, SLOT(onUpdate()));
connect(_btn_update_and_queue, SIGNAL(pressed()), this, SLOT(onUpdateAndQueue()));
connect(_btn_cancel, SIGNAL(pressed()), this, SLOT(close()));

QVBoxLayout* main_layout = new QVBoxLayout();

QHBoxLayout* name_layout = new QHBoxLayout();
name_layout->addWidget(new QLabel("Scan Name: "));
name_layout->addWidget(_scan_name);

QHBoxLayout* type_layout = new QHBoxLayout();
type_layout->addWidget(new QLabel("Scan Type: "));
type_layout->addWidget(_scan_type);

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(button_layout);

setLayout(main_layout);

setWindowTitle("Scan Region");
}

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

void ScanRegionDialog::updateProps(QList<gstar::AnnotationProperty*> &anno_list)
{
for(auto &itr : anno_list)
{
if(itr->getName() == DEF_STR_DISPLAY_NAME)
{
_scan_name->setText(itr->getValue().toString());
}
}
}

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

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

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

void ScanRegionDialog::onUpdateAndQueue()
{
emit ScanUpdated();
close();
}

Expand Down
35 changes: 19 additions & 16 deletions src/mvc/ScanRegionDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
#include <QComboBox>
#include <QStringListModel>
#include <QListWidgetItem>
#include <QSpinBox>
#include <QDialogButtonBox>
#include <QList>
#include "gstar/AnnotationProperty.h"

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

/**
* @brief When open the acquisition window, the widget is showing for capturing
* the image from the area detector writer, the window will also be updated to
* show the image.
*/
class ScanRegionDialog : public QDialog
{

Expand All @@ -42,28 +37,36 @@ class ScanRegionDialog : public QDialog
*/
~ScanRegionDialog();

void updateProps(QList<gstar::AnnotationProperty*> &anno_list);

QString getScanName() { return _scan_name->text(); }

signals:
void NewScan();

void ScanUpdated();

public slots:

void onUpdate();

void onUpdateAndQueue();

protected:

void _createLayout();

private:
QLabel *rowLabel;
QLabel *colLabel;
QLineEdit *_scan_name;

QComboBox *_scan_type;

QPushButton *_btn_update;

//QDialogButtonBox *buttonBox;
QPushButton *_btn_update_and_queue;

QPushButton *updateBtn;
QPushButton *cancelBtn;
QPushButton *_btn_cancel;

QSpinBox *sbRow;
QSpinBox *sbCol;

QListWidget* _scan_options;
};


Expand Down
6 changes: 6 additions & 0 deletions src/mvc/VLM_Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,12 @@ void VLM_Widget::createMicroProbeTab()
this,
SLOT(treeDoubleClicked(const QModelIndex &)));

connect(m_mpAnnoTreeView,
&QTreeView::clicked,
this,
&VLM_Widget::treeDoubleClicked);


m_btnAddMicroProbe = new QPushButton("Add Micro Probe Region");
connect(m_btnAddMicroProbe,
SIGNAL(clicked()),
Expand Down
1 change: 1 addition & 0 deletions uProbeX.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<file>images/grid.png</file>
<file>images/question.png</file>
<file>images/gear.png</file>
<file>images/compose.png</file>
</qresource>
</RCC>

0 comments on commit 91599fe

Please sign in to comment.