Kaynağa Gözat

Add cmd line option for generating a GUI from XML

Sascha Zelzer 11 yıl önce
ebeveyn
işleme
4cfeaaf79e

+ 6 - 0
Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp

@@ -49,6 +49,7 @@ int main(int argc, char** argv)
   cmdLineParser.setStrictModeEnabled(true);
 
   cmdLineParser.addArgument("module", "", QVariant::String, "Path to a CLI module (executable), and show the generated GUI.");
+  cmdLineParser.addArgument("gui", "", QVariant::String, "Path to a CLI XML file, and show the generated GUI.");
   cmdLineParser.addArgument("validate-module", "", QVariant::String, "Path to a CLI module (executable), and validate the XML.");
   cmdLineParser.addArgument("validate-xml", "", QVariant::String, "Path to a CLI XML file, and validate the XML.");
   cmdLineParser.addArgument("string", "", QVariant::String, "An XML string to validate. Be careful to quote correctly." );
@@ -191,6 +192,11 @@ int main(int argc, char** argv)
     mainWindow.addModule(args["module"].toString());
   }
 
+  if (args.contains("gui"))
+  {
+    mainWindow.addModule(QString("xmlchecker://") + args["gui"].toString());
+  }
+
   mainWindow.show();
 
   return myApp.exec();

+ 8 - 1
Libs/CommandLineModules/Backend/XMLChecker/ctkCmdLineModuleBackendXMLChecker.cpp

@@ -24,6 +24,7 @@
 #include "ctkCmdLineModuleFrontend.h"
 #include "ctkCmdLineModuleFuture.h"
 #include <QUrl>
+#include <QFile>
 #include <QString>
 #include <QDateTime>
 #include <ctkUtils.h>
@@ -105,8 +106,14 @@ qint64 ctkCmdLineModuleBackendXMLChecker::timeStamp(const QUrl & /*location*/) c
 
 
 //----------------------------------------------------------------------------
-QByteArray ctkCmdLineModuleBackendXMLChecker::rawXmlDescription(const QUrl &/*location*/)
+QByteArray ctkCmdLineModuleBackendXMLChecker::rawXmlDescription(const QUrl& location)
 {
+  if (location.isValid())
+  {
+    QFile file(location.path());
+    file.open(QFile::ReadOnly);
+    return file.readAll();
+  }
   return d->m_HardCodedXML.toAscii();
 }