Skip to content

Commit

Permalink
Action param edit/add/dup/delete in place
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Feb 6, 2024
1 parent 265dabb commit 286db31
Show file tree
Hide file tree
Showing 11 changed files with 427 additions and 131 deletions.
19 changes: 16 additions & 3 deletions src/cdlgmdfdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,24 @@ CDlgMdfDM::initDialogData(CMDF* pmdf, CMDF_DecisionMatrix* pdm, int index)
this,
SLOT(delAction()));

setLevel(pdm->getLevel());
setPage(pdm->getStartPage());
setLevel(pmdf->getLevel());
ui->comboLevel->setEnabled(false);

setOffset(pdm->getStartOffset());
setRows(pdm->getRowCount());
setSize(pdm->getRowSize());

if (0 == pmdf->getLevel()) {
setPage(pdm->getStartPage());
setSize(8);
ui->spinRowSize->setEnabled(false);
}
else {
setPage(0);
ui->spinStartPage->setEnabled(false);
setSize(pdm->getRowSize());
}



// Render available actions
renderActions();
Expand Down
6 changes: 5 additions & 1 deletion src/cdlgmdfdm.ui
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinRowSize"/>
<widget class="QSpinBox" name="spinRowSize">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_10">
Expand Down
109 changes: 103 additions & 6 deletions src/cdlgmdfdmaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CDlgMdfDmAction::CDlgMdfDmAction(QWidget* parent)
connect(ui->btnDelActionParam,
SIGNAL(clicked()),
this,
SLOT(delActionParam()));
SLOT(deleteActionParam()));

vscpworks* pworks = (vscpworks*)QCoreApplication::instance();

