diff options
Diffstat (limited to 'src/tools/uic/cpp')
-rw-r--r-- | src/tools/uic/cpp/cpp.pri | 12 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppextractimages.cpp | 140 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppextractimages.h | 64 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwritedeclaration.cpp | 63 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwritedeclaration.h | 3 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteicondata.cpp | 172 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteicondata.h | 68 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteicondeclaration.cpp | 67 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteicondeclaration.h | 63 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteiconinitialization.cpp | 102 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteiconinitialization.h | 68 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteincludes.cpp | 22 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteincludes.h | 5 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteinitialization.cpp | 212 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteinitialization.h | 13 |
15 files changed, 62 insertions, 1012 deletions
diff --git a/src/tools/uic/cpp/cpp.pri b/src/tools/uic/cpp/cpp.pri index 49c71a6dfa..a6b6188117 100644 --- a/src/tools/uic/cpp/cpp.pri +++ b/src/tools/uic/cpp/cpp.pri @@ -3,18 +3,10 @@ INCLUDEPATH += $$PWD $$QT_BUILD_TREE/src/tools/uic DEFINES += QT_UIC_CPP_GENERATOR # Input -HEADERS += $$PWD/cppextractimages.h \ - $$PWD/cppwritedeclaration.h \ - $$PWD/cppwriteicondata.h \ - $$PWD/cppwriteicondeclaration.h \ - $$PWD/cppwriteiconinitialization.h \ +HEADERS += $$PWD/cppwritedeclaration.h \ $$PWD/cppwriteincludes.h \ $$PWD/cppwriteinitialization.h -SOURCES += $$PWD/cppextractimages.cpp \ - $$PWD/cppwritedeclaration.cpp \ - $$PWD/cppwriteicondata.cpp \ - $$PWD/cppwriteicondeclaration.cpp \ - $$PWD/cppwriteiconinitialization.cpp \ +SOURCES += $$PWD/cppwritedeclaration.cpp \ $$PWD/cppwriteincludes.cpp \ $$PWD/cppwriteinitialization.cpp diff --git a/src/tools/uic/cpp/cppextractimages.cpp b/src/tools/uic/cpp/cppextractimages.cpp deleted file mode 100644 index 4d06d08dae..0000000000 --- a/src/tools/uic/cpp/cppextractimages.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "cppextractimages.h" -#include "cppwriteicondata.h" -#include "driver.h" -#include "ui4.h" -#include "utils.h" -#include "uic.h" - -#include <qtextstream.h> -#include <qtextcodec.h> -#include <qdir.h> -#include <qfile.h> -#include <qfileinfo.h> - -QT_BEGIN_NAMESPACE - -namespace CPP { - -ExtractImages::ExtractImages(const Option &opt) - : m_output(0), m_option(opt) -{ -} - -void ExtractImages::acceptUI(DomUI *node) -{ - if (!m_option.extractImages) - return; - - if (node->elementImages() == 0) - return; - - QString className = node->elementClass() + m_option.postfix; - - QFile f; - if (m_option.qrcOutputFile.size()) { - f.setFileName(m_option.qrcOutputFile); - if (!f.open(QIODevice::WriteOnly | QFile::Text)) { - fprintf(stderr, "%s: Error: Could not create resource file\n", qPrintable(m_option.messagePrefix())); - return; - } - - QFileInfo fi(m_option.qrcOutputFile); - QDir dir = fi.absoluteDir(); - if (!dir.exists(QLatin1String("images")) && !dir.mkdir(QLatin1String("images"))) { - fprintf(stderr, "%s: Error: Could not create image dir\n", qPrintable(m_option.messagePrefix())); - return; - } - dir.cd(QLatin1String("images")); - m_imagesDir = dir; - - m_output = new QTextStream(&f); -#ifndef QT_NO_TEXTCODEC - m_output->setCodec(QTextCodec::codecForName("UTF-8")); -#endif - - QTextStream &out = *m_output; - - out << "<RCC>\n"; - out << " <qresource prefix=\"/" << className << "\" >\n"; - TreeWalker::acceptUI(node); - out << " </qresource>\n"; - out << "</RCC>\n"; - - f.close(); - delete m_output; - m_output = 0; - } -} - -void ExtractImages::acceptImages(DomImages *images) -{ - TreeWalker::acceptImages(images); -} - -void ExtractImages::acceptImage(DomImage *image) -{ - QString format = image->elementData()->attributeFormat(); - QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower(); - QString fname = m_imagesDir.absoluteFilePath(image->attributeName() + QLatin1Char('.') + extension); - - *m_output << " <file>images/" << image->attributeName() << QLatin1Char('.') + extension << "</file>\n"; - - QFile f; - f.setFileName(fname); - const bool isXPM_GZ = format == QLatin1String("XPM.GZ"); - QIODevice::OpenMode openMode = QIODevice::WriteOnly; - if (isXPM_GZ) - openMode |= QIODevice::Text; - if (!f.open(openMode)) { - fprintf(stderr, "%s: Error: Could not create image file %s: %s", - qPrintable(m_option.messagePrefix()), - qPrintable(fname), qPrintable(f.errorString())); - return; - } - - if (isXPM_GZ) { - QTextStream *imageOut = new QTextStream(&f); -#ifndef QT_NO_TEXTCODEC - imageOut->setCodec(QTextCodec::codecForName("UTF-8")); -#endif - - CPP::WriteIconData::writeImage(*imageOut, QString(), m_option.limitXPM_LineLength, image); - delete imageOut; - } else { - CPP::WriteIconData::writeImage(f, image); - } - - f.close(); -} - -} // namespace CPP - -QT_END_NAMESPACE diff --git a/src/tools/uic/cpp/cppextractimages.h b/src/tools/uic/cpp/cppextractimages.h deleted file mode 100644 index d012de8d0a..0000000000 --- a/src/tools/uic/cpp/cppextractimages.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CPPEXTRACTIMAGES_H -#define CPPEXTRACTIMAGES_H - -#include "treewalker.h" -#include <qdir.h> - -QT_BEGIN_NAMESPACE - -class QTextStream; -class Driver; -class Uic; - -struct Option; - -namespace CPP { - -class ExtractImages : public TreeWalker -{ -public: - ExtractImages(const Option &opt); - - void acceptUI(DomUI *node) Q_DECL_OVERRIDE; - void acceptImages(DomImages *images) Q_DECL_OVERRIDE; - void acceptImage(DomImage *image) Q_DECL_OVERRIDE; - -private: - QTextStream *m_output; - const Option &m_option; - QDir m_imagesDir; -}; - -} // namespace CPP - -QT_END_NAMESPACE - -#endif // CPPEXTRACTIMAGES_H diff --git a/src/tools/uic/cpp/cppwritedeclaration.cpp b/src/tools/uic/cpp/cppwritedeclaration.cpp index 3aadc878e3..e384a1e194 100644 --- a/src/tools/uic/cpp/cppwritedeclaration.cpp +++ b/src/tools/uic/cpp/cppwritedeclaration.cpp @@ -27,10 +27,7 @@ ****************************************************************************/ #include "cppwritedeclaration.h" -#include "cppwriteicondeclaration.h" #include "cppwriteinitialization.h" -#include "cppwriteiconinitialization.h" -#include "cppextractimages.h" #include "driver.h" #include "ui4.h" #include "uic.h" @@ -56,47 +53,15 @@ namespace { output << "} // namespace " << *it << "\n"; } } - - void writeScriptContextClass(const QString &indent, QTextStream &str) { - str << indent << "class ScriptContext\n" - << indent << "{\n" - << indent << "public:\n" - << indent << " void run(const QString &script, QWidget *widget, const QWidgetList &childWidgets)\n" - << indent << " {\n" - << indent << " QScriptValue widgetObject = scriptEngine.newQObject(widget);\n" - << indent << " QScriptValue childWidgetArray = scriptEngine.newArray (childWidgets.size());\n" - << indent << " for (int i = 0; i < childWidgets.size(); i++)\n" - << indent << " childWidgetArray.setProperty(i, scriptEngine.newQObject(childWidgets[i]));\n" - << indent << " QScriptContext *ctx = scriptEngine.pushContext();\n" - << indent << " ctx ->activationObject().setProperty(QLatin1String(\"widget\"), widgetObject);\n" - << indent << " ctx ->activationObject().setProperty(QLatin1String(\"childWidgets\"), childWidgetArray);\n\n" - << indent << " scriptEngine.evaluate(script);\n" - << indent << " if (scriptEngine.hasUncaughtException ()) {\n" - << indent << " qWarning() << \"An exception occurred at line \" << scriptEngine.uncaughtExceptionLineNumber()\n" - << indent << " << \" of the script for \" << widget->objectName() << \": \" << engineError() << '\\n'\n" - << indent << " << script;\n" - << indent << " }\n\n" - << indent << " scriptEngine.popContext();\n" - << indent << " }\n\n" - << indent << "private:\n" - << indent << " QString engineError()\n" - << indent << " {\n" - << indent << " QScriptValue error = scriptEngine.evaluate(\"Error\");\n" - << indent << " return error.toString();\n" - << indent << " }\n\n" - << indent << " QScriptEngine scriptEngine;\n" - << indent << "};\n\n"; - } } namespace CPP { -WriteDeclaration::WriteDeclaration(Uic *uic, bool activateScripts) : +WriteDeclaration::WriteDeclaration(Uic *uic) : m_uic(uic), m_driver(uic->driver()), m_output(uic->output()), - m_option(uic->option()), - m_activateScripts(activateScripts) + m_option(uic->option()) { } @@ -154,29 +119,7 @@ void WriteDeclaration::acceptUI(DomUI *node) m_output << "\n"; - WriteInitialization(m_uic, m_activateScripts).acceptUI(node); - - if (node->elementImages()) { - if (m_option.extractImages) { - ExtractImages(m_uic->option()).acceptUI(node); - } else { - m_output << "\n" - << "protected:\n" - << m_option.indent << "enum IconID\n" - << m_option.indent << "{\n"; - WriteIconDeclaration(m_uic).acceptUI(node); - - m_output << m_option.indent << m_option.indent << "unknown_ID\n" - << m_option.indent << "};\n"; - - WriteIconInitialization(m_uic).acceptUI(node); - } - } - - if (m_activateScripts) { - m_output << "\nprivate:\n\n"; - writeScriptContextClass(m_option.indent, m_output); - } + WriteInitialization(m_uic).acceptUI(node); m_output << "};\n\n"; diff --git a/src/tools/uic/cpp/cppwritedeclaration.h b/src/tools/uic/cpp/cppwritedeclaration.h index baa57c5978..ca2122293c 100644 --- a/src/tools/uic/cpp/cppwritedeclaration.h +++ b/src/tools/uic/cpp/cppwritedeclaration.h @@ -43,7 +43,7 @@ namespace CPP { struct WriteDeclaration : public TreeWalker { - WriteDeclaration(Uic *uic, bool activateScripts); + WriteDeclaration(Uic *uic); void acceptUI(DomUI *node) Q_DECL_OVERRIDE; void acceptWidget(DomWidget *node) Q_DECL_OVERRIDE; @@ -58,7 +58,6 @@ private: Driver *m_driver; QTextStream &m_output; const Option &m_option; - const bool m_activateScripts; }; } // namespace CPP diff --git a/src/tools/uic/cpp/cppwriteicondata.cpp b/src/tools/uic/cpp/cppwriteicondata.cpp deleted file mode 100644 index 4601a4c5e9..0000000000 --- a/src/tools/uic/cpp/cppwriteicondata.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "cppwriteicondata.h" -#include "driver.h" -#include "ui4.h" -#include "uic.h" - -#include <qtextstream.h> - -QT_BEGIN_NAMESPACE - -namespace CPP { - -static QByteArray transformImageData(const QString &data) -{ - int baSize = data.length() / 2; - uchar *ba = new uchar[baSize]; - for (int i = 0; i < baSize; ++i) { - char h = data[2 * (i)].toLatin1(); - char l = data[2 * (i) + 1].toLatin1(); - uchar r = 0; - if (h <= '9') - r += h - '0'; - else - r += h - 'a' + 10; - r = r << 4; - if (l <= '9') - r += l - '0'; - else - r += l - 'a' + 10; - ba[i] = r; - } - QByteArray ret(reinterpret_cast<const char *>(ba), baSize); - delete [] ba; - return ret; -} - -static QByteArray unzipXPM(const QString &data, ulong &length) -{ -#ifndef QT_NO_COMPRESS - const int lengthOffset = 4; - QByteArray ba(lengthOffset, ' '); - - // qUncompress() expects the first 4 bytes to be the expected length of the - // uncompressed data - ba[0] = (length & 0xff000000) >> 24; - ba[1] = (length & 0x00ff0000) >> 16; - ba[2] = (length & 0x0000ff00) >> 8; - ba[3] = (length & 0x000000ff); - ba.append(transformImageData(data)); - QByteArray baunzip = qUncompress(ba); - return baunzip; -#else - Q_UNUSED(data); - Q_UNUSED(length); - return QByteArray(); -#endif -} - - -WriteIconData::WriteIconData(Uic *uic) - : driver(uic->driver()), output(uic->output()), option(uic->option()) -{ -} - -void WriteIconData::acceptUI(DomUI *node) -{ - TreeWalker::acceptUI(node); -} - -void WriteIconData::acceptImages(DomImages *images) -{ - TreeWalker::acceptImages(images); -} - -void WriteIconData::acceptImage(DomImage *image) -{ - // Limit line length when writing code. - writeImage(output, option.indent, true, image); -} - -void WriteIconData::writeImage(QTextStream &output, const QString &indent, - bool limitXPM_LineLength, const DomImage *image) -{ - QString img = image->attributeName() + QLatin1String("_data"); - QString data = image->elementData()->text(); - QString fmt = image->elementData()->attributeFormat(); - int size = image->elementData()->attributeLength(); - - if (fmt == QLatin1String("XPM.GZ")) { - ulong length = size; - QByteArray baunzip = unzipXPM(data, length); - length = baunzip.size(); - // shouldn't we test the initial 'length' against the - // resulting 'length' to catch corrupt UIC files? - int a = 0; - int column = 0; - bool inQuote = false; - output << indent << "/* XPM */\n" - << indent << "static const char* const " << img << "[] = { \n"; - while (baunzip[a] != '\"') - a++; - for (; a < (int) length; a++) { - output << baunzip[a]; - if (baunzip[a] == '\n') { - column = 0; - } else if (baunzip[a] == '"') { - inQuote = !inQuote; - } - - column++; - if (limitXPM_LineLength && column >= 512 && inQuote) { - output << "\"\n\""; // be nice with MSVC & Co. - column = 1; - } - } - - if (! baunzip.trimmed ().endsWith ("};")) - output << "};"; - - output << "\n\n"; - } else { - output << indent << "static const unsigned char " << img << "[] = { \n"; - output << indent; - int a ; - for (a = 0; a < (int) (data.length()/2)-1; a++) { - output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << ','; - if (a % 12 == 11) - output << '\n' << indent; - else - output << ' '; - } - output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << '\n'; - output << "};\n\n"; - } -} - -void WriteIconData::writeImage(QIODevice &output, DomImage *image) -{ - const QByteArray array = transformImageData(image->elementData()->text()); - output.write(array.constData(), array.size()); -} - -} // namespace CPP - -QT_END_NAMESPACE diff --git a/src/tools/uic/cpp/cppwriteicondata.h b/src/tools/uic/cpp/cppwriteicondata.h deleted file mode 100644 index c496d5a85b..0000000000 --- a/src/tools/uic/cpp/cppwriteicondata.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CPPWRITEICONDATA_H -#define CPPWRITEICONDATA_H - -#include "treewalker.h" - -QT_BEGIN_NAMESPACE - -class QTextStream; -class QIODevice; -class Driver; -class Uic; - -struct Option; - -namespace CPP { - -class WriteIconData : public TreeWalker -{ -public: - WriteIconData(Uic *uic); - - void acceptUI(DomUI *node) Q_DECL_OVERRIDE; - void acceptImages(DomImages *images) Q_DECL_OVERRIDE; - void acceptImage(DomImage *image) Q_DECL_OVERRIDE; - - static void writeImage(QTextStream &output, const QString &indent, - bool limitXPM_LineLength, const DomImage *image); - static void writeImage(QIODevice &output, DomImage *image); - -private: - Driver *driver; - QTextStream &output; - const Option &option; -}; - -} // namespace CPP - -QT_END_NAMESPACE - -#endif // CPPWRITEICONDATA_H diff --git a/src/tools/uic/cpp/cppwriteicondeclaration.cpp b/src/tools/uic/cpp/cppwriteicondeclaration.cpp deleted file mode 100644 index 5264e3de54..0000000000 --- a/src/tools/uic/cpp/cppwriteicondeclaration.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "cppwriteicondeclaration.h" -#include "driver.h" -#include "ui4.h" -#include "uic.h" - -#include <qtextstream.h> - -QT_BEGIN_NAMESPACE - -namespace CPP { - -WriteIconDeclaration::WriteIconDeclaration(Uic *uic) - : driver(uic->driver()), output(uic->output()), option(uic->option()) -{ -} - -void WriteIconDeclaration::acceptUI(DomUI *node) -{ - TreeWalker::acceptUI(node); -} - -void WriteIconDeclaration::acceptImages(DomImages *images) -{ - TreeWalker::acceptImages(images); -} - -void WriteIconDeclaration::acceptImage(DomImage *image) -{ - QString name = image->attributeName(); - if (name.isEmpty()) - return; - - driver->insertPixmap(name); - output << option.indent << option.indent << name << "_ID,\n"; -} - -} // namespace CPP - -QT_END_NAMESPACE diff --git a/src/tools/uic/cpp/cppwriteicondeclaration.h b/src/tools/uic/cpp/cppwriteicondeclaration.h deleted file mode 100644 index 6483b8bf4a..0000000000 --- a/src/tools/uic/cpp/cppwriteicondeclaration.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CPPWRITEICONDECLARATION_H -#define CPPWRITEICONDECLARATION_H - -#include "treewalker.h" - -QT_BEGIN_NAMESPACE - -class QTextStream; -class Driver; -class Uic; - -struct Option; - -namespace CPP { - -class WriteIconDeclaration : public TreeWalker -{ -public: - WriteIconDeclaration(Uic *uic); - - void acceptUI(DomUI *node) Q_DECL_OVERRIDE; - void acceptImages(DomImages *images) Q_DECL_OVERRIDE; - void acceptImage(DomImage *image) Q_DECL_OVERRIDE; - -private: - Driver *driver; - QTextStream &output; - const Option &option; -}; - -} // namespace CPP - -QT_END_NAMESPACE - -#endif // CPPWRITEICONDECLARATION_H diff --git a/src/tools/uic/cpp/cppwriteiconinitialization.cpp b/src/tools/uic/cpp/cppwriteiconinitialization.cpp deleted file mode 100644 index 33d1c8402e..0000000000 --- a/src/tools/uic/cpp/cppwriteiconinitialization.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "cppwriteiconinitialization.h" -#include "cppwriteicondata.h" -#include "driver.h" -#include "ui4.h" -#include "utils.h" -#include "uic.h" - -#include <qtextstream.h> -#include <qstring.h> - -QT_BEGIN_NAMESPACE - -namespace CPP { - -WriteIconInitialization::WriteIconInitialization(Uic *uic) - : driver(uic->driver()), output(uic->output()), option(uic->option()) -{ - this->uic = uic; -} - -void WriteIconInitialization::acceptUI(DomUI *node) -{ - if (node->elementImages() == 0) - return; - - QString className = node->elementClass() + option.postfix; - - output << option.indent << "static QPixmap " << iconFromDataFunction() << "(IconID id)\n" - << option.indent << "{\n"; - - WriteIconData(uic).acceptUI(node); - - output << option.indent << "switch (id) {\n"; - - TreeWalker::acceptUI(node); - - output << option.indent << option.indent << "default: return QPixmap();\n"; - - output << option.indent << "} // switch\n" - << option.indent << "} // icon\n\n"; -} - -QString WriteIconInitialization::iconFromDataFunction() -{ - return QLatin1String("qt_get_icon"); -} - -void WriteIconInitialization::acceptImages(DomImages *images) -{ - TreeWalker::acceptImages(images); -} - -void WriteIconInitialization::acceptImage(DomImage *image) -{ - QString img = image->attributeName() + QLatin1String("_data"); - QString data = image->elementData()->text(); - QString fmt = image->elementData()->attributeFormat(); - - QString imageId = image->attributeName() + QLatin1String("_ID"); - QString imageData = image->attributeName() + QLatin1String("_data"); - QString ind = option.indent + option.indent; - - output << ind << "case " << imageId << ": "; - - if (fmt == QLatin1String("XPM.GZ")) { - output << "return " << "QPixmap((const char**)" << imageData << ");\n"; - } else { - output << " { QImage img; img.loadFromData(" << imageData << ", sizeof(" << imageData << "), " << fixString(fmt, ind) << "); return QPixmap::fromImage(img); }\n"; - } -} - -} // namespace CPP - -QT_END_NAMESPACE diff --git a/src/tools/uic/cpp/cppwriteiconinitialization.h b/src/tools/uic/cpp/cppwriteiconinitialization.h deleted file mode 100644 index 588cb1bc67..0000000000 --- a/src/tools/uic/cpp/cppwriteiconinitialization.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CPPWRITEICONINITIALIZATION_H -#define CPPWRITEICONINITIALIZATION_H - -#include "treewalker.h" - -class QString; - -QT_BEGIN_NAMESPACE - -class QTextStream; -class Driver; -class Uic; - -struct Option; - -namespace CPP { - -class WriteIconInitialization : public TreeWalker -{ -public: - WriteIconInitialization(Uic *uic); - - void acceptUI(DomUI *node) Q_DECL_OVERRIDE; - void acceptImages(DomImages *images) Q_DECL_OVERRIDE; - void acceptImage(DomImage *image) Q_DECL_OVERRIDE; - - static QString iconFromDataFunction(); - -private: - Uic *uic; - Driver *driver; - QTextStream &output; - const Option &option; -}; - -} // namespace CPP - -QT_END_NAMESPACE - -#endif // CPPWRITEICONINITIALIZATION_H diff --git a/src/tools/uic/cpp/cppwriteincludes.cpp b/src/tools/uic/cpp/cppwriteincludes.cpp index dcbe400224..de64b85219 100644 --- a/src/tools/uic/cpp/cppwriteincludes.cpp +++ b/src/tools/uic/cpp/cppwriteincludes.cpp @@ -69,7 +69,7 @@ static inline QString moduleHeader(const QString &module, const QString &header) namespace CPP { WriteIncludes::WriteIncludes(Uic *uic) - : m_uic(uic), m_output(uic->output()), m_scriptsActivated(false), m_laidOut(false) + : m_uic(uic), m_output(uic->output()), m_laidOut(false) { // When possible (no namespace) use the "QtModule/QClass" convention // and create a re-mapping of the old header "qclass.h" to it. Do not do this @@ -92,7 +92,6 @@ WriteIncludes::WriteIncludes(Uic *uic) void WriteIncludes::acceptUI(DomUI *node) { - m_scriptsActivated = false; m_laidOut = false; m_localIncludes.clear(); m_globalIncludes.clear(); @@ -231,10 +230,6 @@ void WriteIncludes::acceptCustomWidget(DomCustomWidget *node) if (className.isEmpty()) return; - if (const DomScript *domScript = node->elementScript()) - if (!domScript->text().isEmpty()) - activateScripts(); - if (!node->elementHeader() || node->elementHeader()->text().isEmpty()) { add(className, false); // no header specified } else { @@ -296,21 +291,6 @@ void WriteIncludes::writeHeaders(const OrderedSet &headers, bool global) } } -void WriteIncludes::acceptWidgetScripts(const DomScripts &scripts, DomWidget *, const DomWidgets &) -{ - if (!scripts.empty()) { - activateScripts(); - } -} - -void WriteIncludes::activateScripts() -{ - if (!m_scriptsActivated) { - add(QLatin1String("QScriptEngine")); - add(QLatin1String("QDebug")); - m_scriptsActivated = true; - } -} } // namespace CPP QT_END_NAMESPACE diff --git a/src/tools/uic/cpp/cppwriteincludes.h b/src/tools/uic/cpp/cppwriteincludes.h index 7a6a499536..0d9c293efc 100644 --- a/src/tools/uic/cpp/cppwriteincludes.h +++ b/src/tools/uic/cpp/cppwriteincludes.h @@ -54,7 +54,6 @@ struct WriteIncludes : public TreeWalker void acceptLayout(DomLayout *node) Q_DECL_OVERRIDE; void acceptSpacer(DomSpacer *node) Q_DECL_OVERRIDE; void acceptProperty(DomProperty *node) Q_DECL_OVERRIDE; - void acceptWidgetScripts(const DomScripts &, DomWidget *, const DomWidgets &) Q_DECL_OVERRIDE; // // custom widgets @@ -68,8 +67,6 @@ struct WriteIncludes : public TreeWalker void acceptIncludes(DomIncludes *node) Q_DECL_OVERRIDE; void acceptInclude(DomInclude *node) Q_DECL_OVERRIDE; - bool scriptsActivated() const { return m_scriptsActivated; } - private: void add(const QString &className, bool determineHeader = true, const QString &header = QString(), bool global = false); @@ -79,7 +76,6 @@ private: void insertInclude(const QString &header, bool global); void writeHeaders(const OrderedSet &headers, bool global); QString headerForClassName(const QString &className) const; - void activateScripts(); const Uic *m_uic; QTextStream &m_output; @@ -94,7 +90,6 @@ private: StringMap m_classToHeader; StringMap m_oldHeaderToNewHeader; - bool m_scriptsActivated; bool m_laidOut; }; diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp index d208ec6718..cc7e8fc9e3 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.cpp +++ b/src/tools/uic/cpp/cppwriteinitialization.cpp @@ -27,7 +27,6 @@ ****************************************************************************/ #include "cppwriteinitialization.h" -#include "cppwriteiconinitialization.h" #include "driver.h" #include "ui4.h" #include "utils.h" @@ -83,8 +82,8 @@ namespace { int w = 0; int h = 0; - if (properties.contains(QLatin1String("sizeHint"))) { - if (const DomSize *sizeHint = properties.value(QLatin1String("sizeHint"))->elementSize()) { + if (const DomProperty *sh = properties.value(QLatin1String("sizeHint"))) { + if (const DomSize *sizeHint = sh->elementSize()) { w = sizeHint->elementWidth(); h = sizeHint->elementHeight(); } @@ -92,17 +91,23 @@ namespace { output << w << ", " << h << ", "; // size type - QString sizeType = properties.contains(QLatin1String("sizeType")) ? - properties.value(QLatin1String("sizeType"))->elementEnum() : - QString::fromLatin1("Expanding"); + QString sizeType; + if (const DomProperty *st = properties.value(QLatin1String("sizeType"))) { + const QString value = st->elementEnum(); + if (value.startsWith(QLatin1String("QSizePolicy::"))) + sizeType = value; + else + sizeType = QLatin1String("QSizePolicy::") + value; + } else { + sizeType = QStringLiteral("QSizePolicy::Expanding"); + } - if (!sizeType.startsWith(QLatin1String("QSizePolicy::"))) - sizeType.prepend(QLatin1String("QSizePolicy::")); // orientation bool isVspacer = false; - if (properties.contains(QLatin1String("orientation"))) { - const QString orientation = properties.value(QLatin1String("orientation"))->elementEnum(); - if (orientation == QLatin1String("Qt::Vertical") || orientation == QLatin1String("Vertical")) isVspacer = true; + if (const DomProperty *o = properties.value(QLatin1String("orientation"))) { + const QString orientation = o->elementEnum(); + if (orientation == QLatin1String("Qt::Vertical") || orientation == QLatin1String("Vertical")) + isVspacer = true; } if (isVspacer) @@ -125,11 +130,6 @@ namespace { str << indent << varName << "->" << setter << '(' << v << ");\n"; } - void writeSetupUIScriptVariableDeclarations(const QString &indent, QTextStream &str) { - str << indent << "ScriptContext scriptContext;\n" - << indent << "QWidgetList childWidgets;\n"; - } - static inline bool iconHasStatePixmaps(const DomResourceIcon *i) { return i->hasElementNormalOff() || i->hasElementNormalOn() || i->hasElementDisabledOff() || i->hasElementDisabledOn() || @@ -396,10 +396,8 @@ void WriteInitialization::LayoutDefaultHandler::writeProperty(int p, const QStri int defaultStyleValue, bool suppressDefault, QTextStream &str) const { // User value - const DomPropertyMap::const_iterator mit = properties.constFind(propertyName); - const bool found = mit != properties.constEnd(); - if (found) { - const int value = mit.value()->elementNumber(); + if (const DomProperty *prop = properties.value(propertyName)) { + const int value = prop->elementNumber(); // Emulate the pre 4.3 behaviour: The value form default value was only used to determine // the default value, layout properties were always written const bool useLayoutFunctionPre43 = !suppressDefault && (m_state[p] == (HasDefaultFunction|HasDefaultValue)) && value == m_defaultValues[p]; @@ -461,7 +459,7 @@ static bool needsTranslation(const DomElement *element) } // --- WriteInitialization -WriteInitialization::WriteInitialization(Uic *uic, bool activateScripts) : +WriteInitialization::WriteInitialization(Uic *uic) : m_uic(uic), m_driver(uic->driver()), m_output(uic->output()), m_option(uic->option()), m_indent(m_option.indent + m_option.indent), @@ -472,14 +470,13 @@ WriteInitialization::WriteInitialization(Uic *uic, bool activateScripts) : m_delayedOut(&m_delayedInitialization, QIODevice::WriteOnly), m_refreshOut(&m_refreshInitialization, QIODevice::WriteOnly), m_actionOut(&m_delayedActionInitialization, QIODevice::WriteOnly), - m_activateScripts(activateScripts), m_layoutWidget(false), + m_layoutWidget(false), m_firstThemeIcon(true) { } void WriteInitialization::acceptUI(DomUI *node) { - m_registeredImages.clear(); m_actionGroupChain.push(0); m_widgetChain.push(0); m_layoutChain.push(0); @@ -490,9 +487,6 @@ void WriteInitialization::acceptUI(DomUI *node) if (node->elementCustomWidgets()) TreeWalker::acceptCustomWidgets(node->elementCustomWidgets()); - if (node->elementImages()) - TreeWalker::acceptImages(node->elementImages()); - if (m_option.generateImplemetation) m_output << "#include <" << m_driver->headerFileName() << ">\n\n"; @@ -512,9 +506,6 @@ void WriteInitialization::acceptUI(DomUI *node) m_output << m_option.indent << "void " << "setupUi(" << widgetClassName << " *" << varName << ")\n" << m_option.indent << "{\n"; - if (m_activateScripts) - writeSetupUIScriptVariableDeclarations(m_indent, m_output); - const QStringList connections = m_uic->databaseInfo()->connections(); for (int i=0; i<connections.size(); ++i) { QString connection = connections.at(i); @@ -591,15 +582,15 @@ void WriteInitialization::addWizardPage(const QString &pageVarName, const DomWid /* If the node has a (free-format) string "pageId" attribute (which could * an integer or an enumeration value), use setPage(), else addPage(). */ QString id; - const DomPropertyList attributes = page->elementAttribute(); + const auto &attributes = page->elementAttribute(); if (!attributes.empty()) { - const DomPropertyList::const_iterator acend = attributes.constEnd(); - for (DomPropertyList::const_iterator it = attributes.constBegin(); it != acend; ++it) - if ((*it)->attributeName() == QLatin1String("pageId")) { - if (const DomString *ds = (*it)->elementString()) + for (const DomProperty *p : attributes) { + if (p->attributeName() == QLatin1String("pageId")) { + if (const DomString *ds = p->elementString()) id = ds->text(); break; } + } } if (id.isEmpty()) { m_output << m_indent << parentWidget << "->addPage(" << pageVarName << ");\n"; @@ -884,7 +875,7 @@ void WriteInitialization::acceptLayout(DomLayout *node) const QString varName = m_driver->findOrInsertLayout(node); const DomPropertyMap properties = propertyMap(node->elementProperty()); - const bool oldLayoutProperties = properties.constFind(QLatin1String("margin")) != properties.constEnd(); + const bool oldLayoutProperties = properties.value(QLatin1String("margin")) != nullptr; bool isGroupBox = false; @@ -1149,9 +1140,7 @@ void WriteInitialization::writeProperties(const QString &varName, if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) { DomPropertyMap properties = propertyMap(lst); - if (properties.contains(QLatin1String("control"))) { - DomProperty *p = properties.value(QLatin1String("control")); - Q_ASSERT( p ); + if (DomProperty *p = properties.value(QLatin1String("control"))) { m_output << m_indent << varName << "->setControl(" << writeString(toString(p->elementString()), m_dindent) << ");\n"; } @@ -1708,7 +1697,7 @@ void WriteInitialization::writeColorGroup(DomColorGroup *colorGroup, const QStri return; // old format - const QList<DomColor*> colors = colorGroup->elementColor(); + const auto &colors = colorGroup->elementColor(); for (int i=0; i<colors.size(); ++i) { const DomColor *color = colors.at(i); @@ -1719,7 +1708,7 @@ void WriteInitialization::writeColorGroup(DomColorGroup *colorGroup, const QStri } // new format - const QList<DomColorRole *> colorRoles = colorGroup->elementColorRole(); + const auto &colorRoles = colorGroup->elementColorRole(); for (const DomColorRole *colorRole : colorRoles) { if (colorRole->hasAttributeRole()) { const QString brushName = writeBrushInitialization(colorRole->elementBrush()); @@ -1796,7 +1785,7 @@ void WriteInitialization::writeBrush(const DomBrush *brush, const QString &brush << gradient->attributeCoordinateMode() << ");\n"; } - const QList<DomGradientStop *> stops = gradient->elementGradientStop(); + const auto &stops = gradient->elementGradientStop(); for (const DomGradientStop *stop : stops) { const DomColor *color = stop->elementColor(); m_output << m_indent << gradientName << ".setColorAt(" @@ -1894,23 +1883,6 @@ QString WriteInitialization::pixCall(const QString &t, const QString &text) cons type += QLatin1String("()"); return type; } - if (const DomImage *image = findImage(text)) { - if (m_option.extractImages) { - const QString format = image->elementData()->attributeFormat(); - const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower(); - return QLatin1String("QPixmap(QString::fromUtf8(\":/") - + m_generatedClass - + QLatin1String("/images/") - + text - + QLatin1Char('.') - + extension - + QLatin1String("\"))"); - } - return WriteIconInitialization::iconFromDataFunction() - + QLatin1Char('(') - + text - + QLatin1String("_ID)"); - } QString pixFunc = m_uic->pixmapFunction(); if (pixFunc.isEmpty()) @@ -1927,63 +1899,34 @@ QString WriteInitialization::pixCall(const QString &t, const QString &text) cons void WriteInitialization::initializeComboBox(DomWidget *w) { const QString varName = m_driver->findOrInsertWidget(w); - const QString className = w->attributeClass(); - const QList<DomItem*> items = w->elementItem(); + const auto &items = w->elementItem(); if (items.isEmpty()) return; - // If possible use qcombobox's addItems() which is much faster then a bunch of addItem() calls - bool makeStringListCall = true; - bool translatable = false; - QStringList list; - for (int i=0; i<items.size(); ++i) { + for (int i = 0; i < items.size(); ++i) { const DomItem *item = items.at(i); const DomPropertyMap properties = propertyMap(item->elementProperty()); const DomProperty *text = properties.value(QLatin1String("text")); - const DomProperty *pixmap = properties.value(QLatin1String("icon")); - bool needsTr = needsTranslation(text->elementString()); - if (pixmap != 0 || (i > 0 && translatable != needsTr)) { - makeStringListCall = false; - break; - } - translatable = needsTr; - list.append(autoTrCall(text->elementString())); // fix me here - } + const DomProperty *icon = properties.value(QLatin1String("icon")); - if (makeStringListCall) { - QTextStream &o = translatable ? m_refreshOut : m_output; - if (translatable) - o << m_indent << varName << "->clear();\n"; - o << m_indent << varName << "->insertItems(0, QStringList()" << '\n'; - for (int i = 0; i < list.size(); ++i) - o << m_indent << " << " << list.at(i) << "\n"; - o << m_indent << ");\n"; - } else { - for (int i = 0; i < items.size(); ++i) { - const DomItem *item = items.at(i); - const DomPropertyMap properties = propertyMap(item->elementProperty()); - const DomProperty *text = properties.value(QLatin1String("text")); - const DomProperty *icon = properties.value(QLatin1String("icon")); - - QString iconValue; - if (icon) - iconValue = iconCall(icon); - - m_output << m_indent << varName << "->addItem("; - if (icon) - m_output << iconValue << ", "; - - if (needsTranslation(text->elementString())) { - m_output << "QString());\n"; - m_refreshOut << m_indent << varName << "->setItemText(" << i << ", " << trCall(text->elementString()) << ");\n"; - } else { - m_output << noTrCall(text->elementString()) << ");\n"; - } + QString iconValue; + if (icon) + iconValue = iconCall(icon); + + m_output << m_indent << varName << "->addItem("; + if (icon) + m_output << iconValue << ", "; + + if (needsTranslation(text->elementString())) { + m_output << "QString());\n"; + m_refreshOut << m_indent << varName << "->setItemText(" << i << ", " << trCall(text->elementString()) << ");\n"; + } else { + m_output << noTrCall(text->elementString()) << ");\n"; } - m_refreshOut << "\n"; } + m_refreshOut << "\n"; } QString WriteInitialization::disableSorting(DomWidget *w, const QString &varName) @@ -2118,9 +2061,8 @@ void WriteInitialization::addCommonInitializers(Item *item, void WriteInitialization::initializeListWidget(DomWidget *w) { const QString varName = m_driver->findOrInsertWidget(w); - const QString className = w->attributeClass(); - const QList<DomItem*> items = w->elementItem(); + const auto &items = w->elementItem(); if (items.isEmpty()) return; @@ -2150,7 +2092,7 @@ void WriteInitialization::initializeTreeWidget(DomWidget *w) // columns Item item(QLatin1String("QTreeWidgetItem"), m_indent, m_output, m_refreshOut, m_driver); - const QList<DomColumn*> columns = w->elementColumn(); + const auto &columns = w->elementColumn(); for (int i = 0; i < columns.size(); ++i) { const DomColumn *column = columns.at(i); @@ -2193,7 +2135,7 @@ void WriteInitialization::initializeTreeWidget(DomWidget *w) conditions an item is needed needs to be done bottom-up, the whole process makes two passes, storing the intermediate result in a recursive StringInitializerListMap. */ -QList<WriteInitialization::Item *> WriteInitialization::initializeTreeWidgetItems(const QList<DomItem *> &domItems) +QList<WriteInitialization::Item *> WriteInitialization::initializeTreeWidgetItems(const QVector<DomItem *> &domItems) { // items QList<Item *> items; @@ -2237,7 +2179,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w) const QString varName = m_driver->findOrInsertWidget(w); // columns - const QList<DomColumn *> columns = w->elementColumn(); + const auto &columns = w->elementColumn(); if (columns.size() != 0) { m_output << m_indent << "if (" << varName << "->columnCount() < " << columns.size() << ")\n" @@ -2259,7 +2201,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w) } // rows - const QList<DomRow *> rows = w->elementRow(); + const auto &rows = w->elementRow(); if (rows.size() != 0) { m_output << m_indent << "if (" << varName << "->rowCount() < " << rows.size() << ")\n" @@ -2283,7 +2225,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w) // items QString tempName = disableSorting(w, varName); - const QList<DomItem *> items = w->elementItem(); + const auto &items = w->elementItem(); for (int i = 0; i < items.size(); ++i) { const DomItem *cell = items.at(i); @@ -2428,11 +2370,6 @@ void WriteInitialization::acceptConnection(DomConnection *connection) << ");\n"; } -DomImage *WriteInitialization::findImage(const QString &name) const -{ - return m_registeredImages.value(name); -} - DomWidget *WriteInitialization::findWidget(QLatin1String widgetClass) { for (int i = m_widgetChain.count() - 1; i >= 0; --i) { @@ -2445,49 +2382,6 @@ DomWidget *WriteInitialization::findWidget(QLatin1String widgetClass) return 0; } -void WriteInitialization::acceptImage(DomImage *image) -{ - if (!image->hasAttributeName()) - return; - - m_registeredImages.insert(image->attributeName(), image); -} - -void WriteInitialization::acceptWidgetScripts(const DomScripts &widgetScripts, DomWidget *node, const DomWidgets &childWidgets) -{ - // Add the per-class custom scripts to the per-widget ones. - DomScripts scripts(widgetScripts); - - if (DomScript *customWidgetScript = m_uic->customWidgetsInfo()->customWidgetScript(node->attributeClass())) - scripts.push_front(customWidgetScript); - - if (scripts.empty()) - return; - - // concatenate script snippets - QString script; - for (const DomScript *domScript : qAsConst(scripts)) { - const QString snippet = domScript->text(); - if (!snippet.isEmpty()) - script += QStringRef(&snippet).trimmed() + QLatin1Char('\n'); - } - if (script.isEmpty()) - return; - - // Build the list of children and insert call - m_output << m_indent << "childWidgets.clear();\n"; - if (!childWidgets.empty()) { - m_output << m_indent << "childWidgets"; - for (DomWidget *child : childWidgets) - m_output << " << " << m_driver->findOrInsertWidget(child); - m_output << ";\n"; - } - m_output << m_indent << "scriptContext.run(" - << writeString(script, m_dindent) << ", " - << m_driver->findOrInsertWidget(node) << ", childWidgets);\n"; -} - - static void generateMultiDirectiveBegin(QTextStream &outputStream, const QSet<QString> &directives) { if (directives.isEmpty()) diff --git a/src/tools/uic/cpp/cppwriteinitialization.h b/src/tools/uic/cpp/cppwriteinitialization.h index a9691e1de4..187ba8378e 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.h +++ b/src/tools/uic/cpp/cppwriteinitialization.h @@ -88,14 +88,13 @@ struct WriteInitialization : public TreeWalker typedef QList<DomProperty*> DomPropertyList; typedef QHash<QString, DomProperty*> DomPropertyMap; - WriteInitialization(Uic *uic, bool activateScripts); + WriteInitialization(Uic *uic); // // widgets // void acceptUI(DomUI *node) Q_DECL_OVERRIDE; void acceptWidget(DomWidget *node) Q_DECL_OVERRIDE; - void acceptWidgetScripts(const DomScripts &, DomWidget *node, const DomWidgets &childWidgets) Q_DECL_OVERRIDE; void acceptLayout(DomLayout *node) Q_DECL_OVERRIDE; void acceptSpacer(DomSpacer *node) Q_DECL_OVERRIDE; @@ -130,11 +129,6 @@ struct WriteInitialization : public TreeWalker // void acceptConnection(DomConnection *connection) Q_DECL_OVERRIDE; -// -// images -// - void acceptImage(DomImage *image) Q_DECL_OVERRIDE; - enum { Use43UiFile = 0, TopLevelMargin, @@ -221,7 +215,7 @@ private: void initializeComboBox(DomWidget *w); void initializeListWidget(DomWidget *w); void initializeTreeWidget(DomWidget *w); - QList<Item *> initializeTreeWidgetItems(const QList<DomItem *> &domItems); + QList<Item *> initializeTreeWidgetItems(const QVector<DomItem *> &domItems); void initializeTableWidget(DomWidget *w); QString disableSorting(DomWidget *w, const QString &varName); @@ -229,7 +223,6 @@ private: QString findDeclaration(const QString &name); DomWidget *findWidget(QLatin1String widgetClass); - DomImage *findImage(const QString &name) const; bool isValidObject(const QString &name) const; @@ -263,7 +256,6 @@ private: QSet<QString> m_buttonGroups; QHash<QString, DomWidget*> m_registeredWidgets; - QHash<QString, DomImage*> m_registeredImages; QHash<QString, DomAction*> m_registeredActions; typedef QHash<uint, QString> ColorBrushHash; ColorBrushHash m_colorBrushHash; @@ -314,7 +306,6 @@ private: QString m_delayedActionInitialization; QTextStream m_actionOut; - const bool m_activateScripts; bool m_layoutWidget; bool m_firstThemeIcon; |