summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <[email protected]>2017-05-19 10:15:38 +0200
committerRalf Habacker <[email protected]>2017-05-19 10:16:40 +0200
commit98fa381f4e94633fea2a716361d357718c432e43 (patch)
tree93bd4f29d30667caf28282d5a41e039b609de9ab
parent7298e955c24953eae98740ed560f46f4891fc37c (diff)
Place artifacts into folder structure.
BUG:379998 FIXED-IN:2.22.80 (KDE Applications 17.07.80) Signed-off-by: Ralf Habacker <[email protected]>
-rw-r--r--umbrello/codeimport/classimport.cpp8
-rw-r--r--umbrello/codeimport/classimport.h2
-rw-r--r--umbrello/codeimport/cppimport.cpp1
-rw-r--r--umbrello/codeimport/import_utils.cpp39
-rw-r--r--umbrello/codeimport/import_utils.h7
-rw-r--r--umbrello/codeimport/kdevcppparser/cpptree2uml.cpp31
-rw-r--r--umbrello/codeimport/kdevcppparser/cpptree2uml.h4
-rw-r--r--umbrello/main.cpp4
-rw-r--r--umbrello/uml.cpp18
-rw-r--r--umbrello/uml.h2
10 files changed, 92 insertions, 24 deletions
diff --git a/umbrello/codeimport/classimport.cpp b/umbrello/codeimport/classimport.cpp
index d9b5aa8..3196b74 100644
--- a/umbrello/codeimport/classimport.cpp
+++ b/umbrello/codeimport/classimport.cpp
@@ -13,8 +13,9 @@
// app includes
#include "debug_utils.h"
-#include "umldoc.h"
+#include "folder.h"
#include "uml.h"
+#include "umldoc.h"
#include "idlimport.h"
#include "pythonimport.h"
#include "javaimport.h"
@@ -112,6 +113,11 @@ bool ClassImport::importFile(const QString& fileName)
return parseFile(fileName);
}
+void ClassImport::setRootPath(const QString &path)
+{
+ m_rootPath = path;
+}
+
/**
* Write info to a logger or to the debug output.
* @param file the name of the parsed file
diff --git a/umbrello/codeimport/classimport.h b/umbrello/codeimport/classimport.h
index 167c997..10bbb2e 100644
--- a/umbrello/codeimport/classimport.h
+++ b/umbrello/codeimport/classimport.h
@@ -30,6 +30,7 @@ public:
bool importFiles(const QStringList& fileNames);
bool importFile(const QString& fileName);
+ void setRootPath(const QString &path);
/**
* Return state of the importer. It may be disabled because of
@@ -65,6 +66,7 @@ protected:
CodeImpThread* m_thread; ///< thread in which the work of importing is done
bool m_enabled; ///< state of importer
+ QString m_rootPath; ///< root path of import
};
#endif
diff --git a/umbrello/codeimport/cppimport.cpp b/umbrello/codeimport/cppimport.cpp
index 765ce6d..a6181fd 100644
--- a/umbrello/codeimport/cppimport.cpp
+++ b/umbrello/codeimport/cppimport.cpp
@@ -99,6 +99,7 @@ void CppImport::feedTheModel(const QString& fileName)
}
ms_seenFiles.append(fileName);
CppTree2Uml modelFeeder(fileName, m_thread);
+ modelFeeder.setRootPath(m_rootPath);
modelFeeder.parseTranslationUnit(*ast);
}
diff --git a/umbrello/codeimport/import_utils.cpp b/umbrello/codeimport/import_utils.cpp
index 2fde35e..bdbd275 100644
--- a/umbrello/codeimport/import_utils.cpp
+++ b/umbrello/codeimport/import_utils.cpp
@@ -550,24 +550,45 @@ void createGeneralization(UMLClassifier *child, UMLClassifier *parent)
}
/**
+ * Create a subdir with the given name.
+ */
+UMLFolder *createSubDir(const QString& name,
+ UMLFolder *parentPkg,
+ const QString &comment)
+{
+ UMLDoc *umldoc = UMLApp::app()->document();
+ if (!parentPkg) {
+ parentPkg = umldoc->rootFolder(Uml::ModelType::Component);
+ }
+
+ UMLObject::ObjectType type = UMLObject::ot_Folder;
+ UMLFolder *o = umldoc->findUMLObjectRaw(parentPkg, name, type)->asUMLFolder();
+ if (o)
+ return o;
+ o = Object_Factory::createUMLObject(type, name, parentPkg, false)->asUMLFolder();
+ if (o)
+ o->setDoc(comment);
+ return o;
+}
+
+
+/**
* Create an artifact with the given name.
*/
UMLObject *createArtifact(const QString& name,
- UMLPackage *parentPkg,
+ UMLFolder *parentPkg,
const QString &comment)
{
- Q_UNUSED(parentPkg);
+ UMLDoc *umldoc = UMLApp::app()->document();
+ if (!parentPkg) {
+ parentPkg = umldoc->rootFolder(Uml::ModelType::Component);
+ }
UMLObject::ObjectType type = UMLObject::ot_Artifact;
- if (!Settings::optionState().codeImportState.createArtifacts)
- return 0;
- UMLDoc *umldoc = UMLApp::app()->document();
- UMLFolder *componentView = umldoc->rootFolder(Uml::ModelType::Component);
- QFileInfo fi(name);
- UMLObject *o = umldoc->findUMLObjectRaw(componentView, fi.fileName(), type);
+ UMLObject *o = umldoc->findUMLObjectRaw(parentPkg, name, type);
if (o)
return o;
- o = Object_Factory::createUMLObject(type, fi.fileName(), componentView, false);
+ o = Object_Factory::createUMLObject(type, name, parentPkg, false);
UMLArtifact *a = o->asUMLArtifact();
a->setDrawAsType(UMLArtifact::file);
a->setDoc(comment);
diff --git a/umbrello/codeimport/import_utils.h b/umbrello/codeimport/import_utils.h
index 2839497..99198b4 100644
--- a/umbrello/codeimport/import_utils.h
+++ b/umbrello/codeimport/import_utils.h
@@ -12,6 +12,7 @@
#define IMPORT_UTILS_H
#include "basictypes.h"
+#include "folder.h"
#include "umlattributelist.h"
#include <QStringList>
@@ -32,8 +33,12 @@ class QMimeData;
*/
namespace Import_Utils {
+ UMLFolder *createSubDir(const QString& name,
+ UMLFolder *parentPkg,
+ const QString &comment = QString());
+
UMLObject *createArtifact(const QString& name,
- UMLPackage *parentPkg = 0,
+ UMLFolder *parentPkg = NULL,
const QString &comment = QString());
UMLObject* createUMLObject(UMLObject::ObjectType type,
diff --git a/umbrello/codeimport/kdevcppparser/cpptree2uml.cpp b/umbrello/codeimport/kdevcppparser/cpptree2uml.cpp
index d7e462b..90df1fa 100644
--- a/umbrello/codeimport/kdevcppparser/cpptree2uml.cpp
+++ b/umbrello/codeimport/kdevcppparser/cpptree2uml.cpp
@@ -38,7 +38,8 @@
#include <QRegExp>
CppTree2Uml::CppTree2Uml(const QString& fileName, CodeImpThread* thread)
- : m_thread(thread)
+ : m_thread(thread),
+ m_rootFolder(0)
{
clear();
QDir dir(fileName);
@@ -66,10 +67,36 @@ void CppTree2Uml::clear()
m_anon = 0;
}
+void CppTree2Uml::setRootPath(const QString &rootPath)
+{
+ m_rootPath = rootPath;
+ if (Settings::optionState().codeImportState.createArtifacts) {
+ if (!m_rootFolder) {
+ UMLDoc *umldoc = UMLApp::app()->document();
+ UMLFolder *componentView = umldoc->rootFolder(Uml::ModelType::Component);
+ if (!m_rootPath.isEmpty()) {
+ UMLFolder *root = Import_Utils::createSubDir(m_rootPath, componentView);
+ m_rootFolder = root;
+ } else {
+ m_rootFolder = componentView;
+ }
+ }
+ }
+}
+
void CppTree2Uml::parseTranslationUnit(const ParsedFile &file)
{
clear();
- Import_Utils::createArtifact(file.fileName(), 0, file->comment());
+ if (Settings::optionState().codeImportState.createArtifacts) {
+ QFileInfo fi(file.fileName());
+
+ UMLFolder *parent = m_rootFolder;
+ QString path = fi.path().replace(m_rootPath, QLatin1String(""));
+ if (!path.isEmpty())
+ parent = Import_Utils::createSubDir(path.mid(1), m_rootFolder);
+
+ Import_Utils::createArtifact(fi.fileName(), parent, file->comment());
+ }
TreeParser::parseTranslationUnit(file);
}
diff --git a/umbrello/codeimport/kdevcppparser/cpptree2uml.h b/umbrello/codeimport/kdevcppparser/cpptree2uml.h
index 030ecd4..bc87ebf 100644
--- a/umbrello/codeimport/kdevcppparser/cpptree2uml.h
+++ b/umbrello/codeimport/kdevcppparser/cpptree2uml.h
@@ -19,6 +19,7 @@
// fwd decls
class CodeImpThread;
class UMLClassifier;
+class UMLFolder;
class UMLOperation;
class UMLPackage;
@@ -29,6 +30,7 @@ public:
virtual ~CppTree2Uml();
void clear();
+ void setRootPath(const QString &rootPath);
//FileDom file() { return m_file; }
// translation-unit
@@ -89,6 +91,8 @@ private:
int m_nsCnt; ///< stack top for m_currentNamespace
int m_clsCnt; ///< stack top for m_currentClass
CodeImpThread* m_thread;
+ QString m_rootPath; ///< root path of project
+ UMLFolder *m_rootFolder;
private:
CppTree2Uml(const CppTree2Uml& source);
diff --git a/umbrello/main.cpp b/umbrello/main.cpp
index dc260dd..488b5cb 100644
--- a/umbrello/main.cpp
+++ b/umbrello/main.cpp
@@ -217,7 +217,7 @@ int main(int argc, char *argv[])
QStringList importList = args->values(IMPORT_FILES);
if (importList.size() > 0) {
uml->newDocument();
- uml->importFiles(&importList);
+ uml->importFiles(importList);
}
}
#else
@@ -226,7 +226,7 @@ int main(int argc, char *argv[])
for (int i = 0; i < args->count(); i++)
importList.append(args->url(i).toLocalFile());
uml->newDocument();
- uml->importFiles(&importList);
+ uml->importFiles(importList);
}
#endif
else
diff --git a/umbrello/uml.cpp b/umbrello/uml.cpp
index 3f0ebda..eead106 100644
--- a/umbrello/uml.cpp
+++ b/umbrello/uml.cpp
@@ -2873,16 +2873,18 @@ void UMLApp::slotUpdateViews()
/**
* Import the source files that are in fileList.
*/
-void UMLApp::importFiles(QStringList* fileList)
+void UMLApp::importFiles(QStringList &fileList, const QString &rootPath)
{
- if (!fileList->isEmpty()) {
- listView()->setUpdatesEnabled(false);
- logWindow()->setUpdatesEnabled(false);
+ if (!fileList.isEmpty()) {
+ bool saveState = listView()->parentWidget()->isVisible();
+ listView()->parentWidget()->setVisible(false);
+ logWindow()->parentWidget()->setVisible(true);
logWindow()->clear();
- const QString& firstFile = fileList->first();
+ const QString& firstFile = fileList.first();
ClassImport *classImporter = ClassImport::createImporterByFileExt(firstFile);
- classImporter->importFiles(*fileList);
+ classImporter->setRootPath(rootPath);
+ classImporter->importFiles(fileList);
delete classImporter;
m_doc->setLoading(false);
// Modification is set after the import is made, because the file was modified when adding the classes.
@@ -2909,7 +2911,7 @@ void UMLApp::slotImportClass()
QStringList files = KFileDialog::getOpenFileNames(KUrl(), f, this, i18n("Select file(s) to import:"));
#endif
if (!files.isEmpty()) {
- importFiles(&files);
+ importFiles(files);
}
}
@@ -2944,7 +2946,7 @@ void UMLApp::slotImportProject()
if (!dir.isEmpty()) {
QStringList filter = Uml::ProgrammingLanguage::toExtensions(UMLApp::app()->activeLanguage());
getFiles(listFile, dir, filter);
- importFiles(&listFile);
+ importFiles(listFile, dir);
}
}
diff --git a/umbrello/uml.h b/umbrello/uml.h
index 9bb013f..c49cdf4 100644
--- a/umbrello/uml.h
+++ b/umbrello/uml.h
@@ -195,7 +195,7 @@ public:
QString activeLanguageScopeSeparator();
KConfig* config();
- void importFiles(QStringList* fileList);
+ void importFiles(QStringList& fileList, const QString &rootPath = QString());
protected:
virtual void keyPressEvent(QKeyEvent* e);