diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qguiaction.h | 2 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.h | 6 | ||||
-rw-r--r-- | src/widgets/kernel/qtestsupport_widgets.h | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.h | 12 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractbutton.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 48 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox_p.h | 82 | ||||
-rw-r--r-- | src/widgets/widgets/qgroupbox.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qtoolbar.h | 12 | ||||
-rw-r--r-- | src/xml/dom/qdom.cpp | 77 | ||||
-rw-r--r-- | src/xml/dom/qdom.h | 3 | ||||
-rw-r--r-- | src/xml/dom/qdom_p.h | 2 | ||||
-rw-r--r-- | src/xml/dom/qdomhelpers.cpp | 272 | ||||
-rw-r--r-- | src/xml/dom/qdomhelpers_p.h | 42 |
16 files changed, 473 insertions, 109 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index a35e55b8f0..554c24356b 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -4826,9 +4826,11 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) /*! \macro qMove(x) \relates <QtGlobal> + \obsolete - It expands to "std::move" if your compiler supports that C++11 function, or to nothing - otherwise. + Use \c std::move instead. + + It expands to "std::move". qMove takes an rvalue reference to its parameter \a x, and converts it to an xvalue. */ @@ -4929,6 +4931,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) /*! \macro Q_DECL_OVERRIDE \since 5.0 + \obsolete \relates <QtGlobal> This macro can be used to declare an overriding virtual @@ -4936,8 +4939,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) an error if the overriding virtual function does not in fact override anything. - It expands to "override" if your compiler supports that C++11 - contextual keyword, or to nothing otherwise. + It expands to "override". The macro goes at the end of the function, usually after the \c{const}, if any: @@ -4949,6 +4951,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) /*! \macro Q_DECL_FINAL \since 5.0 + \obsolete \relates <QtGlobal> This macro can be used to declare an overriding virtual or a class @@ -4956,10 +4959,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) no longer override this virtual function, or inherit from this class, respectively. - It expands to "final" if your compiler supports that C++11 - contextual keyword, or something non-standard if your compiler - supports something close enough to the C++11 semantics, or to - nothing otherwise. + It expands to "final". The macro goes at the end of the function, usually after the \c{const}, if any: diff --git a/src/gui/kernel/qguiaction.h b/src/gui/kernel/qguiaction.h index bd7d13e156..454f66893f 100644 --- a/src/gui/kernel/qguiaction.h +++ b/src/gui/kernel/qguiaction.h @@ -62,7 +62,7 @@ class Q_GUI_EXPORT QGuiAction : public QObject Q_DECLARE_PRIVATE(QGuiAction) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed) Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed) Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed) diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index a1b1c2e92b..2f02f62a57 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -243,7 +243,7 @@ void QTextDocumentPrivate::clear() curs->adjusted_anchor = 0; } - QList<QTextCursorPrivate *>oldCursors = cursors; + QSet<QTextCursorPrivate *> oldCursors = cursors; QT_TRY{ cursors.clear(); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index f4e7a25f22..94c67b3264 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -277,8 +277,8 @@ private: public: void documentChange(int from, int length); - inline void addCursor(QTextCursorPrivate *c) { cursors.append(c); } - inline void removeCursor(QTextCursorPrivate *c) { cursors.removeAll(c); } + inline void addCursor(QTextCursorPrivate *c) { cursors.insert(c); } + inline void removeCursor(QTextCursorPrivate *c) { cursors.remove(c); } QTextFrame *frameAt(int pos) const; QTextFrame *rootFrame() const; @@ -330,7 +330,7 @@ private: BlockMap blocks; int initialBlockCharFormatIndex; - QList<QTextCursorPrivate *> cursors; + QSet<QTextCursorPrivate *> cursors; QMap<int, QTextObject *> objects; QMap<QUrl, QVariant> resources; QMap<QUrl, QVariant> cachedResources; diff --git a/src/widgets/kernel/qtestsupport_widgets.h b/src/widgets/kernel/qtestsupport_widgets.h index ca1406b0b2..2b37a9e858 100644 --- a/src/widgets/kernel/qtestsupport_widgets.h +++ b/src/widgets/kernel/qtestsupport_widgets.h @@ -40,7 +40,7 @@ #ifndef QTESTSUPPORT_WIDGETS_H #define QTESTSUPPORT_WIDGETS_H -#include "qtwidgetsglobal.h" +#include <QtWidgets/qtwidgetsglobal.h> QT_BEGIN_NAMESPACE diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index 86f937c4c6..5117fa94c8 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -177,11 +177,11 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(QSize sizeHint READ sizeHint) Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint) Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops) - Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged DESIGNABLE isWindow) - Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged DESIGNABLE isWindow) - Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged DESIGNABLE isWindow) // deprecated - Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow) - Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow) + Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged) + Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged) + Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged) // deprecated + Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity) + Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified) #ifndef QT_NO_TOOLTIP Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip) Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration) @@ -203,7 +203,7 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) #endif Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale) - Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath DESIGNABLE isWindow) + Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) public: diff --git a/src/widgets/widgets/qabstractbutton.h b/src/widgets/widgets/qabstractbutton.h index c6f6e4c546..d44da2f4f3 100644 --- a/src/widgets/widgets/qabstractbutton.h +++ b/src/widgets/widgets/qabstractbutton.h @@ -66,7 +66,7 @@ class Q_WIDGETS_EXPORT QAbstractButton : public QWidget Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) #endif Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true) Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat) Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive) Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay) diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 03dcde0a58..19b442f477 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -91,30 +91,11 @@ QT_BEGIN_NAMESPACE QComboBoxPrivate::QComboBoxPrivate() : QWidgetPrivate(), - model(0), - lineEdit(0), - container(0), - insertPolicy(QComboBox::InsertAtBottom), - sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow), - minimumContentsLength(0), shownOnce(false), autoCompletion(true), duplicatesEnabled(false), frame(true), - maxVisibleItems(10), - maxCount(INT_MAX), - modelColumn(0), - inserting(false), - arrowState(QStyle::State_None), - hoverControl(QStyle::SC_None), - autoCompletionCaseSensitivity(Qt::CaseInsensitive), - indexBeforeChange(-1) -#ifdef Q_OS_MAC - , m_platformMenu(0) -#endif -#if QT_CONFIG(completer) - , completer(0) -#endif + inserting(false) { } @@ -447,12 +428,8 @@ void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e) QFrame::paintEvent(e); } -void QComboBoxPrivateContainer::leaveEvent(QEvent *) -{ -} - QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent) - : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false) + : QFrame(parent, Qt::Popup), combo(parent) { // we need the combobox and itemview Q_ASSERT(parent); @@ -557,7 +534,7 @@ void QComboBoxPrivateContainer::updateScrollers() */ void QComboBoxPrivateContainer::viewDestroyed() { - view = 0; + view = nullptr; setItemView(new QComboBoxListView()); } @@ -591,7 +568,7 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView) if (isAncestorOf(view)) delete view; - view = 0; + view = nullptr; } // setup the item view @@ -1568,7 +1545,7 @@ void QComboBox::setAutoCompletion(bool enable) d->lineEdit->setCompleter(d->completer); d->completer->setWidget(this); } else { - d->lineEdit->setCompleter(0); + d->lineEdit->setCompleter(nullptr); } } @@ -1757,7 +1734,7 @@ QSize QComboBox::iconSize() const if (d->iconSize.isValid()) return d->iconSize; - int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); + int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this); return QSize(iconWidth, iconWidth); } @@ -1827,7 +1804,7 @@ QString QComboBox::placeholderText() const bool QComboBox::isEditable() const { Q_D(const QComboBox); - return d->lineEdit != 0; + return d->lineEdit != nullptr; } /*! \internal @@ -1883,7 +1860,7 @@ void QComboBox::setEditable(bool editable) setAttribute(Qt::WA_InputMethodEnabled, false); d->lineEdit->hide(); d->lineEdit->deleteLater(); - d->lineEdit = 0; + d->lineEdit = nullptr; } d->updateDelegate(); @@ -1932,6 +1909,8 @@ void QComboBox::setLineEdit(QLineEdit *edit) d->lineEdit->setFocusProxy(this); d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); #if QT_DEPRECATED_SINCE(5, 13) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED #if QT_CONFIG(completer) setAutoCompletion(d->autoCompletion); @@ -1948,6 +1927,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) } #endif #endif +QT_WARNING_POP #endif setAttribute(Qt::WA_InputMethodEnabled); @@ -1996,7 +1976,7 @@ void QComboBox::setValidator(const QValidator *v) const QValidator *QComboBox::validator() const { Q_D(const QComboBox); - return d->lineEdit ? d->lineEdit->validator() : 0; + return d->lineEdit ? d->lineEdit->validator() : nullptr; } #endif // QT_NO_VALIDATOR @@ -2040,7 +2020,7 @@ void QComboBox::setCompleter(QCompleter *c) QCompleter *QComboBox::completer() const { Q_D(const QComboBox); - return d->lineEdit ? d->lineEdit->completer() : 0; + return d->lineEdit ? d->lineEdit->completer() : nullptr; } #endif // QT_CONFIG(completer) @@ -2927,7 +2907,7 @@ void QComboBox::hidePopup() QSignalBlocker containerBlocker(d->container); // Flash selected/triggered item (if any). if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) { - QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0; + QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : nullptr; if (selectionModel && selectionModel->hasSelection()) { QEventLoop eventLoop; const QItemSelection selection = selectionModel->selection(); diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 00211d70aa..c79406eafd 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -79,7 +79,6 @@ QT_REQUIRE_CONFIG(combobox); QT_BEGIN_NAMESPACE -class QAction; class QPlatformMenu; class QComboBoxListView : public QListView @@ -131,9 +130,6 @@ private: QComboBox *combo; }; - -class QStandardItemModel; - class Q_AUTOTEST_EXPORT QComboBoxPrivateScroller : public QWidget { Q_OBJECT @@ -212,7 +208,7 @@ Q_SIGNALS: private: QAbstractSlider::SliderAction sliderAction; QBasicTimer timer; - bool fast; + bool fast = false; }; class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame @@ -246,7 +242,6 @@ protected: void showEvent(QShowEvent *e) override; void hideEvent(QHideEvent *e) override; void timerEvent(QTimerEvent *timerEvent) override; - void leaveEvent(QEvent *e) override; void resizeEvent(QResizeEvent *e) override; void paintEvent(QPaintEvent *e) override; QStyleOptionComboBox comboStyleOption() const; @@ -257,18 +252,19 @@ Q_SIGNALS: private: QComboBox *combo; - QAbstractItemView *view; - QComboBoxPrivateScroller *top; - QComboBoxPrivateScroller *bottom; - bool maybeIgnoreMouseButtonRelease; + QAbstractItemView *view = nullptr; + QComboBoxPrivateScroller *top = nullptr; + QComboBoxPrivateScroller *bottom = nullptr; QElapsedTimer popupTimer; + bool maybeIgnoreMouseButtonRelease = false; friend class QComboBox; friend class QComboBoxPrivate; }; class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate -{ Q_OBJECT +{ + Q_OBJECT public: QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {} @@ -355,8 +351,8 @@ public: void _q_complete(); void _q_itemSelected(const QModelIndex &item); bool contains(const QString &text, int role); - void emitActivated(const QModelIndex&); - void _q_emitHighlighted(const QModelIndex&); + void emitActivated(const QModelIndex &index); + void _q_emitHighlighted(const QModelIndex &index); void _q_emitCurrentIndexChanged(const QModelIndex &index); void _q_modelDestroyed(); void _q_modelReset(); @@ -366,8 +362,8 @@ public: void _q_resetButton(); void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void _q_updateIndexBeforeChange(); - void _q_rowsInserted(const QModelIndex & parent, int start, int end); - void _q_rowsRemoved(const QModelIndex & parent, int start, int end); + void _q_rowsInserted(const QModelIndex &parent, int start, int end); + void _q_rowsRemoved(const QModelIndex &parent, int start, int end); void updateArrow(QStyle::StateFlag state); bool updateHoverControl(const QPoint &pos); QRect popupGeometry(int screen = -1) const; @@ -402,40 +398,38 @@ public: }; #endif - QAbstractItemModel *model; - QLineEdit *lineEdit; - QComboBoxPrivateContainer *container; - QComboBox::InsertPolicy insertPolicy; - QComboBox::SizeAdjustPolicy sizeAdjustPolicy; - int minimumContentsLength; - QSize iconSize; - uint shownOnce : 1; - uint autoCompletion : 1; - uint duplicatesEnabled : 1; - uint frame : 1; - uint padding : 26; - int maxVisibleItems; - int maxCount; - int modelColumn; - QString placeholderText; - bool inserting; - mutable QSize minimumSizeHint; - mutable QSize sizeHint; - QStyle::StateFlag arrowState; - QStyle::SubControl hoverControl; - QRect hoverRect; - QPersistentModelIndex currentIndex; - QPersistentModelIndex root; - Qt::CaseSensitivity autoCompletionCaseSensitivity; - int indexBeforeChange; + QAbstractItemModel *model = nullptr; + QLineEdit *lineEdit = nullptr; + QComboBoxPrivateContainer *container = nullptr; #ifdef Q_OS_MAC - QPlatformMenu *m_platformMenu; + QPlatformMenu *m_platformMenu = nullptr; #endif #if QT_CONFIG(completer) QPointer<QCompleter> completer; #endif - static QPalette viewContainerPalette(QComboBox *cmb) - { return cmb->d_func()->viewContainer()->palette(); } + QPersistentModelIndex currentIndex; + QPersistentModelIndex root; + QString placeholderText; + QRect hoverRect; + QSize iconSize; + mutable QSize minimumSizeHint; + mutable QSize sizeHint; + QComboBox::InsertPolicy insertPolicy = QComboBox::InsertAtBottom; + QComboBox::SizeAdjustPolicy sizeAdjustPolicy = QComboBox::AdjustToContentsOnFirstShow; + QStyle::StateFlag arrowState = QStyle::State_None; + QStyle::SubControl hoverControl = QStyle::SC_None; + Qt::CaseSensitivity autoCompletionCaseSensitivity = Qt::CaseInsensitive; + int minimumContentsLength = 0; + int indexBeforeChange = -1; + int maxVisibleItems = 10; + int maxCount = std::numeric_limits<int>::max(); + int modelColumn = 0; + int placeholderIndex = -1; + bool shownOnce : 1; + bool autoCompletion : 1; + bool duplicatesEnabled : 1; + bool frame : 1; + bool inserting : 1; }; QT_END_NAMESPACE diff --git a/src/widgets/widgets/qgroupbox.h b/src/widgets/widgets/qgroupbox.h index deaeba4656..bd8394b43b 100644 --- a/src/widgets/widgets/qgroupbox.h +++ b/src/widgets/widgets/qgroupbox.h @@ -57,7 +57,7 @@ class Q_WIDGETS_EXPORT QGroupBox : public QWidget Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) Q_PROPERTY(bool flat READ isFlat WRITE setFlat) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true) public: explicit QGroupBox(QWidget *parent = nullptr); explicit QGroupBox(const QString &title, QWidget *parent = nullptr); diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 0c434e8d1d..6aaf59cafd 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -59,15 +59,9 @@ class Q_WIDGETS_EXPORT QToolBar : public QWidget { Q_OBJECT - Q_PROPERTY(bool movable READ isMovable WRITE setMovable - DESIGNABLE (qobject_cast<QMainWindow *>(parentWidget()) != 0) - NOTIFY movableChanged) - Q_PROPERTY(Qt::ToolBarAreas allowedAreas READ allowedAreas WRITE setAllowedAreas - DESIGNABLE (qobject_cast<QMainWindow *>(parentWidget()) != 0) - NOTIFY allowedAreasChanged) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation - DESIGNABLE (qobject_cast<QMainWindow *>(parentWidget()) == 0) - NOTIFY orientationChanged) + Q_PROPERTY(bool movable READ isMovable WRITE setMovable NOTIFY movableChanged) + Q_PROPERTY(Qt::ToolBarAreas allowedAreas READ allowedAreas WRITE setAllowedAreas NOTIFY allowedAreasChanged) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle NOTIFY toolButtonStyleChanged) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index b3357d7835..3d236863f4 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -59,6 +59,7 @@ #include <qvariant.h> #include <qshareddata.h> #include <qdebug.h> +#include <qxmlstream.h> #include <stdio.h> QT_BEGIN_NAMESPACE @@ -5734,6 +5735,34 @@ bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader return true; } +bool QDomDocumentPrivate::setContent(QXmlStreamReader *reader, bool namespaceProcessing, + QString *errorMsg, int *errorLine, int *errorColumn) +{ + clear(); + impl = new QDomImplementationPrivate; + type = new QDomDocumentTypePrivate(this, this); + type->ref.deref(); + + if (!reader) { + qWarning("Failed to set content, XML reader is not initialized"); + return false; + } + + QDomParser domParser(this, reader, namespaceProcessing); + + if (!domParser.parse()) { + if (errorMsg) + *errorMsg = std::get<0>(domParser.errorInfo()); + if (errorLine) + *errorLine = std::get<1>(domParser.errorInfo()); + if (errorColumn) + *errorColumn = std::get<2>(domParser.errorInfo()); + return false; + } + + return true; +} + QDomNodePrivate* QDomDocumentPrivate::cloneNode(bool deep) { QDomNodePrivate *p = new QDomDocumentPrivate(this, deep); @@ -6153,9 +6182,16 @@ bool QDomDocument::setContent(const QString& text, bool namespaceProcessing, QSt { if (!impl) impl = new QDomDocumentPrivate(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QXmlInputSource source; source.setData(text); return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn); +#else + QXmlStreamReader streamReader(text); + streamReader.setNamespaceProcessing(namespaceProcessing); + return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn); +#endif } /*! @@ -6215,10 +6251,17 @@ bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing, { if (!impl) impl = new QDomDocumentPrivate(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QBuffer buf; buf.setData(data); QXmlInputSource source(&buf); return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn); +#else + QXmlStreamReader streamReader(data); + streamReader.setNamespaceProcessing(namespaceProcessing); + return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn); +#endif } /*! @@ -6231,8 +6274,15 @@ bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing, QString { if (!impl) impl = new QDomDocumentPrivate(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QXmlInputSource source(dev); return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn); +#else + QXmlStreamReader streamReader(dev); + streamReader.setNamespaceProcessing(namespaceProcessing); + return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn); +#endif } /*! @@ -6315,6 +6365,33 @@ bool QDomDocument::setContent(QXmlInputSource *source, QXmlReader *reader, QStri } /*! + \overload + \since 5.15 + + This function reads the XML document from the QXmlStreamReader \a reader + and parses it. Returns \c true if the content was successfully parsed; + otherwise returns \c false. + + If \a namespaceProcessing is \c true, the parser recognizes namespaces in the XML + file and sets the prefix name, local name and namespace URI to appropriate values. + If \a namespaceProcessing is \c false, the parser does no namespace processing when + it reads the XML file. + + If a parse error occurs, the error message is placed in \c{*}\a{errorMsg}, the line + number in \c{*}\a{errorLine} and the column number in \c{*}\a{errorColumn} (unless + the associated pointer is set to 0). + + \sa QXmlStreamReader +*/ +bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg, + int *errorLine, int *errorColumn) +{ + if (!impl) + impl = new QDomDocumentPrivate(); + return IMPL->setContent(reader, namespaceProcessing, errorMsg, errorLine, errorColumn); +} + +/*! Converts the parsed document back to its textual representation. This function uses \a indent as the amount of space to indent diff --git a/src/xml/dom/qdom.h b/src/xml/dom/qdom.h index 2d07e34f3b..84abaea53e 100644 --- a/src/xml/dom/qdom.h +++ b/src/xml/dom/qdom.h @@ -91,6 +91,7 @@ class QDomNode; class QDomEntity; class QDomNotation; class QDomCharacterData; +class QXmlStreamReader; class Q_XML_EXPORT QDomImplementation { @@ -343,6 +344,8 @@ public: bool setContent(const QString& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr ); bool setContent(QIODevice* dev, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr ); bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr ); + bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr, + int *errorLine = nullptr, int *errorColumn = nullptr); // Qt extensions QString toString(int = 1) const; diff --git a/src/xml/dom/qdom_p.h b/src/xml/dom/qdom_p.h index 06ed0d5f0e..d197e999f1 100644 --- a/src/xml/dom/qdom_p.h +++ b/src/xml/dom/qdom_p.h @@ -465,6 +465,8 @@ public: int *errorLine, int *errorColumn); bool setContent(QXmlInputSource *source, QXmlReader *reader, QXmlSimpleReader *simpleReader, QString *errorMsg, int *errorLine, int *errorColumn); + bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg, + int *errorLine, int *errorColumn); // Attributes QDomDocumentTypePrivate *doctype() { return type.data(); } diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp index bda6f8ef87..9399ad3b9b 100644 --- a/src/xml/dom/qdomhelpers.cpp +++ b/src/xml/dom/qdomhelpers.cpp @@ -39,6 +39,7 @@ #include "qdomhelpers_p.h" #include "qdom_p.h" +#include "qxmlstream.h" #include "private/qxml_p.h" QT_BEGIN_NAMESPACE @@ -166,6 +167,18 @@ QDomBuilder::ErrorInfo QDomHandler::errorInfo() const * **************************************************************/ +int QDomDocumentLocator::column() const +{ + Q_ASSERT(reader); + return static_cast<int>(reader->columnNumber()); +} + +int QDomDocumentLocator::line() const +{ + Q_ASSERT(reader); + return static_cast<int>(reader->lineNumber()); +} + void QSAXDocumentLocator::setLocator(QXmlLocator *l) { locator = l; @@ -252,6 +265,44 @@ bool QDomBuilder::startElement(const QString &nsURI, const QString &qName, return true; } +inline QString stringRefToString(const QStringRef &stringRef) +{ + // Calling QStringRef::toString() on a NULL QStringRef in some cases returns + // an empty string (i.e. QString("")) instead of a NULL string (i.e. QString()). + // QDom implementation differentiates between NULL and empty strings, so + // we need this as workaround to keep the current behavior unchanged. + return stringRef.isNull() ? QString() : stringRef.toString(); +} + +bool QDomBuilder::startElement(const QString &nsURI, const QString &qName, + const QXmlStreamAttributes &atts) +{ + QDomNodePrivate *n = + nsProcessing ? doc->createElementNS(nsURI, qName) : doc->createElement(qName); + if (!n) + return false; + + n->setLocation(locator->line(), locator->column()); + + node->appendChild(n); + node = n; + + // attributes + for (const auto &attr : atts) { + auto domElement = static_cast<QDomElementPrivate *>(node); + if (nsProcessing) { + domElement->setAttributeNS(stringRefToString(attr.namespaceUri()), + stringRefToString(attr.qualifiedName()), + stringRefToString(attr.value())); + } else { + domElement->setAttribute(stringRefToString(attr.qualifiedName()), + stringRefToString(attr.value())); + } + } + + return true; +} + bool QDomBuilder::endElement() { if (!node || node == doc) @@ -368,4 +419,225 @@ bool QDomBuilder::notationDecl(const QString &name, const QString &publicId, return true; } +/************************************************************** + * + * QDomParser + * + **************************************************************/ + +QDomParser::QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, bool namespaceProcessing) + : reader(r), locator(r), domBuilder(d, &locator, namespaceProcessing) +{ +} + +bool QDomParser::parse() +{ + return parseProlog() && parseBody(); +} + +QDomBuilder::ErrorInfo QDomParser::errorInfo() const +{ + return domBuilder.error(); +} + +bool QDomParser::parseProlog() +{ + Q_ASSERT(reader); + + bool foundDtd = false; + + while (!reader->atEnd()) { + reader->readNext(); + + if (reader->hasError()) { + domBuilder.fatalError(reader->errorString()); + return false; + } + + switch (reader->tokenType()) { + case QXmlStreamReader::StartDocument: + if (!reader->documentVersion().isEmpty()) { + QString value(QLatin1String("version='")); + value += reader->documentVersion(); + value += QLatin1Char('\''); + if (!reader->documentEncoding().isEmpty()) { + value += QLatin1String(" encoding='"); + value += reader->documentEncoding(); + value += QLatin1Char('\''); + } + if (reader->isStandaloneDocument()) { + value += QLatin1String(" standalone='yes'"); + } else { + // TODO: Add standalone='no', if 'standalone' is specified. With the current + // QXmlStreamReader there is no way to figure out if it was specified or not. + // QXmlStreamReader needs to be modified for handling that case correctly. + } + + if (!domBuilder.processingInstruction(QLatin1String("xml"), value)) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing XML declaration")); + return false; + } + } + break; + case QXmlStreamReader::DTD: + if (foundDtd) { + domBuilder.fatalError(QDomParser::tr("Multiple DTD sections are not allowed")); + return false; + } + foundDtd = true; + + if (!domBuilder.startDTD(stringRefToString(reader->dtdName()), + stringRefToString(reader->dtdPublicId()), + stringRefToString(reader->dtdSystemId()))) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing document type declaration")); + return false; + } + if (!parseMarkupDecl()) + return false; + break; + case QXmlStreamReader::Comment: + if (!domBuilder.comment(reader->text().toString())) { + domBuilder.fatalError(QDomParser::tr("Error occurred while processing comment")); + return false; + } + break; + case QXmlStreamReader::ProcessingInstruction: + if (!domBuilder.processingInstruction(reader->processingInstructionTarget().toString(), + reader->processingInstructionData().toString())) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing a processing instruction")); + return false; + } + break; + default: + // If the token is none of the above, prolog processing is done. + return true; + } + } + + return true; +} + +bool QDomParser::parseBody() +{ + Q_ASSERT(reader); + + std::stack<QStringRef> tagStack; + while (!reader->atEnd() && !reader->hasError()) { + switch (reader->tokenType()) { + case QXmlStreamReader::StartElement: + tagStack.push(reader->qualifiedName()); + if (!domBuilder.startElement(stringRefToString(reader->namespaceUri()), + stringRefToString(reader->qualifiedName()), + reader->attributes())) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing a start element")); + return false; + } + break; + case QXmlStreamReader::EndElement: + if (tagStack.empty() || reader->qualifiedName() != tagStack.top()) { + domBuilder.fatalError( + QDomParser::tr("Unexpected end element '%1'").arg(reader->name())); + return false; + } + tagStack.pop(); + if (!domBuilder.endElement()) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing an end element")); + return false; + } + break; + case QXmlStreamReader::Characters: + if (!reader->isWhitespace()) { // Skip the content consisting of only whitespaces + if (!reader->text().toString().trimmed().isEmpty()) { + if (!domBuilder.characters(reader->text().toString(), reader->isCDATA())) { + domBuilder.fatalError(QDomParser::tr( + "Error occurred while processing the element content")); + return false; + } + } + } + break; + case QXmlStreamReader::Comment: + if (!domBuilder.comment(reader->text().toString())) { + domBuilder.fatalError(QDomParser::tr("Error occurred while processing comments")); + return false; + } + break; + case QXmlStreamReader::ProcessingInstruction: + if (!domBuilder.processingInstruction(reader->processingInstructionTarget().toString(), + reader->processingInstructionData().toString())) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing a processing instruction")); + return false; + } + break; + case QXmlStreamReader::EntityReference: + if (!domBuilder.skippedEntity(reader->name().toString())) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing an entity reference")); + return false; + } + break; + default: + domBuilder.fatalError(QDomParser::tr("Unexpected token")); + return false; + } + + reader->readNext(); + } + + if (reader->hasError()) { + domBuilder.fatalError(reader->errorString()); + reader->readNext(); + return false; + } + + if (!tagStack.empty()) { + domBuilder.fatalError(QDomParser::tr("Tag mismatch")); + return false; + } + + return true; +} + +bool QDomParser::parseMarkupDecl() +{ + Q_ASSERT(reader); + + const auto entities = reader->entityDeclarations(); + for (const auto &entityDecl : entities) { + // Entity declarations are created only for Extrenal Entities. Internal Entities + // are parsed, and QXmlStreamReader handles the parsing itself and returns the + // parsed result. So we don't need to do anything for the Internal Entities. + if (!entityDecl.publicId().isEmpty() || !entityDecl.systemId().isEmpty()) { + // External Entity + if (!domBuilder.unparsedEntityDecl(stringRefToString(entityDecl.name()), + stringRefToString(entityDecl.publicId()), + stringRefToString(entityDecl.systemId()), + stringRefToString(entityDecl.notationName()))) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing entity declaration")); + return false; + } + } + } + + const auto notations = reader->notationDeclarations(); + for (const auto ¬ationDecl : notations) { + if (!domBuilder.notationDecl(stringRefToString(notationDecl.name()), + stringRefToString(notationDecl.publicId()), + stringRefToString(notationDecl.systemId()))) { + domBuilder.fatalError( + QDomParser::tr("Error occurred while processing notation declaration")); + return false; + } + } + + return true; +} + QT_END_NAMESPACE diff --git a/src/xml/dom/qdomhelpers_p.h b/src/xml/dom/qdomhelpers_p.h index 7647de65d2..f5efd8a42d 100644 --- a/src/xml/dom/qdomhelpers_p.h +++ b/src/xml/dom/qdomhelpers_p.h @@ -39,6 +39,7 @@ #ifndef QDOMHELPERS_P_H #define QDOMHELPERS_P_H +#include <qcoreapplication.h> #include <qglobal.h> #include <qxml.h> @@ -57,6 +58,8 @@ QT_BEGIN_NAMESPACE class QDomDocumentPrivate; class QDomNodePrivate; +class QXmlStreamReader; +class QXmlStreamAttributes; /************************************************************** * @@ -77,6 +80,19 @@ public: virtual int line() const = 0; }; +class QDomDocumentLocator : public QXmlDocumentLocator +{ +public: + QDomDocumentLocator(QXmlStreamReader *r) : reader(r) {} + ~QDomDocumentLocator() override = default; + + int column() const override; + int line() const override; + +private: + QXmlStreamReader *reader; +}; + class QSAXDocumentLocator : public QXmlDocumentLocator { public: @@ -105,6 +121,7 @@ public: bool endDocument(); bool startElement(const QString &nsURI, const QString &qName, const QXmlAttributes &atts); + bool startElement(const QString &nsURI, const QString &qName, const QXmlStreamAttributes &atts); bool endElement(); bool characters(const QString &characters, bool cdata = false); bool processingInstruction(const QString &target, const QString &data); @@ -188,6 +205,31 @@ private: QDomBuilder domBuilder; }; +/************************************************************** + * + * QDomParser + * + **************************************************************/ + +class QDomParser +{ + Q_DECLARE_TR_FUNCTIONS(QDomParser) +public: + QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, bool namespaceProcessing); + + bool parse(); + QDomBuilder::ErrorInfo errorInfo() const; + +private: + bool parseProlog(); + bool parseBody(); + bool parseMarkupDecl(); + + QXmlStreamReader *reader; + QDomDocumentLocator locator; + QDomBuilder domBuilder; +}; + QT_END_NAMESPACE #endif // QDOMHELPERS_P_H |