Skip to content

Commit

Permalink
Added edit/add/dup/delete DM action
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Feb 6, 2024
1 parent 286db31 commit 7ff74cc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
98 changes: 92 additions & 6 deletions src/cdlgmdfdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CDlgMdfDM::initDialogData(CMDF* pmdf, CMDF_DecisionMatrix* pdm, int index)
connect(ui->btnDelAction,
SIGNAL(clicked()),
this,
SLOT(delAction()));
SLOT(deleteAction()));

setLevel(pmdf->getLevel());
ui->comboLevel->setEnabled(false);
Expand All @@ -138,14 +138,12 @@ CDlgMdfDM::initDialogData(CMDF* pmdf, CMDF_DecisionMatrix* pdm, int index)
setSize(8);
ui->spinRowSize->setEnabled(false);
}
else {
else {
setPage(0);
ui->spinStartPage->setEnabled(false);
setSize(pdm->getRowSize());
}



// Render available actions
renderActions();

Expand Down Expand Up @@ -301,8 +299,8 @@ CDlgMdfDM::editAction(void)
int idx = ui->listActions->currentRow();

QListWidgetItem* pitem = ui->listActions->currentItem();
printf("data=%d\n",pitem->data(QListWidgetItem::UserType).toUInt());
CMDF_Action* paction = m_pdm->getAction(pitem->data(QListWidgetItem::UserType).toUInt());
printf("data=%d\n", pitem->data(QListWidgetItem::UserType).toUInt());
CMDF_Action* paction = m_pdm->getAction(pitem->data(QListWidgetItem::UserType).toUInt());

CDlgMdfDmAction dlg(this);
dlg.initDialogData(m_pmdf, paction);
Expand All @@ -324,6 +322,33 @@ CDlgMdfDM::editAction(void)
void
CDlgMdfDM::addAction(void)
{
bool ok;

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

QListWidgetItem* pitem = ui->listActions->currentItem();
CMDF_Action* paction = new CMDF_Action; // = m_pdm->getAction(pitem->data(QListWidgetItem::UserType).toUInt());
if (nullptr == paction) {
return;
}


CDlgMdfDmAction dlg(this);
adddlg:

dlg.initDialogData(m_pmdf, paction);
if (QDialog::Accepted == dlg.exec()) {
if (!m_pdm->addAction(paction)) {
QMessageBox::warning(this, tr("MDF add new action"), tr("Action with code %1 is already define. Must be unique.").arg(paction->getCode()));
}
ui->listActions->clear();
renderActions();
ui->listActions->setCurrentRow(idx);
}
else {
delete paction;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -333,6 +358,44 @@ CDlgMdfDM::addAction(void)
void
CDlgMdfDM::dupAction(void)
{
bool ok;

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

QListWidgetItem* pitem = ui->listActions->currentItem();
CMDF_Action* paction = m_pdm->getAction(pitem->data(QListWidgetItem::UserType).toUInt());
if (nullptr == paction) {
return;
}

CMDF_Action* pactionnew = new (CMDF_Action);
if (nullptr == pactionnew) {
return;
}

pactionnew->setCode(paction->getCode());
pactionnew->setName(paction->getName());

adddlg:
CDlgMdfDmAction dlg(this);
dlg.initDialogData(m_pmdf, pactionnew);
// 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_pdm->addAction(pactionnew)) {
QMessageBox::warning(this, tr("MDF add new action"), tr("Action with code %1 is already define. Must be unique.").arg(paction->getCode()));
goto adddlg;
}
ui->listActions->clear();
renderActions();
ui->listActions->setCurrentRow(idx);
}
else {
delete paction;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -342,6 +405,29 @@ CDlgMdfDM::dupAction(void)
void
CDlgMdfDM::deleteAction(void)
{
bool ok;

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

QListWidgetItem* pitem = ui->listActions->currentItem();
CMDF_Action* paction = m_pdm->getAction(pitem->data(QListWidgetItem::UserType).toUInt());
if (nullptr == paction) {
return;
}

if (QMessageBox::No == QMessageBox::question(this,
tr("MDF delete action"),
tr("Delete action with code %1.").arg(paction->getCode()))) {
return;
}

if (!m_pdm->deleteAction(paction)) {
QMessageBox::warning(this, tr("MDF add new action"), tr("Failed to remove action with code %1.").arg(paction->getCode()));
}

renderActions();
ui->listActions->setCurrentRow(idx);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion src/cdlgmdfdm.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listActions"/>
<widget class="QListWidget" name="listActions">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down
7 changes: 1 addition & 6 deletions src/cdlgmdfdmaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,13 @@ CDlgMdfDmAction::addActionParam(void)
// 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);
adddlg:
dlg.initDialogData(m_pmdf, pactionparam);
// If DM is level I only offset 0 is allowd
if (VSCP_LEVEL1 == m_pmdf->getLevel()) {
Expand Down Expand Up @@ -333,7 +329,6 @@ CDlgMdfDmAction::dupActionParam(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());
if (nullptr == pactionparam) {
return;
Expand Down
6 changes: 5 additions & 1 deletion src/cdlgmdfdmaction.ui
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listActionParams"/>
<widget class="QListWidget" name="listActionParams">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down

0 comments on commit 7ff74cc

Please sign in to comment.