utility: loading project via commanlineargument

loading a project via commanline with --project or -p argument
This commit is contained in:
Andreas Stallinger
2016-01-12 13:24:04 +01:00
parent b8faa5506d
commit 46a629358c
7 changed files with 110 additions and 2 deletions
+9
View File
@@ -9,6 +9,7 @@
#include "Application.h"
#include "includes.h" // defines 'void setup(int argc, char *argv[])'
#include "qt/commandline/QtCommandLineParser.h"
#include "qt/window/QtMainWindow.h"
#include "qt/window/QtSplashScreen.h"
#include "qt/network/QtNetworkFactory.h"
@@ -38,6 +39,12 @@ int main(int argc, char *argv[])
setup(argc, argv);
QApplication qtApp(argc, argv);
QApplication::setApplicationName("Coati");
QApplication::setApplicationVersion(version.toDisplayString().c_str());
QtCommandLineParser commandLineParser;
commandLineParser.setup();
commandLineParser.process(qtApp);
qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps);
@@ -63,5 +70,7 @@ int main(int argc, char *argv[])
delete splash;
}
commandLineParser.parseCommandline();
return qtApp.exec();
}
+1
View File
@@ -91,6 +91,7 @@ void Application::loadProject(const FilePath& projectSettingsFilePath)
m_project->loadProject(projectSettingsFilePath);
m_mainView->updateRecentProjectMenu();
m_mainView->hideStartScreen();
}
void Application::refreshProject()
+8 -1
View File
@@ -215,7 +215,7 @@ void ConfigManager::setValues(const std::string& key, const std::vector<bool>& v
setValues(key, stringValues);
}
void ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
bool ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
{
std::string text = textAccess->getText();
@@ -225,6 +225,11 @@ void ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
{
TiXmlHandle docHandle(&doc);
TiXmlNode *rootNode = docHandle.FirstChild("config").ToNode();
if(rootNode == nullptr)
{
LOG_ERROR("No rootelement 'config' in the configfile");
return false;
}
for (TiXmlNode *childNode = rootNode->FirstChild(); childNode; childNode = childNode->NextSibling())
{
parseSubtree(childNode, "");
@@ -233,7 +238,9 @@ void ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
else
{
LOG_ERROR("Unable to load file.");
return false;
}
return true;
}
void ConfigManager::save(const std::string filepath)
+1 -1
View File
@@ -37,7 +37,7 @@ public:
void setValues(const std::string& key, const std::vector<float>& values);
void setValues(const std::string& key, const std::vector<bool>& values);
void load(const std::shared_ptr<TextAccess> textAccess);
bool load(const std::shared_ptr<TextAccess> textAccess);
void save(const std::string filepath);
std::string toString();
+3
View File
@@ -5,6 +5,9 @@ add_files(
platform_includes/includesMac.h
platform_includes/includesWindows.h
qt/commandline/QtCommandLineParser.cpp
qt/commandline/QtCommandLineParser.h
qt/element/QtAutocompletionList.cpp
qt/element/QtAutocompletionList.h
qt/element/QtCodeArea.cpp
@@ -0,0 +1,69 @@
#include "qt/commandline/QtCommandLineParser.h"
#include "utility/ConfigManager.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
QtCommandLineParser::QtCommandLineParser()
{
}
QtCommandLineParser::~QtCommandLineParser()
{
}
void QtCommandLineParser::setup()
{
setApplicationDescription("Coati helper");
addVersionOption();
addHelpOption();
QCommandLineOption projectOption(QStringList() << "p" << "project",
QCoreApplication::translate("main", "Load Coati with the a Coatiprojectfile <CoatiProject>."),
QCoreApplication::translate("main", "CoatiProject"));
addOption(projectOption);
}
void QtCommandLineParser::parseCommandline()
{
if(isSet("project"))
{
QString projectfilename = value("project") ;
FilePath projectfile(projectfilename.toStdString());
bool isValidProjectfile = true;
std::stringstream errorstring("Provided Projectfile is not valid: ");
errorstring << "Provided Projectfile('" << projectfile.fileName() << ") ";
if(!projectfile.exists())
{
errorstring << "does not exist";
isValidProjectfile = false;
}
if(projectfile.extension() != ".coatiproject")
{
errorstring << "has a wrong fileending";
isValidProjectfile = false;
}
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
if(!configManager->load(TextAccess::createFromFile(projectfile.str())))
{
errorstring << "could not be loaded";
isValidProjectfile = false;
}
if(isValidProjectfile)
{
MessageLoadProject(projectfile.str()).dispatch();
}
else
{
MessageStatus(errorstring.str(), true).dispatch();
LOG_ERROR(errorstring.str());
}
}
}
@@ -0,0 +1,19 @@
#ifndef QTCOMMANDLINEPARSER_H
#define QTCOMMANDLINEPARSER_H
#include <QCommandLineParser>
#include "Application.h"
class QtCommandLineParser : public QCommandLineParser
{
public:
QtCommandLineParser();
~QtCommandLineParser();
void setup();
void parseCommandline();
private:
};
#endif //QTCOMMANDLINEPARSER_H