diff options
author | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-05-29 10:09:25 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-06-04 12:10:56 +0000 |
commit | 32bcc3dc5ff0639e80a9a2f0709fbe2c63476b77 (patch) | |
tree | 98f7f184060bcf357fb709da30fbdcd1db1eec6d /src/libs/utils/wizard.cpp | |
parent | 5375e6a10e2298a36a7e5bb1ced6def1f9acd1db (diff) |
Wizards: Add dialog to investigate wizard state
Add an action to trigger it (not bound to any key sequence
by default).
Change-Id: I52ed9107fcbcb8c6b5ae1e4c4768250e405e141a
Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/wizard.cpp')
-rw-r--r-- | src/libs/utils/wizard.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/libs/utils/wizard.cpp b/src/libs/utils/wizard.cpp index 9507425c517..dcfff2959b4 100644 --- a/src/libs/utils/wizard.cpp +++ b/src/libs/utils/wizard.cpp @@ -30,15 +30,19 @@ #include "wizard.h" +#include "algorithm.h" #include "hostosinfo.h" #include "qtcassert.h" #include "wizardpage.h" +#include <QDialog> +#include <QDialogButtonBox> #include <QHash> #include <QIcon> #include <QKeyEvent> #include <QLabel> #include <QMap> +#include <QScrollArea> #include <QVBoxLayout> #include <QVariant> @@ -393,6 +397,79 @@ void Wizard::registerFieldName(const QString &name) d_ptr->m_fieldNames.insert(name); } +QSet<QString> Wizard::fieldNames() const +{ + return d_ptr->m_fieldNames; +} + +QHash<QString, QVariant> Wizard::variables() const +{ + QHash<QString, QVariant> result; + foreach (const QString &f, fieldNames()) { + result.insert(f, field(f)); + } + return result; +} + +QString typeOf(const QVariant &v) +{ + QString result; + switch (v.type()) { + case QVariant::Map: + result = QLatin1String("Object"); + break; + default: + result = QLatin1String(v.typeName()); + } + return result; +} + +void Wizard::showVariables() +{ + QString result = QLatin1String("<table>\n <tr><td>Key</td><td>Type</td><td>Value</td><td>Eval</td></tr>\n"); + QHash<QString, QVariant> vars = variables(); + QList<QString> keys = vars.keys(); + sort(keys); + foreach (const QString &key, keys) { + const QVariant &v = vars.value(key); + result += QLatin1String(" <tr><td>") + + key + QLatin1String("</td><td>") + + typeOf(v) + QLatin1String("</td><td>") + + stringify(v) + QLatin1String("</td><td>") + + evaluate(v) + QLatin1String("</td></tr>\n"); + } + + result += QLatin1String("</table>"); + + auto dialog = new QDialog(this); + dialog->setMinimumSize(800, 600); + auto layout = new QVBoxLayout(dialog); + auto scrollArea = new QScrollArea; + auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal); + + auto label = new QLabel(result); + label->setWordWrap(true); + scrollArea->setWidget(label); + + layout->addWidget(scrollArea); + layout->addWidget(buttons); + + connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); + connect(dialog, &QDialog::finished, dialog, &QObject::deleteLater); + + dialog->show(); +} + +QString Wizard::stringify(const QVariant &v) const +{ + return v.toString(); +} + +QString Wizard::evaluate(const QVariant &v) const +{ + return stringify(v); +} + bool Wizard::event(QEvent *event) { if (event->type() == QEvent::ShortcutOverride) { |