Commit 6272e5ec authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Move generator related stuff in base class DotGenerator

CCBUG:414595
parent 9fd41006
......@@ -142,6 +142,56 @@ DotGenerator::DotGenerator()
m_usePosition(false),
m_useFullNodeLabels(true)
{
Settings::OptionState& optionState = Settings::optionState();
if (optionState.autoLayoutState.autoDotPath) {
m_dotPath = currentDotPath();
}
else if (!optionState.autoLayoutState.dotPath.isEmpty()) {
m_dotPath = optionState.autoLayoutState.dotPath;
}
}
/**
* Return the path where dot is installed.
*
* @return string with dot path
*/
QString DotGenerator::currentDotPath()
{
#if QT_VERSION >= 0x050000
QString executable = QStandardPaths::findExecutable(QLatin1String("dot"));
#else
QString executable = KStandardDirs::findExe(QLatin1String("dot"));
#endif
if (!executable.isEmpty()) {
QFileInfo fi(executable);
return fi.absolutePath();
}
#ifdef Q_OS_WIN
// search for dot installation
QString appDir(QLatin1String(qgetenv("ProgramFiles").constData()));
QDir dir(appDir);
dir.setFilter(QDir::Dirs);
dir.setNameFilters(QStringList() << QLatin1String("Graphviz*"));
dir.setSorting(QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
if (list.size() > 0) {
QString dotPath = list.at(0).absoluteFilePath();
QString exePath = QFile::exists(dotPath + QLatin1String("\\bin")) ? dotPath + QLatin1String("\\bin") : dotPath;
return QFile::exists(exePath + QLatin1String("\\dot.exe")) ? exePath : QString();
}
#endif
return QString();
}
void DotGenerator::setGeneratorName(const QString &name)
{
m_generator = name;
}
QString DotGenerator::generatorFullPath()
{
return m_dotPath + QLatin1Char('/') + m_generator;
}
/**
......
......@@ -37,6 +37,11 @@ public:
bool createDotFile(UMLScene *scene, const QString &fileName, const QString &variant = QLatin1String("default"));
static QString currentDotPath();
void setGeneratorName(const QString &name);
QString generatorFullPath();
int generatorVersion();
protected:
bool findItem(QStringList &params, const QString &search);
QString fixID(const QString &_id);
......@@ -50,6 +55,7 @@ protected:
QString m_generator; ///< name of graphviz generator
bool m_usePosition; ///< use position tag from dot (not used yet)
bool m_useFullNodeLabels; ///< use full node labels
QString m_dotPath; ///< contains path to generator executable
friend QDebug operator<<(QDebug out, DotGenerator &c);
};
......
......@@ -98,49 +98,9 @@ LayoutGenerator::LayoutGenerator()
*/
bool LayoutGenerator::isEnabled()
{
Settings::OptionState& optionState = Settings::optionState();
if (optionState.autoLayoutState.autoDotPath) {
m_dotPath = currentDotPath();
}
else if (!optionState.autoLayoutState.dotPath.isEmpty()) {
m_dotPath = optionState.autoLayoutState.dotPath;
}
return !m_dotPath.isEmpty();
}
/**
* Return the path where dot is installed.
*
* @return string with dot path
*/
QString LayoutGenerator::currentDotPath()
{
#if QT_VERSION >= 0x050000
QString executable = QStandardPaths::findExecutable(QLatin1String("dot"));
#else
QString executable = KStandardDirs::findExe(QLatin1String("dot"));
#endif
if (!executable.isEmpty()) {
QFileInfo fi(executable);
return fi.absolutePath();
}
#ifdef Q_OS_WIN
// search for dot installation
QString appDir(QLatin1String(qgetenv("ProgramFiles").constData()));
QDir dir(appDir);
dir.setFilter(QDir::Dirs);
dir.setNameFilters(QStringList() << QLatin1String("Graphviz*"));
dir.setSorting(QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
if (list.size() > 0) {
QString dotPath = list.at(0).absoluteFilePath();
QString exePath = QFile::exists(dotPath + QLatin1String("\\bin")) ? dotPath + QLatin1String("\\bin") : dotPath;
return QFile::exists(exePath + QLatin1String("\\dot.exe")) ? exePath : QString();
}
#endif
return QString();
}
/**
* generate layout and apply it to the given diagram.
*
......@@ -187,7 +147,7 @@ bool LayoutGenerator::generate(UMLScene *scene, const QString &variant)
if (!createDotFile(scene, in.fileName(), variant))
return false;
QString executable = m_dotPath + QLatin1Char('/') + m_generator;
QString executable = generatorFullPath();
QProcess p;
QStringList args;
......
......@@ -46,7 +46,6 @@ public:
LayoutGenerator();
bool isEnabled();
static QString currentDotPath();
bool generate(UMLScene *scene, const QString &variant = QString());
bool apply(UMLScene *scene);
static bool availableConfigFiles(UMLScene *scene, QHash<QString,QString> &configFiles);
......@@ -61,7 +60,6 @@ protected:
NodeType m_nodes; ///< list of nodes found in parsed dot file
EdgeType m_edges; ///< list of edges found in parsed dot file
QHash<QString, QPointF> m_edgeLabelPosition; ///< contains global node parameters
QString m_dotPath; ///< contains path to dot executable
friend QDebug operator<<(QDebug out, LayoutGenerator &c);
};
......
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