Commit 98fa381f authored by Ralf Habacker's avatar Ralf Habacker

Place artifacts into folder structure.

BUG:379998
FIXED-IN:2.22.80 (KDE Applications 17.07.80)
Signed-off-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
parent 7298e955
......@@ -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
......
......@@ -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
......@@ -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);
}
......
......@@ -549,25 +549,46 @@ void createGeneralization(UMLClassifier *child, UMLClassifier *parent)
umldoc->addAssociation(assoc);
}
/**
* 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);
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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
......
......@@ -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);
}
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment