summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-11-20 13:34:09 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-11-24 15:50:02 +0000
commit1fc0866f4fc07b6ae503bdd24c6fe98d0714ed2a (patch)
tree4eceb2c7a653677325c06c972fd0bbf5d5ceda0f
parent635f2a07bb33f1a28b0b3fc2d0d997f32e9dc7fc (diff)
downloadqtactiveqt-1fc0866f4fc07b6ae503bdd24c6fe98d0714ed2a.tar.gz
Testcon: Add command line options for loading CLSIDs, files and scripts.
Factor out load methods and add command line parser. Task-number: QTBUG-49355 Change-Id: Ic7c15c19e0b51e666fc13d74751713ccdc97dd9d Reviewed-by: Fredrik Orderud <forderud@gmail.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r--tools/testcon/main.cpp24
-rw-r--r--tools/testcon/mainwindow.cpp71
-rw-r--r--tools/testcon/mainwindow.h4
3 files changed, 82 insertions, 17 deletions
diff --git a/tools/testcon/main.cpp b/tools/testcon/main.cpp
index dda1b3a..56946f6 100644
--- a/tools/testcon/main.cpp
+++ b/tools/testcon/main.cpp
@@ -35,6 +35,8 @@
#include <QApplication>
#include <QAxFactory>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
QAXFACTORY_DEFAULT(MainWindow,
QLatin1String("{5f5ce700-48a8-47b1-9b06-3b7f79e41d7c}"),
@@ -48,8 +50,30 @@ QT_USE_NAMESPACE
int main( int argc, char **argv )
{
QApplication app( argc, argv );
+ QCoreApplication::setApplicationName(QLatin1String("TestCon"));
+ QCoreApplication::setOrganizationName(QLatin1String("QtProject"));
+ QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QLatin1String("ActiveX Control Test Container"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption scriptOption(QLatin1String("script"),
+ QLatin1String("A script to load."),
+ QLatin1String("script"));
+ parser.addOption(scriptOption);
+ parser.addPositionalArgument(QLatin1String("clsid/file"),
+ QLatin1String("The clsid/file to show."));
+ parser.process(app);
MainWindow mw;
+ foreach (const QString &a, parser.positionalArguments()) {
+ if (a.startsWith(QLatin1Char('{')) && a.endsWith(QLatin1Char('}')))
+ mw.addControlFromClsid(a);
+ else
+ mw.addControlFromFile(a);
+ }
+ if (parser.isSet(scriptOption))
+ mw.loadScript(parser.value(scriptOption));
mw.show();
return app.exec();;
diff --git a/tools/testcon/mainwindow.cpp b/tools/testcon/mainwindow.cpp
index cc03f5a..5c2ff71 100644
--- a/tools/testcon/mainwindow.cpp
+++ b/tools/testcon/mainwindow.cpp
@@ -111,29 +111,48 @@ QList<QAxWidget *> MainWindow::axWidgets() const
return result;
}
-void MainWindow::on_actionFileNew_triggered()
+bool MainWindow::addControlFromClsid(const QString &clsid)
{
- QAxSelect select(this);
- if (select.exec()) {
- QAxWidget *container = new QAxWidget;
- container->setControl(select.clsid());
+ QAxWidget *container = new QAxWidget;
+ const bool result = container->setControl(clsid);
+ if (result) {
container->setObjectName(container->windowTitle());
mdiArea->addSubWindow(container);
container->show();
+ updateGUI();
+ } else {
+ delete container;
+ QMessageBox::information(this,
+ tr("Error Loading Control"),
+ tr("The control \"%1\" could not be loaded.").arg(clsid));
}
- updateGUI();
+ return result;
+}
+
+void MainWindow::on_actionFileNew_triggered()
+{
+ QAxSelect select(this);
+ while (select.exec() && !addControlFromClsid(select.clsid())) { }
}
void MainWindow::on_actionFileLoad_triggered()
{
- QString fname = QFileDialog::getOpenFileName(this, tr("Load"), QString(), QLatin1String("*.qax"));
- if (fname.isEmpty())
- return;
+ while (true) {
+ const QString fname = QFileDialog::getOpenFileName(this, tr("Load"), QString(), QLatin1String("*.qax"));
+ if (fname.isEmpty() || addControlFromFile(fname))
+ break;
+ }
+}
- QFile file(fname);
+bool MainWindow::addControlFromFile(const QString &fileName)
+{
+ QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
- QMessageBox::information(this, tr("Error Loading File"), tr("The file could not be opened for reading.\n%1").arg(fname));
- return;
+ QMessageBox::information(this,
+ tr("Error Loading File"),
+ tr("The file could not be opened for reading.\n%1\n%2")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString()));
+ return false;
}
QAxWidget *container = new QAxWidget(mdiArea);
@@ -146,6 +165,7 @@ void MainWindow::on_actionFileLoad_triggered()
container->show();
updateGUI();
+ return true;
}
void MainWindow::on_actionFileSave_triggered()
@@ -320,14 +340,29 @@ void MainWindow::on_actionScriptingRun_triggered()
#endif
}
+#ifdef QT_NO_QAXSCRIPT
+static inline void noScriptMessage(QWidget *parent)
+{
+ QMessageBox::information(parent, MainWindow::tr("Function not available"),
+ MainWindow::tr("QAxScript functionality is not available with this compiler."));
+}
+#endif // !QT_NO_QAXSCRIPT
+
void MainWindow::on_actionScriptingLoad_triggered()
{
#ifndef QT_NO_QAXSCRIPT
QString file = QFileDialog::getOpenFileName(this, tr("Open Script"), QString(), QAxScriptManager::scriptFileFilter());
- if (file.isEmpty())
- return;
+ if (!file.isEmpty())
+ loadScript(file);
+#else // !QT_NO_QAXSCRIPT
+ noScriptMessage(this);
+#endif
+}
+bool MainWindow::loadScript(const QString &file)
+{
+#ifndef QT_NO_QAXSCRIPT
if (!scripts) {
scripts = new QAxScriptManager(this);
scripts->addObject(this);
@@ -343,9 +378,11 @@ void MainWindow::on_actionScriptingLoad_triggered()
connect(script, &QAxScript::error, this, &MainWindow::logMacro);
actionScriptingRun->setEnabled(true);
}
-#else
- QMessageBox::information(this, tr("Function not available"),
- tr("QAxScript functionality is not available with this compiler."));
+ return script;
+#else // !QT_NO_QAXSCRIPT
+ Q_UNUSED(file)
+ noScriptMessage(this);
+ return false;
#endif
}
diff --git a/tools/testcon/mainwindow.h b/tools/testcon/mainwindow.h
index 68b85b1..f88106f 100644
--- a/tools/testcon/mainwindow.h
+++ b/tools/testcon/mainwindow.h
@@ -57,6 +57,10 @@ public:
MainWindow(QWidget *parent = 0);
~MainWindow();
+ bool addControlFromClsid(const QString &clsid);
+ bool addControlFromFile(const QString &fileName);
+ bool loadScript(const QString &file);
+
protected slots:
void on_actionFileNew_triggered();
void on_actionFileLoad_triggered();