Expand Down Expand Up @@ -236,10 +236,10 @@ CDlgMdfDmAction::renderActionParams(void)
for (int i = 0; i < pActionParamList->size(); i++) {
CMDF_ActionParameter* pactionparam = (*pActionParamList)[i];
if (nullptr != pactionparam) {
QString str = QString("Offset: %1 - %2").arg(pactionparam->getOffset()).arg(pactionparam->getName().c_str());
QString str = QString("Offset: %1 - %2").arg(pactionparam->getOffset()).arg(pactionparam->getName().c_str());
QListWidgetItem* pitem = new QListWidgetItem(str, ui->listActionParams);
if (nullptr != pitem) {
pitem->setData(QListWidgetItem::UserType,pactionparam->getOffset());
pitem->setData(QListWidgetItem::UserType, pactionparam->getOffset());
ui->listActionParams->addItem(pitem);
}
}
Expand All @@ -262,8 +262,8 @@ CDlgMdfDmAction::editActionParam(void)
int idx = ui->listActionParams->currentRow();

QListWidgetItem* pitem = ui->listActionParams->currentItem();
printf("data=%d\n",pitem->data(QListWidgetItem::UserType).toUInt());
CMDF_ActionParameter* pactionparam = m_paction->getActionParam(pitem->data(QListWidgetItem::UserType).toUInt());
printf("data=%d\n", pitem->data(QListWidgetItem::UserType).toUInt());
CMDF_ActionParameter* pactionparam = m_paction->getActionParam(pitem->data(QListWidgetItem::UserType).toUInt());

CDlgMdfDmActionParam dlg(this);
dlg.initDialogData(m_pmdf, pactionparam);
Expand All @@ -285,6 +285,39 @@ CDlgMdfDmAction::editActionParam(void)
void
CDlgMdfDmAction::addActionParam(void)
{
bool ok;

// Save the selected row
int idx = ui->listActionParams->currentRow();

// QListWidgetItem* pitem = ui->listActionParams->currentItem();
// printf("data=%d\n", pitem->data(QListWidgetItem::UserType).toUInt());
// CMDF_ActionParameter* pactionparam = m_paction->getActionParam(pitem->data(QListWidgetItem::UserType).toUInt());

CMDF_ActionParameter* pactionparam = new (CMDF_ActionParameter);
if (nullptr == pactionparam) {
return;
}

adddlg:
CDlgMdfDmActionParam dlg(this);
dlg.initDialogData(m_pmdf, pactionparam);
// If DM is level I only offset 0 is allowd
if (VSCP_LEVEL1 == m_pmdf->getLevel()) {
dlg.setOffsetReadOnly();
}
if (QDialog::Accepted == dlg.exec()) {
if (!m_paction->addActionParam(pactionparam)) {
QMessageBox::warning(this, tr("MDF add new action parameter"), tr("Action parameter with offset %1 is already define. Must be unique.").arg(pactionparam->getOffset()));
goto adddlg;
}
ui->listActionParams->clear();
renderActionParams();
ui->listActionParams->setCurrentRow(idx);
}
else {
delete pactionparam;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -294,6 +327,47 @@ CDlgMdfDmAction::addActionParam(void)
void
CDlgMdfDmAction::dupActionParam(void)
{
bool ok;

// Save the selected row
int idx = ui->listActionParams->currentRow();

QListWidgetItem* pitem = ui->listActionParams->currentItem();
// printf("data=%d\n", pitem->data(QListWidgetItem::UserType).toUInt());
CMDF_ActionParameter* pactionparam = m_paction->getActionParam(pitem->data(QListWidgetItem::UserType).toUInt());
if (nullptr == pactionparam) {
return;
}

CMDF_ActionParameter* pactionparamnew = new (CMDF_ActionParameter);
if (nullptr == pactionparamnew) {
return;
}

pactionparamnew->setOffset(pactionparam->getOffset());
pactionparamnew->setName(pactionparam->getName());
pactionparamnew->setMin(pactionparam->getMin());
pactionparamnew->setMax(pactionparam->getMax());

adddlg:
CDlgMdfDmActionParam dlg(this);
dlg.initDialogData(m_pmdf, pactionparamnew);
// If DM is level I only offset 0 is allowd
if (VSCP_LEVEL1 == m_pmdf->getLevel()) {
dlg.setOffsetReadOnly();
}
if (QDialog::Accepted == dlg.exec()) {
if (!m_paction->addActionParam(pactionparamnew)) {
QMessageBox::warning(this, tr("MDF add new action parameter"), tr("Action parameter with offset %1 is already define. Must be unique.").arg(pactionparam->getOffset()));
goto adddlg;
}
ui->listActionParams->clear();
renderActionParams();
ui->listActionParams->setCurrentRow(idx);
}
else {
delete pactionparam;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -303,6 +377,29 @@ CDlgMdfDmAction::dupActionParam(void)
void
CDlgMdfDmAction::deleteActionParam(void)
{
bool ok;

// Save the selected row
int idx = ui->listActionParams->currentRow();

QListWidgetItem* pitem = ui->listActionParams->currentItem();
CMDF_ActionParameter* pactionparam = m_paction->getActionParam(pitem->data(QListWidgetItem::UserType).toUInt());
if (nullptr == pactionparam) {
return;
}

if (QMessageBox::No == QMessageBox::question(this,
tr("MDF delete action parameter"),
tr("Delete action parameter with offset %1.").arg(pactionparam->getOffset()))) {
return;
}

if (!m_paction->deleteActionParam(pactionparam)) {
QMessageBox::warning(this, tr("MDF add new action parameter"), tr("Failed to remove action parameter with offset %1.").arg(pactionparam->getOffset()));
}

renderActionParams();
ui->listActionParams->setCurrentRow(idx);
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -314,7 +411,7 @@ CDlgMdfDmAction::accept()
{
std::string str;
if (nullptr != m_paction) {
m_paction ->setCode(getCode());
m_paction->setCode(getCode());
m_paction->setName(getName().toStdString());
}
else {
Expand Down
8 changes: 8 additions & 0 deletions src/cdlgmdfdmactionparam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ CDlgMdfDmActionParam::initDialogData(CMDF* pmdf, CMDF_ActionParameter* pactionpa
this->setFixedSize(this->size());
}

///////////////////////////////////////////////////////////////////////////////
// setOffsetReadOnly
//

void CDlgMdfDmActionParam::setOffsetReadOnly(void)
{
ui->spinOffset->setValue(0);
ui->spinOffset->setEnabled(false);
}

// ----------------------------------------------------------------------------
// Getters & Setters
Expand Down
6 changes: 6 additions & 0 deletions src/cdlgmdfdmactionparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class CDlgMdfDmActionParam : public QDialog {
*/
void initDialogData(CMDF *pmdf, CMDF_ActionParameter* pactionparam, int index = 0);

/*!
Set offset input field to read only
Used by level I as it is always zero for level I DM's
*/
void setOffsetReadOnly(void);

/// @brief Rener action parameters
void renderActionParams(void);

Expand Down
5 changes: 4 additions & 1 deletion src/cdlgmdfdmactionparam.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@
<item row="3" column="1">
<widget class="QSpinBox" name="spinMax">
<property name="maximum">
<number>65535</number>
<number>255</number>
</property>
<property name="value">
<number>255</number>
</property>
</widget>
</item>
Expand Down
Loading

0 comments on commit 286db31

Please sign in to comment.