Skip to content

Commit

Permalink
File save XML/JSON up to file section
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Feb 29, 2024
1 parent 8769e47 commit d5d46af
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 44 deletions.
97 changes: 54 additions & 43 deletions src/cfrmmdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ CFrmMdf::CFrmMdf(QWidget* parent, const char* path)
// Open has been selected in the menu - Open new MDF file
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openMdf()));

// Save has been selected in the menu - Save MDF file on XML format
connect(ui->actionSave_XML, SIGNAL(triggered()), this, SLOT(saveMdf_XML()));

// Save has been selected in the menu - Save MDF file on JSON format
connect(ui->actionSave_JSON, SIGNAL(triggered()), this, SLOT(saveMdf_JSON()));

// Open has been selected in the menu - Edit Module info
connect(ui->actionEdit_item, SIGNAL(triggered()), this, SLOT(editItem()));

Expand Down Expand Up @@ -281,6 +287,52 @@ CFrmMdf::openMdf(void)
}
}

///////////////////////////////////////////////////////////////////////////////
// saveMdf_XML
//

void
CFrmMdf::saveMdf_XML()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Open Module Description File (MDF)"),
"/usr/local/src/VSCP/vscp-works-qt/mdf/ttt.xml",
tr("MDF Files (*.mdf *.json *.xml);;All Files (*.*)"));

if (fileName.length()) {
qInfo() << "Selected MDF filename: " << fileName;
int rv = m_mdf.save(fileName.toStdString(), MDF_FORMAT_XML);
if (VSCP_ERROR_SUCCESS != rv) {
spdlog::error("Failed to save MDF file {0}", fileName.toStdString());
QMessageBox::warning(this, APPNAME, tr("Failed to save MDF file."));
return;
}
}
}

///////////////////////////////////////////////////////////////////////////////
// saveMdf_JSON
//

void
CFrmMdf::saveMdf_JSON()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Module Description File (MDF)"),
"/usr/local/src/VSCP/vscp-works-qt/mdf/ttt.json",
tr("MDF Files (*.mdf *.json *.xml);;All Files (*.*)"));

if (fileName.length()) {
qInfo() << "Selected MDF filename: " << fileName;
int rv = m_mdf.save(fileName.toStdString(), MDF_FORMAT_JSON);
if (VSCP_ERROR_SUCCESS != rv) {
spdlog::error("Failed to save MDF file {0}", fileName.toStdString());
QMessageBox::warning(this, APPNAME, tr("Failed to save MDF file."));
return;
}
}
}

///////////////////////////////////////////////////////////////////////////////
// accepted
//
Expand Down Expand Up @@ -6413,8 +6465,6 @@ CFrmMdf::deleteBitDefinition(void)
}
childrenList.clear();

// std::deque<CMDF_Register*>* pregisters = m_mdf.getRegisterObjList();

// Find element and delete it
for (std::deque<CMDF_Bit*>::iterator it = prvar->getListBits()->begin(); it != prvar->getListBits()->end();) {
if (*it == pItem->getObject()) {
Expand Down Expand Up @@ -6792,10 +6842,8 @@ CFrmMdf::deleteValueDefinition(void)

pItemHead->removeChild(pItem);
}
else if ((nullptr != pItemHead) && (mdf_type_alarm == pItemHead->getObjectType())) {
}
else if ((nullptr != pItemHeadHead) && (mdf_type_action_param_item == pItemHeadHead->getObjectType())) {

// Get action parameter
CMDF_ActionParameter* pactpar = (CMDF_ActionParameter*)pItemHeadHead->getObject();

Expand Down Expand Up @@ -6849,7 +6897,7 @@ CFrmMdf::deleteValueDefinition(void)
pItemHead->removeChild(pItem);
}
else if ((mdf_type_event_data_item == pItemHeadHead->getObjectType()) && (mdf_type_value == pItemHead->getObjectType())) {

// Get event data parameter
CMDF_EventData* pevdata = (CMDF_EventData*)pItemHeadHead->getObject();

Expand All @@ -6876,43 +6924,6 @@ CFrmMdf::deleteValueDefinition(void)
pItemHead->removeChild(pItem);
}
} break;

// case mdf_type_value_sub_item: {

// QMdfTreeWidgetItem* pItemHeadHead = (QMdfTreeWidgetItem*)pItemHead->parent();
// if ((nullptr == pItemHeadHead) || (nullptr == (CMDF_Register*)pItemHeadHead->getObject())) {
// return;
// }

// if ((nullptr != pItemHeadHeadHead) && (mdf_type_register == pItemHeadHeadHead->getObjectType())) {

// CMDF_Register* preg = (CMDF_Register*)pItemHeadHead->getObject();
// QList<QTreeWidgetItem*> childrenList = pItemHead->takeChildren();
// // Remove children
// for (qsizetype i = 0; i < childrenList.size(); ++i) {
// QMdfTreeWidgetItem* item = (QMdfTreeWidgetItem*)childrenList.at(i);
// delete item;
// }
// childrenList.clear();

// std::deque<CMDF_Register*>* pregisters = m_mdf.getRegisterObjList();
// // Find element and delete it
// std::deque<CMDF_Value*>* pvalues = preg->getListValues();
// // Find element and delete it
// for (std::deque<CMDF_Value*>::iterator it = preg->getListValues()->begin(); it != preg->getListValues()->end();) {
// if (*it == pItem->getObject()) {
// CMDF_Value* pvalue = *it;
// preg->getListValues()->erase(it);
// delete pvalue;
// break;
// }
// ++it;
// }

// pItemHeadHead->removeChild(pItemHead);
// }

// } break;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/cfrmmdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ public slots:
/// Load MDF for selected node
void loadMdf(void);

/// Save MDF to external storage on XML format
void saveMdf_XML(void);

/// Save MDF to external storage on JSON format
void saveMdf_JSON(void);

/*!
Find next MDF type item in tree
@param Pointer to MDF widget item
Expand Down
20 changes: 19 additions & 1 deletion src/cfrmmdf.ui
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
<addaction name="actionNew"/>
<addaction name="actionDownload_MDF"/>
<addaction name="actionOpen"/>
<addaction name="actionReload_MDF"/>
<addaction name="actionSave_XML"/>
<addaction name="actionSave_JSON"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
</widget>
Expand Down Expand Up @@ -297,7 +300,7 @@
</action>
<action name="actionOpen">
<property name="text">
<string>Open MDF...</string>
<string>Load MDF...</string>
</property>
<property name="toolTip">
<string>Open existing MDF</string>
Expand Down Expand Up @@ -354,6 +357,21 @@
<string>Ctrl+D</string>
</property>
</action>
<action name="actionSave_XML">
<property name="text">
<string>Save MDF on XML format...</string>
</property>
</action>
<action name="actionReload_MDF">
<property name="text">
<string>Reload MDF</string>
</property>
</action>
<action name="actionSave_JSON">
<property name="text">
<string>Save MDF on JSON format...</string>
</property>
</action>
</widget>
<resources>
<include location="vscpworks.qrc"/>
Expand Down

0 comments on commit d5d46af

Please sign in to comment.