diff options
24 files changed, 130 insertions, 50 deletions
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp index a9c53ed2cd..f20fb9f7c3 100644 --- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp +++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp @@ -132,7 +132,7 @@ QMimeData *PiecesModel::mimeData(const QModelIndexList &indexes) const QMimeData *mimeData = new QMimeData(); QByteArray encodedData; - QDataStream stream(&encodedData, QIODevice::WriteOnly); + QDataStream stream(&encodedData, QDataStream::WriteOnly); for (const QModelIndex &index : indexes) { if (index.isValid()) { @@ -170,7 +170,7 @@ bool PiecesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, } QByteArray encodedData = data->data("image/x-puzzle-piece"); - QDataStream stream(&encodedData, QIODevice::ReadOnly); + QDataStream stream(&encodedData, QDataStream::ReadOnly); while (!stream.atEnd()) { QPixmap pixmap; diff --git a/qmake/CMakeLists.txt b/qmake/CMakeLists.txt index 9e2c7b513c..2a7549f862 100644 --- a/qmake/CMakeLists.txt +++ b/qmake/CMakeLists.txt @@ -61,6 +61,7 @@ qt_add_tool(${target_name} ../src/corelib/io/qfilesystementry.cpp ../src/corelib/io/qfsfileengine.cpp ../src/corelib/io/qfsfileengine_iterator.cpp + ../src/corelib/io/qiodevicebase.h ../src/corelib/io/qiodevice.cpp ../src/corelib/io/qiodevice.h ../src/corelib/io/qsettings.cpp ../src/corelib/io/qtemporaryfile.cpp ../src/corelib/io/qtemporaryfile.h diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index ec4f1076be..6f78e2bdc6 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -71,6 +71,7 @@ qt_add_module(Core io/qfilesystemmetadata_p.h io/qfsfileengine.cpp io/qfsfileengine_p.h io/qfsfileengine_iterator.cpp io/qfsfileengine_iterator_p.h + io/qiodevicebase.h io/qiodevice.cpp io/qiodevice.h io/qiodevice_p.h io/qipaddress.cpp io/qipaddress_p.h io/qlockfile.cpp io/qlockfile.h io/qlockfile_p.h diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index c062d9948b..0808114bd3 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -15,6 +15,7 @@ HEADERS += \ io/qfileinfo.h \ io/qfileinfo_p.h \ io/qipaddress_p.h \ + io/qiodevicebase.h \ io/qiodevice.h \ io/qiodevice_p.h \ io/qlockfile.h \ diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 130ceccc44..2463095743 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE -class Q_CORE_EXPORT QDebug +class Q_CORE_EXPORT QDebug : public QIODeviceBase { friend class QMessageLogger; friend class QDebugStateSaver; @@ -70,9 +70,9 @@ class Q_CORE_EXPORT QDebug Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {} - Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), + Stream(QString *string) : ts(string, WriteOnly), ref(1), type(QtDebugMsg), space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {} - Stream(QtMsgType t) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(t), + Stream(QtMsgType t) : ts(&buffer, WriteOnly), ref(1), type(t), space(true), message_output(true), flags(DefaultVerbosity << VerbosityShift) {} QTextStream ts; QString buffer; diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index c29501404b..3d64e8820f 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -305,7 +305,7 @@ QIODevicePrivate::~QIODevicePrivate() */ /*! - \enum QIODevice::OpenModeFlag + \enum QIODeviceBase::OpenModeFlag This enum is used with open() to describe the mode in which a device is opened. It is also returned by openMode(). diff --git a/src/corelib/io/qiodevice.h b/src/corelib/io/qiodevice.h index 7012bbacba..fa43efdb4d 100644 --- a/src/corelib/io/qiodevice.h +++ b/src/corelib/io/qiodevice.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -41,6 +41,7 @@ #define QIODEVICE_H #include <QtCore/qglobal.h> +#include <QtCore/qiodevicebase.h> #ifndef QT_NO_QOBJECT #include <QtCore/qobject.h> #else @@ -61,27 +62,16 @@ class QIODevicePrivate; class Q_CORE_EXPORT QIODevice #ifndef QT_NO_QOBJECT - : public QObject + : public QObject, +#else + : #endif + public QIODeviceBase { #ifndef QT_NO_QOBJECT Q_OBJECT #endif public: - enum OpenModeFlag { - NotOpen = 0x0000, - ReadOnly = 0x0001, - WriteOnly = 0x0002, - ReadWrite = ReadOnly | WriteOnly, - Append = 0x0004, - Truncate = 0x0008, - Text = 0x0010, - Unbuffered = 0x0020, - NewOnly = 0x0040, - ExistingOnly = 0x0080 - }; - Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) - QIODevice(); #ifndef QT_NO_QOBJECT explicit QIODevice(QObject *parent); diff --git a/src/corelib/io/qiodevicebase.h b/src/corelib/io/qiodevicebase.h new file mode 100644 index 0000000000..f1032a1dde --- /dev/null +++ b/src/corelib/io/qiodevicebase.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIODEVICEBASE_H +#define QIODEVICEBASE_H + +#include <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +class QIODeviceBase +{ +public: + enum OpenModeFlag { + NotOpen = 0x0000, + ReadOnly = 0x0001, + WriteOnly = 0x0002, + ReadWrite = ReadOnly | WriteOnly, + Append = 0x0004, + Truncate = 0x0008, + Text = 0x0010, + Unbuffered = 0x0020, + NewOnly = 0x0040, + ExistingOnly = 0x0080 + }; + Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) +}; + +QT_END_NAMESPACE + +#endif // QIODEVICEBASE_H diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 1bb65336bf..a686e918c3 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -1919,7 +1919,7 @@ QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const QMimeData *data = new QMimeData(); QString format = types.at(0); QByteArray encoded; - QDataStream stream(&encoded, QIODevice::WriteOnly); + QDataStream stream(&encoded, QDataStream::WriteOnly); encodeData(indexes, stream); data->setData(format, encoded); return data; @@ -2007,7 +2007,7 @@ bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction acti column = 0; // decode and insert QByteArray encoded = data->data(format); - QDataStream stream(&encoded, QIODevice::ReadOnly); + QDataStream stream(&encoded, QDataStream::ReadOnly); return decodeData(row, column, parent, stream); } @@ -3730,7 +3730,7 @@ bool QAbstractTableModel::dropMimeData(const QMimeData *data, Qt::DropAction act return false; QByteArray encoded = data->data(format); - QDataStream stream(&encoded, QIODevice::ReadOnly); + QDataStream stream(&encoded, QDataStream::ReadOnly); // if the drop is on an item, replace the data in the items if (parent.isValid() && row == -1 && column == -1) { @@ -3781,7 +3781,7 @@ bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction acti return false; QByteArray encoded = data->data(format); - QDataStream stream(&encoded, QIODevice::ReadOnly); + QDataStream stream(&encoded, QDataStream::ReadOnly); // if the drop is on an item, replace the data in the items if (parent.isValid() && row == -1 && column == -1) { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 527feffa54..a7916cfb13 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -47,6 +47,7 @@ #include <QtCore/qbytearray.h> #include <QtCore/qvarlengtharray.h> #include <QtCore/qrefcount.h> +#include <QtCore/qdatastream.h> #ifndef QT_NO_QOBJECT #include <QtCore/qobjectdefs.h> #endif diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp index 308fbe9ae9..c5d0c855e3 100644 --- a/src/corelib/serialization/qcborstreamreader.cpp +++ b/src/corelib/serialization/qcborstreamreader.cpp @@ -45,6 +45,7 @@ #include <private/qbytearray_p.h> #include <private/qnumeric_p.h> #include <private/qstringconverter_p.h> +#include <qiodevice.h> #include <qdebug.h> #include <qstack.h> diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 7888296b85..c6135336cf 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -302,7 +302,7 @@ QDataStream::QDataStream(QIODevice *d) } /*! - \fn QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode mode) + \fn QDataStream::QDataStream(QByteArray *a, OpenMode mode) Constructs a data stream that operates on a byte array, \a a. The \a mode describes how the device is to be used. @@ -314,7 +314,7 @@ QDataStream::QDataStream(QIODevice *d) is created to wrap the byte array. */ -QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode flags) +QDataStream::QDataStream(QByteArray *a, OpenMode flags) { QBuffer *buf = new QBuffer(a); #ifndef QT_NO_QOBJECT @@ -755,6 +755,14 @@ void QDataStream::abortTransaction() dev->commitTransaction(); } +/*! + \internal +*/ +bool QDataStream::isDeviceTransactionStarted() const +{ + return dev && dev->isTransactionStarted(); +} + /***************************************************************************** QDataStream read functions *****************************************************************************/ diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 095a6681c2..ad47490ebf 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -41,8 +41,7 @@ #define QDATASTREAM_H #include <QtCore/qscopedpointer.h> -#include <QtCore/qiodevice.h> -#include <QtCore/qpair.h> +#include <QtCore/qiodevicebase.h> #include <QtCore/qcontainerfwd.h> #ifdef Status @@ -60,7 +59,7 @@ class QDataStreamPrivate; namespace QtPrivate { class StreamStateSaver; } -class Q_CORE_EXPORT QDataStream +class Q_CORE_EXPORT QDataStream : public QIODeviceBase { public: enum Version { @@ -122,7 +121,7 @@ public: QDataStream(); explicit QDataStream(QIODevice *); - QDataStream(QByteArray *, QIODevice::OpenMode flags); + QDataStream(QByteArray *, OpenMode flags); QDataStream(const QByteArray &); ~QDataStream(); @@ -199,6 +198,7 @@ public: void rollbackTransaction(); void abortTransaction(); + bool isDeviceTransactionStarted() const; private: Q_DISABLE_COPY(QDataStream) @@ -222,7 +222,7 @@ class StreamStateSaver public: inline StreamStateSaver(QDataStream *s) : stream(s), oldStatus(s->status()) { - if (!stream->dev || !stream->dev->isTransactionStarted()) + if (!stream->isDeviceTransactionStarted()) stream->resetStatus(); } inline ~StreamStateSaver() diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index c834f22834..9ba65ba02b 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -368,7 +368,7 @@ void QTextStreamPrivate::reset() deleteDevice = false; string = nullptr; stringOffset = 0; - stringOpenMode = QIODevice::NotOpen; + stringOpenMode = QTextStream::NotOpen; readBufferOffset = 0; readBufferStartDevicePos = 0; @@ -983,7 +983,7 @@ QTextStream::QTextStream(QIODevice *device) Constructs a QTextStream that operates on \a string, using \a openMode to define the open mode. */ -QTextStream::QTextStream(QString *string, QIODevice::OpenMode openMode) +QTextStream::QTextStream(QString *string, OpenMode openMode) : d_ptr(new QTextStreamPrivate(this)) { #if defined (QTEXTSTREAM_DEBUG) @@ -1001,7 +1001,7 @@ QTextStream::QTextStream(QString *string, QIODevice::OpenMode openMode) openMode to define the open mode. Internally, the array is wrapped by a QBuffer. */ -QTextStream::QTextStream(QByteArray *array, QIODevice::OpenMode openMode) +QTextStream::QTextStream(QByteArray *array, OpenMode openMode) : d_ptr(new QTextStreamPrivate(this)) { #if defined (QTEXTSTREAM_DEBUG) @@ -1028,7 +1028,7 @@ QTextStream::QTextStream(QByteArray *array, QIODevice::OpenMode openMode) \snippet code/src_corelib_io_qtextstream.cpp 3 */ -QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) +QTextStream::QTextStream(const QByteArray &array, OpenMode openMode) : d_ptr(new QTextStreamPrivate(this)) { #if defined (QTEXTSTREAM_DEBUG) @@ -1059,7 +1059,7 @@ QTextStream::QTextStream(const QByteArray &array, QIODevice::OpenMode openMode) \snippet code/src_corelib_io_qtextstream.cpp 4 */ -QTextStream::QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode) +QTextStream::QTextStream(FILE *fileHandle, OpenMode openMode) : d_ptr(new QTextStreamPrivate(this)) { #if defined (QTEXTSTREAM_DEBUG) @@ -1272,7 +1272,7 @@ QIODevice *QTextStream::device() const \sa string(), setDevice() */ -void QTextStream::setString(QString *string, QIODevice::OpenMode openMode) +void QTextStream::setString(QString *string, OpenMode openMode) { Q_D(QTextStream); flush(); diff --git a/src/corelib/serialization/qtextstream.h b/src/corelib/serialization/qtextstream.h index a3526c84fc..b196e9e935 100644 --- a/src/corelib/serialization/qtextstream.h +++ b/src/corelib/serialization/qtextstream.h @@ -40,10 +40,9 @@ #ifndef QTEXTSTREAM_H #define QTEXTSTREAM_H -#include <QtCore/qiodevice.h> +#include <QtCore/qiodevicebase.h> #include <QtCore/qstring.h> #include <QtCore/qchar.h> -#include <QtCore/qlocale.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qstringconverter.h> @@ -55,8 +54,11 @@ QT_BEGIN_NAMESPACE +class QIODevice; +class QLocale; + class QTextStreamPrivate; -class Q_CORE_EXPORT QTextStream // text stream class +class Q_CORE_EXPORT QTextStream : public QIODeviceBase { Q_DECLARE_PRIVATE(QTextStream) @@ -89,10 +91,10 @@ public: QTextStream(); explicit QTextStream(QIODevice *device); - explicit QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode = QIODevice::ReadWrite); - explicit QTextStream(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite); - explicit QTextStream(QByteArray *array, QIODevice::OpenMode openMode = QIODevice::ReadWrite); - explicit QTextStream(const QByteArray &array, QIODevice::OpenMode openMode = QIODevice::ReadOnly); + explicit QTextStream(FILE *fileHandle, OpenMode openMode = ReadWrite); + explicit QTextStream(QString *string, OpenMode openMode = ReadWrite); + explicit QTextStream(QByteArray *array, OpenMode openMode = ReadWrite); + explicit QTextStream(const QByteArray &array, OpenMode openMode = ReadOnly); virtual ~QTextStream(); void setEncoding(QStringConverter::Encoding encoding); @@ -108,7 +110,7 @@ public: void setDevice(QIODevice *device); QIODevice *device() const; - void setString(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite); + void setString(QString *string, OpenMode openMode = ReadWrite); QString *string() const; Status status() const; diff --git a/src/corelib/serialization/qtextstream_p.h b/src/corelib/serialization/qtextstream_p.h index cee79a7ecf..067a5ec94a 100644 --- a/src/corelib/serialization/qtextstream_p.h +++ b/src/corelib/serialization/qtextstream_p.h @@ -53,6 +53,8 @@ // #include <QtCore/private/qglobal_p.h> +#include "qiodevice.h" +#include "qlocale.h" #include "qtextstream.h" QT_BEGIN_NAMESPACE diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index 9bb0d9aa98..cf905eae66 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -47,6 +47,7 @@ #include <QtCore/qstringlist.h> #include <QtCore/qbitarray.h> #include <QtCore/qmimedata.h> +#include <QtCore/qiodevice.h> #include <private/qduplicatetracker_p.h> #include <private/qstandarditemmodel_p.h> #include <qdebug.h> diff --git a/src/gui/rhi/qrhiprofiler.cpp b/src/gui/rhi/qrhiprofiler.cpp index d2fbc6158b..e5ed15ed5a 100644 --- a/src/gui/rhi/qrhiprofiler.cpp +++ b/src/gui/rhi/qrhiprofiler.cpp @@ -36,6 +36,7 @@ #include "qrhiprofiler_p_p.h" #include "qrhi_p_p.h" +#include <QtCore/qiodevice.h> QT_BEGIN_NAMESPACE diff --git a/src/gui/util/qktxhandler.cpp b/src/gui/util/qktxhandler.cpp index f6aa46718d..f65eed7290 100644 --- a/src/gui/util/qktxhandler.cpp +++ b/src/gui/util/qktxhandler.cpp @@ -41,6 +41,7 @@ #include "qtexturefiledata_p.h" #include <QtEndian> #include <QSize> +#include <QtCore/qiodevice.h> //#define KTX_DEBUG #ifdef KTX_DEBUG diff --git a/src/network/ssl/qasn1element.cpp b/src/network/ssl/qasn1element.cpp index a01927b84d..65a0e08961 100644 --- a/src/network/ssl/qasn1element.cpp +++ b/src/network/ssl/qasn1element.cpp @@ -186,7 +186,7 @@ QAsn1Element QAsn1Element::fromVector(const QList<QAsn1Element> &items) { QAsn1Element seq; seq.mType = SequenceType; - QDataStream stream(&seq.mValue, QIODevice::WriteOnly); + QDataStream stream(&seq.mValue, QDataStream::WriteOnly); for (auto it = items.cbegin(), end = items.cend(); it != end; ++it) it->write(stream); return seq; diff --git a/src/tools/qlalr/lalr.cpp b/src/tools/qlalr/lalr.cpp index c3d3da41fa..853465c272 100644 --- a/src/tools/qlalr/lalr.cpp +++ b/src/tools/qlalr/lalr.cpp @@ -42,13 +42,13 @@ QT_BEGIN_NAMESPACE QTextStream &qerr() { - static QTextStream result(stderr, QIODevice::WriteOnly); + static QTextStream result(stderr, QTextStream::WriteOnly); return result; } QTextStream &qout() { - static QTextStream result(stdout, QIODevice::WriteOnly); + static QTextStream result(stdout, QTextStream::WriteOnly); return result; } QT_END_NAMESPACE diff --git a/src/tools/qlalr/lalr.h b/src/tools/qlalr/lalr.h index 16c957624f..5be44fea67 100644 --- a/src/tools/qlalr/lalr.h +++ b/src/tools/qlalr/lalr.h @@ -39,6 +39,7 @@ #include <algorithm> #include <functional> #include <set> +#include <list> class Rule; class State; diff --git a/src/xml/dom/qdom_p.h b/src/xml/dom/qdom_p.h index a9399d9901..8ab81aa083 100644 --- a/src/xml/dom/qdom_p.h +++ b/src/xml/dom/qdom_p.h @@ -46,6 +46,7 @@ #include <qstring.h> #include <qlist.h> #include <qxml.h> +#include <qshareddata.h> QT_BEGIN_NAMESPACE diff --git a/src/xml/sax/qxml_p.h b/src/xml/sax/qxml_p.h index 1b614dd886..4f5568f214 100644 --- a/src/xml/sax/qxml_p.h +++ b/src/xml/sax/qxml_p.h @@ -42,6 +42,7 @@ #include <qstack.h> #include <qmap.h> +#include <qhash.h> #include <qxml.h> #include <stack> |