diff --git a/src/cdlgmdfdm.cpp b/src/cdlgmdfdm.cpp index 172b53d9..0a58db1f 100644 --- a/src/cdlgmdfdm.cpp +++ b/src/cdlgmdfdm.cpp @@ -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(); diff --git a/src/cdlgmdfdm.ui b/src/cdlgmdfdm.ui index 03c342cc..f8f588c6 100644 --- a/src/cdlgmdfdm.ui +++ b/src/cdlgmdfdm.ui @@ -115,7 +115,11 @@ - + + + 255 + + diff --git a/src/cdlgmdfdmaction.cpp b/src/cdlgmdfdmaction.cpp index 4b1de93f..13b31a17 100644 --- a/src/cdlgmdfdmaction.cpp +++ b/src/cdlgmdfdmaction.cpp @@ -88,7 +88,7 @@ CDlgMdfDmAction::CDlgMdfDmAction(QWidget* parent) connect(ui->btnDelActionParam, SIGNAL(clicked()), this, - SLOT(delActionParam())); + SLOT(deleteActionParam())); vscpworks* pworks = (vscpworks*)QCoreApplication::instance(); @@ -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); } } @@ -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); @@ -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; + } } /////////////////////////////////////////////////////////////////////////////// @@ -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; + } } /////////////////////////////////////////////////////////////////////////////// @@ -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); } /////////////////////////////////////////////////////////////////////////////// @@ -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 { diff --git a/src/cdlgmdfdmactionparam.cpp b/src/cdlgmdfdmactionparam.cpp index 338f1718..271ca6b9 100644 --- a/src/cdlgmdfdmactionparam.cpp +++ b/src/cdlgmdfdmactionparam.cpp @@ -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 diff --git a/src/cdlgmdfdmactionparam.h b/src/cdlgmdfdmactionparam.h index 7f26553c..c5e7487e 100644 --- a/src/cdlgmdfdmactionparam.h +++ b/src/cdlgmdfdmactionparam.h @@ -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); diff --git a/src/cdlgmdfdmactionparam.ui b/src/cdlgmdfdmactionparam.ui index 571e0402..e733a29a 100644 --- a/src/cdlgmdfdmactionparam.ui +++ b/src/cdlgmdfdmactionparam.ui @@ -90,7 +90,10 @@ - 65535 + 255 + + + 255 diff --git a/src/cdlgmdfregister.cpp b/src/cdlgmdfregister.cpp index feb2ce5a..f70ab7ff 100644 --- a/src/cdlgmdfregister.cpp +++ b/src/cdlgmdfregister.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,12 @@ CDlgMdfRegister::initDialogData(CMDF* pmdf, CMDF_Register* preg, int index) m_preg = preg; + // Connect set new register page button + connect(ui->btnNewPage, + SIGNAL(clicked()), + this, + SLOT(newPage())); + // Connect set foreground color button connect(ui->btnSetFgColor, SIGNAL(clicked()), @@ -118,7 +125,7 @@ CDlgMdfRegister::initDialogData(CMDF* pmdf, CMDF_Register* preg, int index) connect(ui->btnSetUndef, SIGNAL(clicked()), this, - SLOT(setUndef())); + SLOT(setUndef())); setName(preg->getName().c_str()); setPage(preg->getPage()); @@ -136,18 +143,18 @@ CDlgMdfRegister::initDialogData(CMDF* pmdf, CMDF_Register* preg, int index) setForegroundColor(preg->getForegroundColor()); setBackgroundColor(preg->getBackgroundColor()); - std::set pages; - uint32_t cnt = pmdf->getPages(pages); - ui->comboPage->clear(); - int pos = 0; - for (std::set::iterator it=pages.begin(); it!=pages.end(); ++it) { - ui->comboPage->addItem(QString("Page %1").arg(*it), *it); - if (preg->getPage() == *it) { - ui->comboPage->setCurrentIndex(pos); - } - pos++; + // Only one page for Level II + if (1 == m_pmdf->getLevel()) { + ui->comboPage->setEnabled(false); + ui->btnNewPage->setEnabled(false); + ui->comboPage->addItem(QString("Level II (no pages)"), 0); } + else { + // Find already defined pages + uint32_t cnt = m_pmdf->getPages(m_pages); + renderPages(); + } switch (index) { case index_name: @@ -196,7 +203,7 @@ CDlgMdfRegister::initDialogData(CMDF* pmdf, CMDF_Register* preg, int index) case index_bgcolor: ui->editBgColor->setFocus(); - break; + break; default: ui->editName->setFocus(); @@ -215,6 +222,7 @@ CDlgMdfRegister::setReadOnly(void) { ui->comboPage->setEnabled(false); ui->editOffset->setEnabled(false); + ui->btnNewPage->setEnabled(false); } /////////////////////////////////////////////////////////////////////////////// @@ -227,6 +235,55 @@ CDlgMdfRegister::setInitialFocus(void) // ui->editName->setFocus(); } +/////////////////////////////////////////////////////////////////////////////// +// renderPages +// + +void +CDlgMdfRegister::renderPages(void) +{ + + ui->comboPage->clear(); + int pos = 0; + for (std::set::iterator it = m_pages.begin(); it != m_pages.end(); ++it) { + ui->comboPage->addItem(QString("Page %1").arg(*it), *it); + if (m_preg->getPage() == *it) { + ui->comboPage->setCurrentIndex(pos); + } + pos++; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// newPage +// + +void +CDlgMdfRegister::newPage(void) +{ + uint16_t newpage; + + // m_pmdf->getPages(pages); +ask_again: + QString str = QInputDialog::getText(this, APPNAME, "Input register page number: "); + if (!str.length()) { + return; + } + newpage = vscp_readStringValue(str.toStdString()); + auto pos = m_pages.find(newpage); + if (m_pages.end() != pos) { + QMessageBox msgWarning; + msgWarning.setText("Register page already exist"); + msgWarning.setIcon(QMessageBox::Warning); + msgWarning.setWindowTitle("Add register page"); + msgWarning.exec(); + goto ask_again; + } + m_pages.insert(newpage); + renderPages(); + ui->comboPage->setCurrentIndex(ui->comboPage->findData(newpage)); +} + /////////////////////////////////////////////////////////////////////////////// // setUndef // @@ -311,12 +368,24 @@ CDlgMdfRegister::setPage(uint16_t page) uint32_t CDlgMdfRegister::getOffset(void) { - return vscp_readStringValue(ui->editOffset->text().toStdString()); + uint32_t offset = vscp_readStringValue(ui->editOffset->text().toStdString()); + + // Level I can only have offset 0-127 + if (1 == m_pmdf->getLevel()) { + offset &= 0x7f; + } + + return offset; } void CDlgMdfRegister::setOffset(uint32_t offset) { + // Level I can only have offset 0-127 + if (1 == m_pmdf->getLevel()) { + offset &= 0x7f; + } + ui->editOffset->setText(QString("%1").arg(offset)); } @@ -459,7 +528,15 @@ CDlgMdfRegister::accept() std::string str; if (nullptr != m_preg) { m_preg->setName(getName().toStdString()); - m_preg->setPage(getPage()); + + // Level I can only have offset 0-127 + if (1 == m_pmdf->getLevel()) { + m_preg->setPage(getPage()); + } + else { + m_preg->setPage(0); + } + m_preg->setOffset(getOffset()); m_preg->setType(static_cast(getType())); m_preg->setSpan(getSpan()); diff --git a/src/cdlgmdfregister.h b/src/cdlgmdfregister.h index 5e0a707b..90490181 100644 --- a/src/cdlgmdfregister.h +++ b/src/cdlgmdfregister.h @@ -29,13 +29,11 @@ #ifndef CDLGMDFREGISTER_H #define CDLGMDFREGISTER_H -#include #include +#include #include - - namespace Ui { class CDlgMdfRegister; } @@ -48,15 +46,15 @@ class CDlgMdfRegister : public QDialog { explicit CDlgMdfRegister(QWidget* parent = nullptr); ~CDlgMdfRegister(); - static const int index_name = 0; - static const int index_page = 1; - static const int index_offset = 2; - static const int index_type = 3; - static const int index_span = 4; - static const int index_width = 5; - static const int index_min = 6; - static const int index_max = 7; - static const int index_access = 8; + static const int index_name = 0; + static const int index_page = 1; + static const int index_offset = 2; + static const int index_type = 3; + static const int index_span = 4; + static const int index_width = 5; + static const int index_min = 6; + static const int index_max = 7; + static const int index_access = 8; static const int index_default = 9; static const int index_fgcolor = 10; static const int index_bgcolor = 11; @@ -73,16 +71,17 @@ class CDlgMdfRegister : public QDialog { @param CMDF *pmdf Pointer to MDF @param pmdfobject Pointer to MDF object @param index Selected file item - + */ - void initDialogData(CMDF *pmdf, CMDF_Register* preg, int index = 0); + void initDialogData(CMDF* pmdf, CMDF_Register* preg, int index = 0); /*! Prevent page and offset from being edited */ void setReadOnly(void); - + /// Render pages into page combo box + void renderPages(void); // ---------------------------------------------------------------------------- // Getters & Setters @@ -138,9 +137,14 @@ class CDlgMdfRegister : public QDialog { public slots: - /*! - Show dialog to select foregrund color + /*! + add/define new register page */ + void newPage(void); + + /*! + Show dialog to select foregrund color +*/ void showFgColorDlg(void); /*! @@ -151,19 +155,21 @@ public slots: /* Set UNDEF for default value */ - void setUndef(void); + void setUndef(void); /*! Accept dialog data and write to register */ void accept(void); - private: Ui::CDlgMdfRegister* ui; + /// Register pages + std::set m_pages; + /// Pointer to MDF - CMDF *m_pmdf; + CMDF* m_pmdf; /// Pointer to register information CMDF_Register* m_preg; diff --git a/src/cdlgmdfregister.ui b/src/cdlgmdfregister.ui index 6678d8cd..e9f6c4be 100644 --- a/src/cdlgmdfregister.ui +++ b/src/cdlgmdfregister.ui @@ -361,51 +361,7 @@ - - - - - Register bit definitions - - - ... - - - - - - - Register values - - - ... - - - - - - - Register descriptions - - - ... - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + diff --git a/src/cfrmmdf.cpp b/src/cfrmmdf.cpp index 658348ff..bf648f2d 100644 --- a/src/cfrmmdf.cpp +++ b/src/cfrmmdf.cpp @@ -48,6 +48,8 @@ #include "ui_cfrmmdf.h" #include "cdlgeditmap.h" +#include "cdlgmdfbit.h" +#include "cdlgmdfbitlist.h" #include "cdlgmdfbootloader.h" #include "cdlgmdfcontact.h" #include "cdlgmdfcontactlist.h" @@ -65,13 +67,11 @@ #include "cdlgmdfmanufacturer.h" #include "cdlgmdfmodule.h" #include "cdlgmdfregister.h" -#include "cdlgmdfbit.h" -#include "cdlgmdfbitlist.h" #include "cdlgmdfregisterlist.h" -#include "cdlgmdfvalue.h" -#include "cdlgmdfvaluelist.h" #include "cdlgmdfremotevar.h" #include "cdlgmdfremotevarlist.h" +#include "cdlgmdfvalue.h" +#include "cdlgmdfvaluelist.h" #include #include @@ -345,6 +345,7 @@ CFrmMdf::showMdfContextMenu(const QPoint& pos) case mdf_type_register_page: menu->addAction(QString(tr("Register list for page")), this, SLOT(editRegister())); + menu->addAction(QString(tr("Add register on page")), this, SLOT(addRegister())); break; case mdf_type_register: @@ -390,7 +391,7 @@ CFrmMdf::showMdfContextMenu(const QPoint& pos) break; case mdf_type_remotevar: - menu->addAction(QString(tr("Edit remote variables")), this, SLOT(editRemoteVariable())); + menu->addAction(QString(tr("Remote variables")), this, SLOT(editRemoteVariable())); break; case mdf_type_remotevar_item: @@ -803,16 +804,16 @@ CFrmMdf::renderBits(QTreeWidgetItem* pParent, std::deque& dequebits, pItemParent->setText(0, str); pItemBitDefs->addChild(pItemParent); - renderBitInfo(pItemParent, pbit); + renderBitItem(pItemParent, pbit); } } /////////////////////////////////////////////////////////////////////////////// -// renderBitInfo +// renderBitItem // void -CFrmMdf::renderBitInfo(QMdfTreeWidgetItem* pItemParent, CMDF_Bit* pbit) +CFrmMdf::renderBitItem(QMdfTreeWidgetItem* pItemParent, CMDF_Bit* pbit) { QString str; QMdfTreeWidgetItem* pItem; @@ -916,16 +917,16 @@ CFrmMdf::renderValues(QTreeWidgetItem* pParent, std::deque& dequeva pItemParent->setText(0, str); pItemValueDefs->addChild(pItemParent); - renderValueInfo(pItemParent, pvalue); + renderValueItem(pItemParent, pvalue); } } /////////////////////////////////////////////////////////////////////////////// -// renderValueInfo +// renderValueItem // void -CFrmMdf::renderValueInfo(QMdfTreeWidgetItem* pParent, CMDF_Value* pvalue) +CFrmMdf::renderValueItem(QMdfTreeWidgetItem* pParent, CMDF_Value* pvalue) { QString str; QMdfTreeWidgetItem* pItem; @@ -948,11 +949,11 @@ CFrmMdf::renderValueInfo(QMdfTreeWidgetItem* pParent, CMDF_Value* pvalue) } /////////////////////////////////////////////////////////////////////////////// -// renderRegisterInfo +// renderRegisterItem // void -CFrmMdf::renderRegisterInfo(QTreeWidgetItem* pParent, CMDF_Register* preg) +CFrmMdf::renderRegisterItem(QTreeWidgetItem* pParent, CMDF_Register* preg) { QString str; QMdfTreeWidgetItem* pItem; @@ -1121,17 +1122,31 @@ CFrmMdf::renderRegisters(QTreeWidgetItem* pParent) pParent->addChild(pItem); // Add registers for page + std::set regset; + std::map regmap; + + // Create set with sorted register offsets and a map + // to help find corresponding register pointer for (auto it = regs->cbegin(); it != regs->cend(); ++it) { if (itr == (*it)->getPage()) { - pSubItem = new QMdfTreeWidgetItem(pItem, (*it), mdf_type_register_item); - if (nullptr != pSubItem) { - str = QString("Register %1 %2").arg((*it)->getOffset()).arg((*it)->getName().c_str()); - pSubItem->setText(0, str); - pItem->addChild(pSubItem); - renderRegisterInfo(pSubItem, *it); - } + regset.insert((*it)->getOffset()); + regmap[(*it)->getOffset()] = *it; } } + + // Render register sorted on offset for a register page + for (auto it = regset.cbegin(); it != regset.cend(); ++it) { + CMDF_Register* preg = regmap[*it]; + pSubItem = new QMdfTreeWidgetItem(pItem, preg, mdf_type_register_item); + if (nullptr != pSubItem) { + str = QString("Register %1 %2").arg(preg->getOffset()).arg(preg->getName().c_str()); + pSubItem->setText(0, str); + pItem->addChild(pSubItem); + renderRegisterItem(pSubItem, preg); + } + } + + // pItem->sortChildren(0,Qt::AscendingOrder); } } } @@ -1139,16 +1154,16 @@ CFrmMdf::renderRegisters(QTreeWidgetItem* pParent) else { std::map mapRegs; m_mdf.getRegisterMap(0, mapRegs); - renderRegisterInfo(pItem, mapRegs[0]); + renderRegisterItem(pItem, mapRegs[0]); } } /////////////////////////////////////////////////////////////////////////////// -// renderRemoteVariableInfo +// renderRemoteVariableItem // void -CFrmMdf::renderRemoteVariableInfo(QTreeWidgetItem* pParent, CMDF_RemoteVariable* prvar) +CFrmMdf::renderRemoteVariableItem(QTreeWidgetItem* pParent, CMDF_RemoteVariable* prvar) { QString str; QMdfTreeWidgetItem* pItem; @@ -1276,12 +1291,14 @@ CFrmMdf::renderRemoteVariables(QTreeWidgetItem* pParent) pSubItem = new QMdfTreeWidgetItem(pParent, pvar, mdf_type_remotevar_item); if (nullptr != pSubItem) { - str = QString("%1 %2").arg(CDlgMdfRemoteVar::pre_str_remote_variable).arg(pvar->getName().c_str()); + str = QString("%1 %2 - %3").arg(CDlgMdfRemoteVar::pre_str_remote_variable).arg(i).arg(pvar->getName().c_str()); pSubItem->setText(0, str); pParent->addChild(pSubItem); - renderRemoteVariableInfo(pSubItem, pvar); + renderRemoteVariableItem(pSubItem, pvar); } } + + // pParent->sortChildren(0,Qt::AscendingOrder); } } @@ -5550,6 +5567,88 @@ CFrmMdf::deleteFile(void) } // switch } +/////////////////////////////////////////////////////////////////////////////// +// addRegister +// + +void +CFrmMdf::addRegister(void) +{ + QMdfTreeWidgetItem* pItem = (QMdfTreeWidgetItem*)ui->treeMDF->currentItem(); + QMdfTreeWidgetItem* pItemHead = (QMdfTreeWidgetItem*)pItem->parent(); + uint16_t selectedIndex = pItem->getElementIndex(); + + // Item must be selected + if (nullptr == pItem) { + int ret = QMessageBox::critical(this, tr("MDF register add"), tr("No MDF register item selected")); + return; + } + + // Must have an object + if (nullptr == pItem->getObject()) { + int ret = QMessageBox::critical(this, tr("MDF register add"), tr("Internal error: Invalid register object")); + spdlog::error("MDF register edit - object has nullptr"); + return; + } + + switch (pItem->getObjectType()) { + + case mdf_type_register_page: { + // This is the main register level - We can add a register here + bool ok; + CMDF_Register* pregnew = new CMDF_Register(); + +addregdlg1: + CDlgMdfRegister dlg(this); + dlg.initDialogData(&m_mdf, pregnew); + if (QDialog::Accepted == dlg.exec()) { + // Check if register is already defined + CMDF_Register* preg = m_mdf.getRegister(pregnew->getOffset(), pregnew->getPage()); + if (nullptr != preg) { + QMessageBox::warning(this, tr("MDF add new register"), tr("Register page=%1 offset=%2 is already define. Must be unique.").arg(pregnew->getPage()).arg(pregnew->getOffset())); + goto addregdlg1; + } + m_mdf.getRegisterObjList()->push_back(pregnew); + QList childrenList = pItem->takeChildren(); + // Remove children + for (qsizetype i = 0; i < childrenList.size(); ++i) { + QMdfTreeWidgetItem* item = (QMdfTreeWidgetItem*)childrenList.at(i); + delete item; + } + childrenList.clear(); + renderRegisters(pItem); + } + } break; + + case mdf_type_register: { + // This is the main register level - We can add a register here + bool ok; + CMDF_Register* pregnew = new CMDF_Register(); + + addregdlg: + CDlgMdfRegister dlg(this); + dlg.initDialogData(&m_mdf, pregnew); + if (QDialog::Accepted == dlg.exec()) { + // Check if register is already defined + CMDF_Register* preg = m_mdf.getRegister(pregnew->getOffset(), pregnew->getPage()); + if (nullptr != preg) { + QMessageBox::warning(this, tr("MDF add new register"), tr("Register page=%1 offset=%2 is already define. Must be unique.").arg(pregnew->getPage()).arg(pregnew->getOffset())); + goto addregdlg; + } + m_mdf.getRegisterObjList()->push_back(pregnew); + QList childrenList = pItem->takeChildren(); + // Remove children + for (qsizetype i = 0; i < childrenList.size(); ++i) { + QMdfTreeWidgetItem* item = (QMdfTreeWidgetItem*)childrenList.at(i); + delete item; + } + childrenList.clear(); + renderRegisters(pItem); + } + } break; + } +} + /////////////////////////////////////////////////////////////////////////////// // editRegister // @@ -5593,7 +5692,30 @@ CFrmMdf::editRegister(void) } break; case mdf_type_register: { - // Should not come here. But if we do don't do an anything. :)))) + // This is the main register level - We can add a register here + bool ok; + CMDF_Register* pregnew = new CMDF_Register(); + + addregdlg: + CDlgMdfRegister dlg(this); + dlg.initDialogData(&m_mdf, pregnew); + if (QDialog::Accepted == dlg.exec()) { + // Check if register is already defined + CMDF_Register* preg = m_mdf.getRegister(pregnew->getOffset(), pregnew->getPage()); + if (nullptr != preg) { + QMessageBox::warning(this, tr("MDF add new register"), tr("Register page=%1 offset=%2 is already define. Must be unique.").arg(pregnew->getPage()).arg(pregnew->getOffset())); + goto addregdlg; + } + m_mdf.getRegisterObjList()->push_back(pregnew); + QList childrenList = pItem->takeChildren(); + // Remove children + for (qsizetype i = 0; i < childrenList.size(); ++i) { + QMdfTreeWidgetItem* item = (QMdfTreeWidgetItem*)childrenList.at(i); + delete item; + } + childrenList.clear(); + renderRegisters(pItem); + } } break; case mdf_type_register_item: { @@ -5615,7 +5737,7 @@ CFrmMdf::editRegister(void) } childrenList.clear(); pItem->setText(0, QString("Register %1 %2").arg(preg->getOffset()).arg(preg->getName().c_str())); - renderRegisterInfo(pItem, preg); + renderRegisterItem(pItem, preg); } } break; @@ -5638,8 +5760,8 @@ CFrmMdf::editRegister(void) delete item; } childrenList.clear(); - pItemHead->setText(0, QString("Register %1 %2").arg(preg->getOffset()).arg(preg->getName().c_str())); - renderRegisterInfo(pItemHead, preg); + pItemHead->setText(0, QString("Register %1 %2").arg(preg->getOffset()).arg(preg->getName().c_str())); + renderRegisterItem(pItemHead, preg); } } break; } @@ -5889,7 +6011,7 @@ CFrmMdf::editBitDefinition(void) } str += "}"; pItem->setText(0, str); - renderBitInfo(pItem, pbit); + renderBitItem(pItem, pbit); } } break; @@ -5918,7 +6040,7 @@ CFrmMdf::editBitDefinition(void) } str += "}"; pItemHead->setText(0, str); - renderBitInfo(pItemHead, pbit); + renderBitItem(pItemHead, pbit); } } break; @@ -6094,7 +6216,7 @@ CFrmMdf::editValueDefinition(void) else if ((nullptr != pItemHeadHead) && (mdf_type_remotevar == pItemHeadHead->getObjectType())) { CMDF_RemoteVariable* prval = (CMDF_RemoteVariable*)pItem->getObject(); CDlgMdfValueList dlg(this); - //dlg.initDialogData(prval); + // dlg.initDialogData(prval); if (QDialog::Accepted == dlg.exec()) { // Redraw all register items - We do not know changes QList childrenList = pItem->takeChildren(); @@ -6134,7 +6256,7 @@ CFrmMdf::editValueDefinition(void) childrenList.clear(); QString str = QString("Value: %1").arg(pvalue->getName().c_str()); pItem->setText(0, str); - renderValueInfo(pItem, pvalue); + renderValueItem(pItem, pvalue); } } break; @@ -6159,7 +6281,7 @@ CFrmMdf::editValueDefinition(void) childrenList.clear(); QString str = QString("Value: %1").arg(pvalue->getName().c_str()); pItemHead->setText(0, str); - renderValueInfo(pItemHead, pvalue); + renderValueItem(pItemHead, pvalue); } } break; @@ -6340,9 +6462,10 @@ CFrmMdf::editRemoteVariable(void) delete item; } childrenList.clear(); - QString str = QString("Remote variable: %1").arg(pvar->getName().c_str()); + QString str = QString("%1 %2 - %3").arg(CDlgMdfRemoteVar::pre_str_remote_variable).arg(0).arg(pvar->getName().c_str()); + //str = QString("%1 %2 - %3").arg(CDlgMdfRemoteVar::pre_str_remote_variable).arg(i).arg(pvar->getName().c_str()); pItem->setText(0, str); - renderRemoteVariableInfo(pItem, pvar); + renderRemoteVariableItem(pItem, pvar); } } break; @@ -6366,7 +6489,7 @@ CFrmMdf::editRemoteVariable(void) } childrenList.clear(); pItemHead->setText(0, QString("%1 %2").arg(CDlgMdfRemoteVar::pre_str_remote_variable).arg(prvar->getName().c_str())); - renderRemoteVariableInfo(pItemHead, prvar); + renderRemoteVariableItem(pItemHead, prvar); } } break; } diff --git a/src/cfrmmdf.h b/src/cfrmmdf.h index 5004efad..7b4f9783 100644 --- a/src/cfrmmdf.h +++ b/src/cfrmmdf.h @@ -240,6 +240,9 @@ public slots: /// Delete file object void deleteFile(void); + /// Edit register info + void addRegister(void); + /// Edit register info void editRegister(void); @@ -316,7 +319,7 @@ public slots: @param pbit Object holding bit info */ void - renderBitInfo(QMdfTreeWidgetItem* pItemParent, CMDF_Bit* pbit); + renderBitItem(QMdfTreeWidgetItem* pItemParent, CMDF_Bit* pbit); /*! Fill value list info @@ -334,7 +337,7 @@ public slots: @param pvalue Object holding value info */ void - renderValueInfo(QMdfTreeWidgetItem* pItemParent, CMDF_Value* pvalue); + renderValueItem(QMdfTreeWidgetItem* pItemParent, CMDF_Value* pvalue); /*! Fill in register info @@ -343,7 +346,7 @@ public slots: @preg Pointer to register definition */ void - renderRegisterInfo(QTreeWidgetItem* pParent, CMDF_Register* preg); + renderRegisterItem(QTreeWidgetItem* pParent, CMDF_Register* preg); /*! Render all registers @@ -359,7 +362,7 @@ public slots: @preg Pointer to remote variable definition */ void - renderRemoteVariableInfo(QTreeWidgetItem* pParent, CMDF_RemoteVariable* pvar); + renderRemoteVariableItem(QTreeWidgetItem* pParent, CMDF_RemoteVariable* pvar); /*! Render all remote variables