diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-08-21 02:35:53 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-08-21 02:35:53 +0000 |
commit | 32073e28f0e425c066e65f3fc6a3101feab22598 (patch) | |
tree | 7e78a6f72b314bd555a49597c38ecabfc24a8714 /qtinterface/tqt4 | |
parent | 90cbdd552d7ab58c8534b0f3d0980d5059adc422 (diff) | |
download | tqtinterface-32073e28f0e425c066e65f3fc6a3101feab22598.tar.gz tqtinterface-32073e28f0e425c066e65f3fc6a3101feab22598.zip |
More TQt functionality in place for Qt4...
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/dependencies/tqtinterface@1166130 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtinterface/tqt4')
-rw-r--r-- | qtinterface/tqt4/Qt/q3painter.h | 3 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/q3popupmenu.h | 98 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qiodevice.h | 1 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qlist.h | 11 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qmovie.h | 177 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qpaintdevice.h | 2 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qtabbar.h | 227 | ||||
-rw-r--r-- | qtinterface/tqt4/Qt/qvariant.h | 642 |
8 files changed, 1160 insertions, 1 deletions
diff --git a/qtinterface/tqt4/Qt/q3painter.h b/qtinterface/tqt4/Qt/q3painter.h index aed5726..a48ad54 100644 --- a/qtinterface/tqt4/Qt/q3painter.h +++ b/qtinterface/tqt4/Qt/q3painter.h @@ -83,6 +83,9 @@ public: void setRasterOp( Qt::RasterOp ); +// void flush( const QRegion ®ion, CoordinateMode cm = CoordDevice ); + void flush(); + private: QRect adjustedRectangle(const QRect &r); diff --git a/qtinterface/tqt4/Qt/q3popupmenu.h b/qtinterface/tqt4/Qt/q3popupmenu.h new file mode 100644 index 0000000..2c138da --- /dev/null +++ b/qtinterface/tqt4/Qt/q3popupmenu.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt3Support module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef Q3POPUPMENU_H +#define Q3POPUPMENU_H + +#include <QtGui/qmenu.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Qt3SupportLight) + +class Q_COMPAT_EXPORT Q3PopupMenu : public QMenu +{ + Q_OBJECT +public: + inline Q3PopupMenu(QWidget *parent = 0, const char *name = 0) : QMenu(parent) + { setObjectName(QLatin1String(name)); } + + inline int exec() { return findIdForAction(QMenu::exec()); } + inline int exec(const QPoint & pos, int indexAtPoint = 0) { + return findIdForAction(QMenu::exec(pos, actions().value(indexAtPoint))); + } + + void setFrameRect(QRect) {} + QRect frameRect() const { return QRect(); } + enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel, + HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel, + PopupPanel, LineEditPanel, TabWidgetPanel, MShape }; + void setFrameShadow(DummyFrame) {} + DummyFrame frameShadow() const { return Plain; } + void setFrameShape(DummyFrame) {} + DummyFrame frameShape() const { return NoFrame; } + void setFrameStyle(int) {} + int frameStyle() const { return 0; } + int frameWidth() const { return 0; } + void setLineWidth(int) {} + int lineWidth() const { return 0; } + void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); } + int margin() const + { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy); return margin; } + void setMidLineWidth(int) {} + int midLineWidth() const { return 0; } + + void changeItem( int id, const QString &text ); // obsolete + void changeItem( const QString &text, int id ); // obsolete + void changeItem( const QPixmap &pixmap, int id ); // obsolete + void changeItem( const QIconSet &icon, const QString &text, int id ); // obsolete + +private: + Q_DISABLE_COPY(Q3PopupMenu) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QPOPUPMENU_H diff --git a/qtinterface/tqt4/Qt/qiodevice.h b/qtinterface/tqt4/Qt/qiodevice.h index 2573603..2dbc9f1 100644 --- a/qtinterface/tqt4/Qt/qiodevice.h +++ b/qtinterface/tqt4/Qt/qiodevice.h @@ -118,6 +118,7 @@ public: QByteArray read(qint64 maxlen); QByteArray readAll(); qint64 readLine(char *data, qint64 maxlen); + qint64 readLine(QString & s, qint64 maxlen); QByteArray readLine(qint64 maxlen = 0); virtual bool canReadLine() const; diff --git a/qtinterface/tqt4/Qt/qlist.h b/qtinterface/tqt4/Qt/qlist.h index fb4d3e3..39e44d9 100644 --- a/qtinterface/tqt4/Qt/qlist.h +++ b/qtinterface/tqt4/Qt/qlist.h @@ -261,6 +261,7 @@ public: inline const_iterator end() const { return reinterpret_cast<Node *>(p.end()); } inline const_iterator constEnd() const { return reinterpret_cast<Node *>(p.end()); } iterator insert(iterator before, const T &t); + void insert(iterator pos, int n, const T &x); iterator erase(iterator pos); iterator erase(iterator first, iterator last); @@ -441,6 +442,16 @@ inline typename QList<T>::iterator QList<T>::insert(iterator before, const T &t) } return n; } + +template <typename T> +inline void QList<T>::insert(iterator pos, int n, const T &x) +{ + int q; + for (q=0;q<n;q++) { + this.insert(pos, x); + } +} + template <typename T> inline typename QList<T>::iterator QList<T>::erase(iterator it) { node_destruct(it.i); diff --git a/qtinterface/tqt4/Qt/qmovie.h b/qtinterface/tqt4/Qt/qmovie.h new file mode 100644 index 0000000..e6a4297 --- /dev/null +++ b/qtinterface/tqt4/Qt/qmovie.h @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMOVIE_H +#define QMOVIE_H + +#include <QtCore/qobject.h> + +#ifndef QT_NO_MOVIE + +#include <QtCore/qbytearray.h> +#include <QtCore/qlist.h> +#include <QtCore/qobject.h> +#include <QtGui/qimagereader.h> + +#ifdef QT3_SUPPORT +#include <QtGui/qimage.h> +#include <QtGui/qpixmap.h> +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QByteArray; +class QColor; +class QIODevice; +class QImage; +class QPixmap; +class QRect; +class QSize; + +class QMoviePrivate; +class Q_GUI_EXPORT QMovie : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QMovie) + Q_ENUMS(MovieState CacheMode) + Q_PROPERTY(int speed READ speed WRITE setSpeed) + Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode) +public: + enum MovieState { + NotRunning, + Paused, + Running + }; + enum CacheMode { + CacheNone, + CacheAll + }; + + QMovie(QObject *parent = 0); + explicit QMovie(QIODevice *device, const QByteArray &format = QByteArray(), QObject *parent = 0); + explicit QMovie(const QString &fileName, const QByteArray &format = QByteArray(), QObject *parent = 0); + ~QMovie(); + + static QList<QByteArray> supportedFormats(); + + void setDevice(QIODevice *device); + QIODevice *device() const; + + void setFileName(const QString &fileName); + QString fileName() const; + + void setFormat(const QByteArray &format); + QByteArray format() const; + + void setBackgroundColor(const QColor &color); + QColor backgroundColor() const; + + MovieState state() const; + + QRect frameRect() const; + QImage currentImage() const; + QPixmap currentPixmap() const; + + bool isValid() const; + + bool jumpToFrame(int frameNumber); + int loopCount() const; + int frameCount() const; + int nextFrameDelay() const; + int currentFrameNumber() const; + + int speed() const; + + QSize scaledSize(); + void setScaledSize(const QSize &size); + + CacheMode cacheMode() const; + void setCacheMode(CacheMode mode); + + CacheMode cacheMode(); // ### Qt 5: remove me + +Q_SIGNALS: + void started(); + void resized(const QSize &size); + void updated(const QRect &rect); + void stateChanged(QMovie::MovieState state); + void error(QImageReader::ImageReaderError error); + void finished(); + void frameChanged(int frameNumber); + +public Q_SLOTS: + void start(); + bool jumpToNextFrame(); + void setPaused(bool paused); + void stop(); + void setSpeed(int percentSpeed); + +private: + Q_DISABLE_COPY(QMovie) + Q_PRIVATE_SLOT(d_func(), void _q_loadNextFrame()) + +#ifdef QT3_SUPPORT +public: + inline QT3_SUPPORT bool isNull() const { return isValid(); } + inline QT3_SUPPORT int frameNumber() const { return currentFrameNumber(); } + inline QT3_SUPPORT bool running() const { return state() == Running; } + inline QT3_SUPPORT bool paused() const { return state() == Paused; } + inline QT3_SUPPORT bool finished() const { return state() == NotRunning; } + inline QT3_SUPPORT void restart() { stop(); start(); } + inline QT3_SUPPORT QImage frameImage() const { return currentImage(); } + inline QT3_SUPPORT QPixmap framePixmap() const { return currentPixmap(); } + inline QT3_SUPPORT void step() { jumpToNextFrame(); } + inline QT3_SUPPORT void pause() { setPaused(true); } + inline QT3_SUPPORT void unpause() { setPaused(false); } +#endif +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QT_NO_MOVIE + +#endif // QMOVIE_H diff --git a/qtinterface/tqt4/Qt/qpaintdevice.h b/qtinterface/tqt4/Qt/qpaintdevice.h index 41a58c6..98157db 100644 --- a/qtinterface/tqt4/Qt/qpaintdevice.h +++ b/qtinterface/tqt4/Qt/qpaintdevice.h @@ -95,7 +95,7 @@ public: #elif defined(Q_WS_X11) virtual Qt::HANDLE handle() const; virtual Qt::HANDLE x11RenderHandle() const; - GC qt_xget_temp_gc( int scrn, bool monochrome ); + static GC qt_xget_temp_gc( int scrn, bool monochrome ); #elif defined(Q_WS_MAC) virtual Qt::HANDLE handle() const; #elif defined(Q_WS_QWS) diff --git a/qtinterface/tqt4/Qt/qtabbar.h b/qtinterface/tqt4/Qt/qtabbar.h new file mode 100644 index 0000000..c05497f --- /dev/null +++ b/qtinterface/tqt4/Qt/qtabbar.h @@ -0,0 +1,227 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTABBAR_H +#define QTABBAR_H + +#include <QtGui/qwidget.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#ifndef QT_NO_TABBAR + +class QIcon; +class QTabBarPrivate; +class QStyleOptionTab; + +class Q_GUI_EXPORT QTabBar: public QWidget +{ + Q_OBJECT + + Q_ENUMS(Shape) + Q_PROPERTY(Shape shape READ shape WRITE setShape) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged) + Q_PROPERTY(int count READ count) + Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase) + Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) + Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode) + Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons) + Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable) + Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove WRITE setSelectionBehaviorOnRemove) + Q_PROPERTY(bool expanding READ expanding WRITE setExpanding) + Q_PROPERTY(bool movable READ isMovable WRITE setMovable) + Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode) + +public: + explicit QTabBar(QWidget* parent=0); + ~QTabBar(); + + enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, + TriangularNorth, TriangularSouth, TriangularWest, TriangularEast +#if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN) + , RoundedAbove = RoundedNorth, RoundedBelow = RoundedSouth, + TriangularAbove = TriangularNorth, TriangularBelow = TriangularSouth +#endif + }; + + enum ButtonPosition { + LeftSide, + RightSide + }; + + enum SelectionBehavior { + SelectLeftTab, + SelectRightTab, + SelectPreviousTab + }; + + Shape shape() const; + void setShape(Shape shape); + + int addTab(const QString &text); + int addTab(const QIcon &icon, const QString &text); + + int insertTab(int index, const QString &text); + int insertTab(int index, const QIcon&icon, const QString &text); + + void removeTab(int index); + void moveTab(int from, int to); + + bool isTabEnabled(int index) const; + void setTabEnabled(int index, bool); + + QString tabText(int index) const; + void setTabText(int index, const QString &text); + + QColor tabTextColor(int index) const; + void setTabTextColor(int index, const QColor &color); + + QIcon tabIcon(int index) const; + void setTabIcon(int index, const QIcon &icon); + + Qt::TextElideMode elideMode() const; + void setElideMode(Qt::TextElideMode); + +#ifndef QT_NO_TOOLTIP + void setTabToolTip(int index, const QString &tip); + QString tabToolTip(int index) const; +#endif + +#ifndef QT_NO_WHATSTHIS + void setTabWhatsThis(int index, const QString &text); + QString tabWhatsThis(int index) const; +#endif + + void setTabData(int index, const QVariant &data); + QVariant tabData(int index) const; + + QRect tabRect(int index) const; + int tabAt(const QPoint &pos) const; + int tabAt(const int &pos) const; + + int currentIndex() const; + int count() const; + + QSize sizeHint() const; + QSize minimumSizeHint() const; + + void setDrawBase(bool drawTheBase); + bool drawBase() const; + + QSize iconSize() const; + void setIconSize(const QSize &size); + + bool usesScrollButtons() const; + void setUsesScrollButtons(bool useButtons); + + bool tabsClosable() const; + void setTabsClosable(bool closable); + + void setTabButton(int index, ButtonPosition position, QWidget *widget); + QWidget *tabButton(int index, ButtonPosition position) const; + + SelectionBehavior selectionBehaviorOnRemove() const; + void setSelectionBehaviorOnRemove(SelectionBehavior behavior); + + bool expanding() const; + void setExpanding(bool enabled); + + bool isMovable() const; + void setMovable(bool movable); + + bool documentMode() const; + void setDocumentMode(bool set); + +public Q_SLOTS: + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentChanged(int index); + void tabCloseRequested(int index); + void tabMoved(int from, int to); + +protected: + virtual QSize tabSizeHint(int index) const; + virtual void tabInserted(int index); + virtual void tabRemoved(int index); + virtual void tabLayoutChange(); + + bool event(QEvent *); + void resizeEvent(QResizeEvent *); + void showEvent(QShowEvent *); + void hideEvent(QHideEvent *); + void paintEvent(QPaintEvent *); + void mousePressEvent (QMouseEvent *); + void mouseMoveEvent (QMouseEvent *); + void mouseReleaseEvent (QMouseEvent *); +#ifndef QT_NO_WHEELEVENT + void wheelEvent(QWheelEvent *event); +#endif + void keyPressEvent(QKeyEvent *); + void changeEvent(QEvent *); + void initStyleOption(QStyleOptionTab *option, int tabIndex) const; + +#ifdef QT3_SUPPORT +public Q_SLOTS: + QT_MOC_COMPAT void setCurrentTab(int index) { setCurrentIndex(index); } +Q_SIGNALS: + QT_MOC_COMPAT void selected(int); +#endif + + friend class QAccessibleTabBar; +private: + Q_DISABLE_COPY(QTabBar) + Q_DECLARE_PRIVATE(QTabBar) + Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs()) + Q_PRIVATE_SLOT(d_func(), void _q_closeTab()) +}; + +#endif // QT_NO_TABBAR + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTABBAR_H diff --git a/qtinterface/tqt4/Qt/qvariant.h b/qtinterface/tqt4/Qt/qvariant.h new file mode 100644 index 0000000..2d7dfd4 --- /dev/null +++ b/qtinterface/tqt4/Qt/qvariant.h @@ -0,0 +1,642 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVARIANT_H +#define QVARIANT_H + +#include <QtCore/qatomic.h> +#include <QtCore/qbytearray.h> +#include <QtCore/qlist.h> +#include <QtCore/qmetatype.h> +#include <QtCore/qmap.h> +#include <QtCore/qhash.h> +#include <QtCore/qstring.h> + +#ifndef QICON_H +typedef QIcon QIconSet; +#endif // QICON_H + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class Q3PointArray; +class QBitArray; +class QDataStream; +class QDate; +class QDateTime; +class QLine; +class QLineF; +class QLocale; +class QMatrix; +class QTransform; +class QStringList; +class QTime; +class QPoint; +class QPointF; +class QSize; +class QSizeF; +class QRect; +class QRectF; +#ifndef QT_NO_REGEXP +class QRegExp; +#endif +class QTextFormat; +class QTextLength; +class QUrl; +class QVariant; +class QVariantComparisonHelper; + +#ifndef QT_NO_MEMBER_TEMPLATES +template <typename T> +inline QVariant qVariantFromValue(const T &); + +template <typename T> +inline void qVariantSetValue(QVariant &, const T &); + +template<typename T> +inline T qVariantValue(const QVariant &); + +template<typename T> +inline bool qVariantCanConvert(const QVariant &); +#endif + +class Q_CORE_EXPORT QVariant +{ + public: + enum Type { + Invalid = 0, + + Bool = 1, + Int = 2, + UInt = 3, + LongLong = 4, + ULongLong = 5, + Double = 6, + Char = 7, + Map = 8, + List = 9, + String = 10, + StringList = 11, + ByteArray = 12, + BitArray = 13, + Date = 14, + Time = 15, + DateTime = 16, + Url = 17, + Locale = 18, + Rect = 19, + RectF = 20, + Size = 21, + SizeF = 22, + Line = 23, + LineF = 24, + Point = 25, + PointF = 26, + RegExp = 27, + Hash = 28, + LastCoreType = Hash, + + // value 62 is internally reserved +#ifdef QT3_SUPPORT + ColorGroup = 63, +#endif + Font = 64, + Pixmap = 65, + Brush = 66, + Color = 67, + Palette = 68, + Icon = 69, + Image = 70, + Polygon = 71, + Region = 72, + Bitmap = 73, + Cursor = 74, + SizePolicy = 75, + KeySequence = 76, + Pen = 77, + TextLength = 78, + TextFormat = 79, + Matrix = 80, + Transform = 81, + Matrix4x4 = 82, + Vector2D = 83, + Vector3D = 84, + Vector4D = 85, + Quaternion = 86, + LastGuiType = Quaternion, + + UserType = 127, +#ifdef QT3_SUPPORT + IconSet = Icon, + CString = ByteArray, + PointArray = Polygon, +#endif + LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type + }; + + inline QVariant(); + ~QVariant(); + QVariant(Type type); + QVariant(int typeOrUserType, const void *copy); + QVariant(int typeOrUserType, const void *copy, uint flags); + QVariant(const QVariant &other); + +#ifndef QT_NO_DATASTREAM + QVariant(QDataStream &s); +#endif + + QVariant(int i); + QVariant(uint ui); + QVariant(qlonglong ll); + QVariant(qulonglong ull); + QVariant(bool b); + QVariant(double d); + QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; } +#ifndef QT_NO_CAST_FROM_ASCII + QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str); +#endif + + QVariant(const QByteArray &bytearray); + QVariant(const QBitArray &bitarray); + QVariant(const QString &string); + QVariant(const QLatin1String &string); + QVariant(const QStringList &stringlist); + QVariant(const QChar &qchar); + QVariant(const QDate &date); + QVariant(const QTime &time); + QVariant(const QDateTime &datetime); + QVariant(const QList<QVariant> &list); + QVariant(const QMap<QString,QVariant> &map); + QVariant(const QHash<QString,QVariant> &hash); +#ifndef QT_NO_GEOM_VARIANT + QVariant(const QSize &size); + QVariant(const QSizeF &size); + QVariant(const QPoint &pt); + QVariant(const QPointF &pt); + QVariant(const QLine &line); + QVariant(const QLineF &line); + QVariant(const QRect &rect); + QVariant(const QRectF &rect); +#endif + QVariant(const QUrl &url); + QVariant(const QLocale &locale); +#ifndef QT_NO_REGEXP + QVariant(const QRegExp ®Exp); +#endif + QVariant(Qt::GlobalColor color); + + QVariant(const QBitmap &bitmap); + QVariant(const Q3PointArray &pa); + QVariant(const QPixmap &pixmap); + + QVariant& operator=(const QVariant &other); + + Type type() const; + int userType() const; + const char *typeName() const; + + bool canConvert(Type t) const; + bool convert(Type t); + +#ifdef QT3_SUPPORT + inline QT3_SUPPORT bool canCast(Type t) const + { return canConvert(t); } + inline QT3_SUPPORT bool cast(Type t) + { return convert(t); } +#endif + + inline bool isValid() const; + bool isNull() const; + + void clear(); + + void detach(); + inline bool isDetached() const; + + int toInt(bool *ok = 0) const; + uint toUInt(bool *ok = 0) const; + qlonglong toLongLong(bool *ok = 0) const; + qulonglong toULongLong(bool *ok = 0) const; + bool toBool() const; + double toDouble(bool *ok = 0) const; + float toFloat(bool *ok = 0) const; + qreal toReal(bool *ok = 0) const; + QByteArray toByteArray() const; + QBitArray toBitArray() const; + QString toString() const; + QStringList toStringList() const; + QChar toChar() const; + QDate toDate() const; + QTime toTime() const; + QDateTime toDateTime() const; + QList<QVariant> toList() const; + QMap<QString, QVariant> toMap() const; + QHash<QString, QVariant> toHash() const; + +#ifndef QT_NO_GEOM_VARIANT + QPoint toPoint() const; + QPointF toPointF() const; + QRect toRect() const; + QSize toSize() const; + QSizeF toSizeF() const; + QLine toLine() const; + QLineF toLineF() const; + QRectF toRectF() const; +#endif + QUrl toUrl() const; + QLocale toLocale() const; +#ifndef QT_NO_REGEXP + QRegExp toRegExp() const; +#endif + +#ifdef QT3_SUPPORT + inline QT3_SUPPORT int &asInt(); + inline QT3_SUPPORT uint &asUInt(); + inline QT3_SUPPORT qlonglong &asLongLong(); + inline QT3_SUPPORT qulonglong &asULongLong(); + inline QT3_SUPPORT bool &asBool(); + inline QT3_SUPPORT double &asDouble(); + inline QT3_SUPPORT QByteArray &asByteArray(); + inline QT3_SUPPORT QBitArray &asBitArray(); + inline QT3_SUPPORT QString &asString(); + inline QT3_SUPPORT QStringList &asStringList(); + inline QT3_SUPPORT QDate &asDate(); + inline QT3_SUPPORT QTime &asTime(); + inline QT3_SUPPORT QDateTime &asDateTime(); + inline QT3_SUPPORT QList<QVariant> &asList(); + inline QT3_SUPPORT QMap<QString,QVariant> &asMap(); + inline QT3_SUPPORT QPoint &asPoint(); + inline QT3_SUPPORT QRect &asRect(); + inline QT3_SUPPORT QSize &asSize(); +#endif //QT3_SUPPORT + + QFont toFont() const; + QColor toColor() const; + QCursor toCursor() const; + QBitmap toBitmap() const; + Q3PointArray toPointArray() const; + QRegion toRegion() const; + QPixmap toPixmap() const; + QImage toImage() const; + QBrush toBrush() const; + QPalette toPalette() const; + QColorGroup toColorGroup() const; + QIconSet toIconSet() const; + + QFont asFont(); + QColor asColor(); + +#ifndef QT_NO_DATASTREAM + void load(QDataStream &ds); + void save(QDataStream &ds) const; +#endif + static const char *typeToName(Type type); + static Type nameToType(const char *name); + +#ifdef QT3_SUPPORT + inline QT3_SUPPORT_CONSTRUCTOR QVariant(bool val, int) { create(Bool, &val); } + inline QT3_SUPPORT const QByteArray toCString() const { return toByteArray(); } + inline QT3_SUPPORT QByteArray &asCString() { return *reinterpret_cast<QByteArray *>(castOrDetach(ByteArray)); } +#endif + + void *data(); + const void *constData() const; + inline const void *data() const { return constData(); } + +#ifndef QT_NO_MEMBER_TEMPLATES + template<typename T> + inline void setValue(const T &value); + + template<typename T> + inline T value() const + { return qVariantValue<T>(*this); } + + template<typename T> + static inline QVariant fromValue(const T &value) + { return qVariantFromValue(value); } + + template<typename T> + bool canConvert() const + { return qVariantCanConvert<T>(*this); } +#endif + + public: +#ifndef qdoc + struct PrivateShared + { + inline PrivateShared(void *v) : ptr(v), ref(1) { } + void *ptr; + QAtomicInt ref; + }; + struct Private + { + inline Private(): type(Invalid), is_shared(false), is_null(true) { data.ptr = 0; } + inline Private(const Private &other) + : data(other.data), type(other.type), + is_shared(other.is_shared), is_null(other.is_null) + {} + union Data + { + char c; + int i; + uint u; + bool b; + double d; + float f; + qreal real; + qlonglong ll; + qulonglong ull; + QObject *o; + void *ptr; + PrivateShared *shared; + } data; + uint type : 30; + uint is_shared : 1; + uint is_null : 1; + }; + public: + typedef void (*f_construct)(Private *, const void *); + typedef void (*f_clear)(Private *); + typedef bool (*f_null)(const Private *); +#ifndef QT_NO_DATASTREAM + typedef void (*f_load)(Private *, QDataStream &); + typedef void (*f_save)(const Private *, QDataStream &); +#endif + typedef bool (*f_compare)(const Private *, const Private *); + typedef bool (*f_convert)(const QVariant::Private *d, Type t, void *, bool *); + typedef bool (*f_canConvert)(const QVariant::Private *d, Type t); + typedef void (*f_debugStream)(QDebug, const QVariant &); + struct Handler { + f_construct construct; + f_clear clear; + f_null isNull; +#ifndef QT_NO_DATASTREAM + f_load load; + f_save save; +#endif + f_compare compare; + f_convert convert; + f_canConvert canConvert; + f_debugStream debugStream; + }; +#endif + + inline bool operator==(const QVariant &v) const + { return cmp(v); } + inline bool operator!=(const QVariant &v) const + { return !cmp(v); } + +protected: + friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *); + friend int qRegisterGuiVariant(); + friend int qUnregisterGuiVariant(); + friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); +#ifndef QT_NO_DEBUG_STREAM + friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); +#endif + Private d; + + static const Handler *handler; + + void create(int type, const void *copy); +#ifdef QT3_SUPPORT + void *castOrDetach(Type t); +#endif + bool cmp(const QVariant &other) const; + +private: + // force compile error, prevent QVariant(bool) to be called + inline QVariant(void *) { Q_ASSERT(false); } +#ifdef QT_NO_CAST_FROM_ASCII + // force compile error when implicit conversion is not wanted + inline QVariant(const char *) { Q_ASSERT(false); } +#endif +#ifndef QT3_SUPPORT + // force compile error, prevent QVariant(QVariant::Type, int) to be called + inline QVariant(bool, int) { Q_ASSERT(false); } +#endif +public: + typedef Private DataPtr; + inline DataPtr &data_ptr() { return d; } +}; + +typedef QList<QVariant> QVariantList; +typedef QMap<QString, QVariant> QVariantMap; +typedef QHash<QString, QVariant> QVariantHash; + +inline bool qvariant_cast_helper(const QVariant &v, QVariant::Type tp, void *ptr) +{ return QVariant::handler->convert(&v.d, tp, ptr, 0); } + +template <typename T> +inline QVariant qVariantFromValue(const T &t) +{ + return QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t, QTypeInfo<T>::isPointer); +} + +template <> +inline QVariant qVariantFromValue(const QVariant &t) { return t; } + +template <typename T> +inline void qVariantSetValue(QVariant &v, const T &t) +{ + //if possible we reuse the current QVariant private + const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); + QVariant::Private &d = v.data_ptr(); + if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { + d.type = type; + d.is_null = false; + T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); + if (QTypeInfo<T>::isComplex) + old->~T(); + new (old) T(t); //call the copy constructor + } else { + v = QVariant(type, &t, QTypeInfo<T>::isPointer); + } +} + +template <> +inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) +{ + v = t; +} + + +inline QVariant::QVariant() {} +inline bool QVariant::isValid() const { return d.type != Invalid; } + +#ifdef QT3_SUPPORT +inline int &QVariant::asInt() +{ return *reinterpret_cast<int *>(castOrDetach(Int)); } +inline uint &QVariant::asUInt() +{ return *reinterpret_cast<uint *>(castOrDetach(UInt)); } +inline qlonglong &QVariant::asLongLong() +{ return *reinterpret_cast<qlonglong *>(castOrDetach(LongLong)); } +inline qulonglong &QVariant::asULongLong() +{ return *reinterpret_cast<qulonglong *>(castOrDetach(ULongLong)); } +inline bool &QVariant::asBool() +{ return *reinterpret_cast<bool *>(castOrDetach(Bool)); } +inline double &QVariant::asDouble() +{ return *reinterpret_cast<double *>(castOrDetach(Double)); } +inline QByteArray& QVariant::asByteArray() +{ return *reinterpret_cast<QByteArray *>(castOrDetach(ByteArray)); } +inline QBitArray& QVariant::asBitArray() +{ return *reinterpret_cast<QBitArray *>(castOrDetach(BitArray)); } +inline QString& QVariant::asString() +{ return *reinterpret_cast<QString *>(castOrDetach(String)); } +inline QStringList& QVariant::asStringList() +{ return *reinterpret_cast<QStringList *>(castOrDetach(StringList)); } +inline QDate& QVariant::asDate() +{ return *reinterpret_cast<QDate *>(castOrDetach(Date)); } +inline QTime& QVariant::asTime() +{ return *reinterpret_cast<QTime *>(castOrDetach(Time)); } +inline QDateTime& QVariant::asDateTime() +{ return *reinterpret_cast<QDateTime *>(castOrDetach(DateTime)); } +inline QList<QVariant>& QVariant::asList() +{ return *reinterpret_cast<QList<QVariant> *>(castOrDetach(List)); } +inline QMap<QString, QVariant>& QVariant::asMap() +{ return *reinterpret_cast<QMap<QString, QVariant> *>(castOrDetach(Map)); } +inline QPoint &QVariant::asPoint() +{ return *reinterpret_cast<QPoint *>(castOrDetach(Point)); } +inline QRect &QVariant::asRect() +{ return *reinterpret_cast<QRect *>(castOrDetach(Rect)); } +inline QSize &QVariant::asSize() +{ return *reinterpret_cast<QSize *>(castOrDetach(Size)); } +#endif //QT3_SUPPORT + +#ifndef QT_NO_MEMBER_TEMPLATES +template<typename T> +inline void QVariant::setValue(const T &avalue) +{ qVariantSetValue(*this, avalue); } +#endif + +#ifndef QT_NO_DATASTREAM +Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p); +Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant& p); +Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant::Type& p); +Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p); +#endif + +inline bool QVariant::isDetached() const +{ return !d.is_shared || d.data.shared->ref == 1; } + + +#ifdef qdoc + inline bool operator==(const QVariant &v1, const QVariant &v2); + inline bool operator!=(const QVariant &v1, const QVariant &v2); +#else + +/* Helper class to add one more level of indirection to prevent + implicit casts. +*/ +class QVariantComparisonHelper +{ +public: + inline QVariantComparisonHelper(const QVariant &var) + : v(&var) {} +private: + friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); + const QVariant *v; +}; + +inline bool operator==(const QVariant &v1, const QVariantComparisonHelper &v2) +{ + return v1.cmp(*v2.v); +} + +inline bool operator!=(const QVariant &v1, const QVariantComparisonHelper &v2) +{ + return !operator==(v1, v2); +} +#endif + +#ifndef QT_MOC +template<typename T> inline T qvariant_cast(const QVariant &v) +{ + const int vid = qMetaTypeId<T>(static_cast<T *>(0)); + if (vid == v.userType()) + return *reinterpret_cast<const T *>(v.constData()); + if (vid < int(QMetaType::User)) { + T t; + if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) + return t; + } + return T(); +} + +template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v) +{ + static const int vid = qRegisterMetaType<QVariant>("QVariant"); + if (vid == v.userType()) + return *reinterpret_cast<const QVariant *>(v.constData()); + return v; +} + +template<typename T> +inline T qVariantValue(const QVariant &variant) +{ return qvariant_cast<T>(variant); } + +template<typename T> +inline bool qVariantCanConvert(const QVariant &variant) +{ + return variant.canConvert(static_cast<QVariant::Type>( + qMetaTypeId<T>(static_cast<T *>(0)))); +} +#endif +Q_DECLARE_SHARED(QVariant) +Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE); + +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); +Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant::Type); +#endif + +QT_END_NAMESPACE + +Q_DECLARE_BUILTIN_METATYPE(QVariantList, QVariantList) +Q_DECLARE_BUILTIN_METATYPE(QVariantMap, QVariantMap) +Q_DECLARE_BUILTIN_METATYPE(QVariantHash, QVariantHash) + +QT_END_HEADER + +#endif // QVARIANT_H |