Skip to content

Commit

Permalink
Generate directories for sub models when saving meta-model.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 17, 2015
1 parent 3fdd91d commit 0d8476c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1264,8 +1264,8 @@ bool LibraryTreeWidget::saveTLMLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream textStream(&file);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << pLibraryTreeNode->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText();
textStream.setGenerateByteOrderMark(false);QString metaModelXml = pLibraryTreeNode->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText();
textStream << metaModelXml;
file.close();
/* mark the file as saved and update the labels. */
pLibraryTreeNode->setIsSaved(true);
Expand All @@ -1274,6 +1274,21 @@ bool LibraryTreeWidget::saveTLMLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode
pLibraryTreeNode->getModelWidget()->setWindowTitle(pLibraryTreeNode->getNameStructure());
pLibraryTreeNode->getModelWidget()->setModelFilePathLabel(fileName);
}
// Create folders for the submodels and copy there source file in them.
QDomDocument xml;
xml.setContent(metaModelXml);
QDomNodeList subModels = xml.elementsByTagName("SubModel");
for (int i = 0; i < subModels.size(); i++) {
QDomElement subModel = subModels.at(i).toElement();
QString directoryName = subModel.attribute("Name");
/*! @todo We need to have a complete filename here to copy the file. */
QString modelFile = subModel.attribute("ModelFile");
QFileInfo fileInfo(fileName);
QString directoryPath = fileInfo.absoluteDir().absolutePath() + "/" + directoryName;
if (!QDir().exists(directoryPath)) {
QDir().mkpath(directoryPath);
}
}
} else {
QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
.arg(tr("Unable to save the file. %1").arg(file.errorString())), Helper::ok);
Expand Down

0 comments on commit 0d8476c

Please sign in to comment.