From 9c68bdf3ed66564bce3064a49ca80b7889c35952 Mon Sep 17 00:00:00 2001 From: Lasse Holmstedt Date: Wed, 14 Jul 2010 11:31:11 +0200 Subject: Added symbian defs for e55781212532e2abcdd1cef8548b146fb14f0713 Reviewed-by: Jason McDonald Submitted-by: Alessandro Portale --- src/s60installs/bwins/QtDeclarativeu.def | 1 + src/s60installs/eabi/QtDeclarativeu.def | 1 + 2 files changed, 2 insertions(+) diff --git a/src/s60installs/bwins/QtDeclarativeu.def b/src/s60installs/bwins/QtDeclarativeu.def index e96f83f..8fdd72c 100644 --- a/src/s60installs/bwins/QtDeclarativeu.def +++ b/src/s60installs/bwins/QtDeclarativeu.def @@ -1675,4 +1675,5 @@ EXPORTS ?setBindingForObject@QDeclarativeEngineDebug@@QAE_NHABVQString@@ABVQVariant@@_N@Z @ 1674 NONAME ; bool QDeclarativeEngineDebug::setBindingForObject(int, class QString const &, class QVariant const &, bool) ??0QDeclarativeImageProvider@@QAE@W4ImageType@0@@Z @ 1675 NONAME ; QDeclarativeImageProvider::QDeclarativeImageProvider(enum QDeclarativeImageProvider::ImageType) ?setMethodBody@QDeclarativeEngineDebug@@QAE_NHABVQString@@0@Z @ 1676 NONAME ; bool QDeclarativeEngineDebug::setMethodBody(int, class QString const &, class QString const &) + ?resetBindingForObject@QDeclarativeEngineDebug@@QAE_NHABVQString@@@Z @ 1677 NONAME ; bool QDeclarativeEngineDebug::resetBindingForObject(int, class QString const &) diff --git a/src/s60installs/eabi/QtDeclarativeu.def b/src/s60installs/eabi/QtDeclarativeu.def index 083e07f..dd5103f 100644 --- a/src/s60installs/eabi/QtDeclarativeu.def +++ b/src/s60installs/eabi/QtDeclarativeu.def @@ -1706,4 +1706,5 @@ EXPORTS _ZN25QDeclarativeImageProviderC1ENS_9ImageTypeE @ 1705 NONAME _ZN25QDeclarativeImageProviderC2ENS_9ImageTypeE @ 1706 NONAME _ZNK25QDeclarativeImageProvider9imageTypeEv @ 1707 NONAME + _ZN23QDeclarativeEngineDebug21resetBindingForObjectEiRK7QString @ 1708 NONAME -- cgit v0.12 From ea6a5146397b668bf535ee7249bd4262d6185234 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 14 Jul 2010 12:02:08 +0200 Subject: Work around memory leak issue in grid and linear layouts. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These classes create a new QWidget and assign it to a static pointer which is never cleaned up. Using Q_GLOBAL_STATIC ensures that they are deleted on library unload. This is really just a cosmetic change that removes a leak warning - the real fix should be to find a way to not use a new QWidget like this. It seems odd that QGraphicsLayouts, which don't use QWidget in any other way, should depend on QWidget like this. Task-number: QTBUG-10768 Merge-request: 741 Reviewed-by: Jan-Arve Sæther --- src/gui/graphicsview/qgraphicsgridlayout.cpp | 7 +++---- src/gui/graphicsview/qgraphicslinearlayout.cpp | 7 +++---- tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 7 +++++++ tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsgridlayout.cpp b/src/gui/graphicsview/qgraphicsgridlayout.cpp index 83db3ec..062b5ac 100644 --- a/src/gui/graphicsview/qgraphicsgridlayout.cpp +++ b/src/gui/graphicsview/qgraphicsgridlayout.cpp @@ -94,14 +94,13 @@ public: #endif }; +Q_GLOBAL_STATIC(QWidget, globalStyleInfoWidget); + QLayoutStyleInfo QGraphicsGridLayoutPrivate::styleInfo() const { - static QWidget *wid = 0; - if (!wid) - wid = new QWidget; QGraphicsItem *item = parentItem(); QStyle *style = (item && item->isWidget()) ? static_cast(item)->style() : QApplication::style(); - return QLayoutStyleInfo(style, wid); + return QLayoutStyleInfo(style, globalStyleInfoWidget()); } /*! diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp index b828722..37408ef 100644 --- a/src/gui/graphicsview/qgraphicslinearlayout.cpp +++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp @@ -171,14 +171,13 @@ int QGraphicsLinearLayoutPrivate::gridColumn(int index) const return int(qMin(uint(index), uint(engine.columnCount()))); } +Q_GLOBAL_STATIC(QWidget, globalStyleInfoWidget) + QLayoutStyleInfo QGraphicsLinearLayoutPrivate::styleInfo() const { - static QWidget *wid = 0; - if (!wid) - wid = new QWidget; QGraphicsItem *item = parentItem(); QStyle *style = (item && item->isWidget()) ? static_cast(item)->style() : QApplication::style(); - return QLayoutStyleInfo(style, wid); + return QLayoutStyleInfo(style, globalStyleInfoWidget()); } /*! diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index b9a5c66..d1d6860 100644 --- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -105,6 +105,7 @@ private slots: void geometries_data(); void geometries(); void avoidRecursionInInsertItem(); + void styleInfoLeak(); void task236367_maxSizeHint(); }; @@ -2196,6 +2197,12 @@ void tst_QGraphicsGridLayout::avoidRecursionInInsertItem() QCOMPARE(layout->count(), 0); } +void tst_QGraphicsGridLayout::styleInfoLeak() +{ + QGraphicsGridLayout grid; + grid.horizontalSpacing(); +} + void tst_QGraphicsGridLayout::task236367_maxSizeHint() { QGraphicsWidget *widget = new QGraphicsWidget; diff --git a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index c26e5d4..6107fa1 100644 --- a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -102,6 +102,7 @@ private slots: void layoutDirection(); void removeLayout(); void avoidRecursionInInsertItem(); + void styleInfoLeak(); // Task specific tests void task218400_insertStretchCrash(); @@ -1443,6 +1444,12 @@ void tst_QGraphicsLinearLayout::avoidRecursionInInsertItem() QCOMPARE(layout->count(), 0); } +void tst_QGraphicsLinearLayout::styleInfoLeak() +{ + QGraphicsLinearLayout layout; + layout.spacing(); +} + void tst_QGraphicsLinearLayout::task218400_insertStretchCrash() { QGraphicsScene *scene = new QGraphicsScene; -- cgit v0.12 From 21fbfdb2acdc368c047d14004373d2d0baa6c0b1 Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Wed, 14 Jul 2010 16:33:49 +0200 Subject: Docs: HTML comments marks so Creator can extract data efficiently. Reviewed-by: Martin Smith --- tools/qdoc3/htmlgenerator.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++- tools/qdoc3/htmlgenerator.h | 7 ++++++ tools/qdoc3/node.cpp | 18 ++++++++++++++++ tools/qdoc3/node.h | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 89b1e98..16c5eb2 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -1382,12 +1382,14 @@ void HtmlGenerator::generateClassLikeNode(const InnerNode *inner, out() << "
\n"; if (!inner->doc().isEmpty()) { + generateExtractionMark(inner, DetailedDescriptionMark); //out() << "
\n" out() << "
\n" // QTBUG-9504 << "

" << "Detailed Description" << "

\n"; generateBody(inner, marker); out() << "
\n"; // QTBUG-9504 generateAlsoList(inner, marker); + generateExtractionMark(inner, EndMark); } sections = marker->sections(inner, CodeMarker::Detailed, CodeMarker::Okay); @@ -1593,12 +1595,14 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker) ++s; } + generateExtractionMark(fake, DetailedDescriptionMark); out() << "
\n"; out() << "

" << "Detailed Description" << "

\n"; generateBody(fake, marker); if (cn) generateQmlText(cn->doc().body(), cn, marker, fake->name()); generateAlsoList(fake, marker); + generateExtractionMark(fake, EndMark); //out() << "
\n"; sections = marker->qmlSections(qml_cn,CodeMarker::Detailed); @@ -1631,16 +1635,20 @@ void HtmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker) Text brief = fake->doc().briefText(); if (fake->subType() == Node::Module && !brief.isEmpty()) { + generateExtractionMark(fake, DetailedDescriptionMark); out() << "
\n"; out() << "
\n"; // QTBUG-9504 out() << "

" << "Detailed Description" << "

\n"; } - else + else { + generateExtractionMark(fake, DetailedDescriptionMark); out() << "
\n"; // QTBUG-9504 + } generateBody(fake, marker); out() << "
\n"; // QTBUG-9504 generateAlsoList(fake, marker); + generateExtractionMark(fake, EndMark); if (!fake->groupMembers().isEmpty()) { NodeMap groupMembersMap; @@ -1913,6 +1921,7 @@ void HtmlGenerator::generateBrief(const Node *node, CodeMarker *marker, { Text brief = node->doc().briefText(); if (!brief.isEmpty()) { + generateExtractionMark(node, BriefMark); out() << "

"; generateText(brief, node, marker); if (!relative || node == relative) @@ -1920,6 +1929,7 @@ void HtmlGenerator::generateBrief(const Node *node, CodeMarker *marker, else out() << " More...

\n"; + generateExtractionMark(node, EndMark); } } @@ -3504,6 +3514,7 @@ void HtmlGenerator::generateDetailedMember(const Node *node, #ifdef GENERATE_MAC_REFS generateMacRef(node, marker); #endif + generateExtractionMark(node, MemberMark); if (node->type() == Node::Enum && (enume = static_cast(node))->flagsType()) { #ifdef GENERATE_MAC_REFS @@ -3566,6 +3577,7 @@ void HtmlGenerator::generateDetailedMember(const Node *node, } } generateAlsoList(node, marker); + generateExtractionMark(node, EndMark); } void HtmlGenerator::findAllClasses(const InnerNode *node) @@ -4148,6 +4160,7 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, #ifdef GENERATE_MAC_REFS generateMacRef(node, marker); #endif + generateExtractionMark(node, MemberMark); out() << "
"; if (node->subType() == Node::QmlPropertyGroup) { const QmlPropGroupNode* qpgn = static_cast(node); @@ -4219,6 +4232,7 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, generateAlsoList(node, marker); out() << "
"; out() << "
"; + generateExtractionMark(node, EndMark); } /*! @@ -4457,6 +4471,40 @@ void HtmlGenerator::generatePageIndex(const QString& fileName, CodeMarker* marke file.close(); } +void HtmlGenerator::generateExtractionMark(const Node *node, ExtractionMarkType markType) +{ + if (markType != EndMark) { + out() << "\n"; + } else { + out() << "\n"; + } +} + #endif #if 0 // fossil removed for new doc format MWS 19/04/2010 diff --git a/tools/qdoc3/htmlgenerator.h b/tools/qdoc3/htmlgenerator.h index 80341de..c8ede63 100644 --- a/tools/qdoc3/htmlgenerator.h +++ b/tools/qdoc3/htmlgenerator.h @@ -123,6 +123,12 @@ class HtmlGenerator : public PageGenerator private: enum SubTitleSize { SmallSubTitle, LargeSubTitle }; + enum ExtractionMarkType { + BriefMark, + DetailedDescriptionMark, + MemberMark, + EndMark + }; const QPair anchorForNode(const Node *node); const Node *findNodeForTarget(const QString &target, @@ -268,6 +274,7 @@ class HtmlGenerator : public PageGenerator CodeMarker* marker) const; void generatePageIndex(const QString& fileName, CodeMarker* marker) const; + void generateExtractionMark(const Node *node, ExtractionMarkType markType); #if 0 NavigationBar currentNavigationBar; diff --git a/tools/qdoc3/node.cpp b/tools/qdoc3/node.cpp index b077074..af129ed 100644 --- a/tools/qdoc3/node.cpp +++ b/tools/qdoc3/node.cpp @@ -1246,6 +1246,24 @@ QStringList FunctionNode::parameterNames() const } /*! + Returns a raw list of parameters. If \a names is true, the + names are included. If \a values is true, the default values + are included, if any are present. + */ +QString FunctionNode::rawParameters(bool names, bool values) const +{ + QString raw; + foreach (const Parameter ¶meter, parameters()) { + raw += parameter.leftType() + parameter.rightType(); + if (names) + raw += parameter.name(); + if (values) + raw += parameter.defaultValue(); + } + return raw; +} + +/*! Returns the list of reconstructed parameters. If \a values is true, the default values are included, if any are present. */ diff --git a/tools/qdoc3/node.h b/tools/qdoc3/node.h index e9f2d74..121b818 100644 --- a/tools/qdoc3/node.h +++ b/tools/qdoc3/node.h @@ -616,6 +616,7 @@ class FunctionNode : public LeafNode int numOverloads() const; const QList& parameters() const { return params; } QStringList parameterNames() const; + QString rawParameters(bool names = false, bool values = false) const; const FunctionNode* reimplementedFrom() const { return rf; } const QList &reimplementedBy() const { return rb; } const PropertyNode* associatedProperty() const { return ap; } -- cgit v0.12 From 4e2eb2945dbc3865e2901f12d663ed89e8f0dfbf Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 14 Jul 2010 18:35:09 +0200 Subject: Compile with QT_NO_DEBUG_STREAM Task-number: QTBUG-11510 --- src/gui/styles/qstyle.cpp | 4 ++-- src/gui/styles/qstyle.h | 2 ++ src/gui/styles/qstyleoption.cpp | 6 ++---- src/gui/styles/qstyleoption.h | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index 4cfa93f..676483e 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -2421,9 +2421,9 @@ QT_BEGIN_INCLUDE_NAMESPACE #include QT_END_INCLUDE_NAMESPACE +#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) QDebug operator<<(QDebug debug, QStyle::State state) { -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) debug << "QStyle::State("; QStringList states; @@ -2455,9 +2455,9 @@ QDebug operator<<(QDebug debug, QStyle::State state) qSort(states); debug << states.join(QLatin1String(" | ")); debug << ')'; -#endif return debug; } +#endif /*! \since 4.6 diff --git a/src/gui/styles/qstyle.h b/src/gui/styles/qstyle.h index 439d626..1ee262d 100644 --- a/src/gui/styles/qstyle.h +++ b/src/gui/styles/qstyle.h @@ -878,7 +878,9 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QStyle::State) Q_DECLARE_OPERATORS_FOR_FLAGS(QStyle::SubControls) +#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) Q_GUI_EXPORT QDebug operator<<(QDebug debug, QStyle::State state); +#endif QT_END_NAMESPACE diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp index c057a2b..eeab316 100644 --- a/src/gui/styles/qstyleoption.cpp +++ b/src/gui/styles/qstyleoption.cpp @@ -5419,9 +5419,9 @@ QStyleHintReturnVariant::QStyleHintReturnVariant() : QStyleHintReturn(Version, T Returns a T or 0 depending on the type of \a hint. */ +#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) { -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) switch (optionType) { case QStyleOption::SO_Default: debug << "SO_Default"; break; @@ -5482,21 +5482,19 @@ QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) case QStyleOption::SO_GraphicsItem: debug << "SO_GraphicsItem"; break; } -#endif return debug; } QDebug operator<<(QDebug debug, const QStyleOption &option) { -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) debug << "QStyleOption("; debug << QStyleOption::OptionType(option.type); debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight"); debug << ',' << option.state; debug << ',' << option.rect; debug << ')'; -#endif return debug; } +#endif QT_END_NAMESPACE diff --git a/src/gui/styles/qstyleoption.h b/src/gui/styles/qstyleoption.h index 95de8d5..005b36a 100644 --- a/src/gui/styles/qstyleoption.h +++ b/src/gui/styles/qstyleoption.h @@ -958,8 +958,10 @@ T qstyleoption_cast(QStyleHintReturn *hint) return 0; } +#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType); Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QStyleOption &option); +#endif QT_END_NAMESPACE -- cgit v0.12 From adbdb6c4b52d72e77d1cb4ff23573e957a7c9e14 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 15 Jul 2010 12:18:58 +1000 Subject: Performance docs. --- doc/src/declarative/qdeclarativeperformance.qdoc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/src/declarative/qdeclarativeperformance.qdoc b/doc/src/declarative/qdeclarativeperformance.qdoc index 26c1e89..be8c029 100644 --- a/doc/src/declarative/qdeclarativeperformance.qdoc +++ b/doc/src/declarative/qdeclarativeperformance.qdoc @@ -115,4 +115,25 @@ provide an image that includes the frame and the shadow. Avoid running JavaScript during animation. For example, running a complex JavaScript expression for each frame of an x property animation. +\section1 Rendering + +Often using a different graphics system will give superior performance to the native +graphics system (this is especially the case on X11). This can be configured using +QApplication::setGraphicsSystem() or via the command line using the \c -graphicssystem +switch. + +You can enable OpenGL acceleration using the \c opengl graphics system, or by setting a +QGLWidget as the viewport of your QDeclarativeView. + +You may need to try various options to find what works the best for your application. +For embedded X11-based devices one recommended combination is to use the raster graphics +system with a QGLWidget for the viewport. While this doesn't guarantee the \bold fastest +performance for all use-cases, it typically has \bold{consistently good} performance for +all use-cases. In contrast, only using the raster paint engine may result in very good +performance for parts of your application and very poor performance elsewhere. + +The QML Viewer uses the raster graphics system by default for X11 and OS X. It also +includes a \c -opengl command line option which sets a QGLWidget as the viewport of the +view. On OS X, a QGLWidget is always used. + */ -- cgit v0.12 From 8ed72a96bc5c3af283f8ca4460adae9d4b466479 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 15 Jul 2010 09:48:45 +1000 Subject: Text element does not clip even with clip=true Task: QTBUG-12201 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 +- src/declarative/graphicsitems/qdeclarativetext.cpp | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 190b22c..ddaeb05 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2503,7 +2503,7 @@ QDeclarativeListProperty QDeclarativeItemPrivate::transi \qmlproperty bool Item::clip This property holds whether clipping is enabled. - if clipping is enabled, an item will clip its own painting, as well + If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle. Non-rectangular clipping regions are not supported for performance reasons. diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 9a281e5..ba4fa21 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1127,6 +1127,15 @@ int QDeclarativeText::resourcesLoading() const return d->doc ? d->doc->resourcesLoading() : 0; } +/*! + \qmlproperty bool Text::clip + This property holds whether the text is clipped. + + Note that if the text does not fit in the bounding rectangle it will be abruptly chopped. + + If you want to display potentially long text in a limited space, you probably want to use \c elide instead. +*/ + void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeText); @@ -1146,13 +1155,10 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid bool needClip = clip() && (d->imgCache.width() > width() || d->imgCache.height() > height()); - if (needClip) { - p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); - } - p->drawPixmap(br.x(), br.y(), d->imgCache); if (needClip) - p->restore(); + p->drawPixmap(0, 0, width(), height(), d->imgCache, -br.x(), -br.y(), width(), height()); + else + p->drawPixmap(br.x(), br.y(), d->imgCache); if (d->smooth) { p->setRenderHint(QPainter::Antialiasing, oldAA); @@ -1166,7 +1172,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid if (needClip) { p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); + p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); } if (d->richText) { QAbstractTextDocumentLayout::PaintContext context; -- cgit v0.12 From b78e46817e5e2d9bd6a8d83b1447a6c4e941a5b3 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 13:00:45 +1000 Subject: Change tutorial from using "Musician" etc. types to using "PieChart" etc. types to make a more practical example that shows how to do painting as well. Also includes some tutorial improvments. --- doc/src/declarative/extending-tutorial.qdoc | 255 ++++++++++++--------- .../tutorials/extending/chapter1-basics/app.qml | 18 +- .../extending/chapter1-basics/chapter1-basics.pro | 4 +- .../tutorials/extending/chapter1-basics/main.cpp | 4 +- .../extending/chapter1-basics/musician.cpp | 66 ------ .../tutorials/extending/chapter1-basics/musician.h | 68 ------ .../extending/chapter1-basics/piechart.cpp | 81 +++++++ .../tutorials/extending/chapter1-basics/piechart.h | 71 ++++++ .../tutorials/extending/chapter2-methods/app.qml | 24 +- .../chapter2-methods/chapter2-methods.pro | 4 +- .../tutorials/extending/chapter2-methods/main.cpp | 4 +- .../extending/chapter2-methods/musician.cpp | 74 ------ .../extending/chapter2-methods/musician.h | 81 ------- .../extending/chapter2-methods/piechart.cpp | 87 +++++++ .../extending/chapter2-methods/piechart.h | 84 +++++++ .../tutorials/extending/chapter3-bindings/app.qml | 42 ++-- .../chapter3-bindings/chapter3-bindings.pro | 4 +- .../tutorials/extending/chapter3-bindings/main.cpp | 4 +- .../extending/chapter3-bindings/musician.cpp | 76 ------ .../extending/chapter3-bindings/musician.h | 82 ------- .../extending/chapter3-bindings/piechart.cpp | 89 +++++++ .../extending/chapter3-bindings/piechart.h | 84 +++++++ .../extending/chapter4-customPropertyTypes/app.qml | 18 +- .../chapter4-customPropertyTypes.pro | 8 +- .../chapter4-customPropertyTypes/instrument.cpp | 56 ----- .../chapter4-customPropertyTypes/instrument.h | 63 ----- .../chapter4-customPropertyTypes/main.cpp | 8 +- .../chapter4-customPropertyTypes/musician.cpp | 67 ------ .../chapter4-customPropertyTypes/musician.h | 78 ------- .../chapter4-customPropertyTypes/piechart.cpp | 72 ++++++ .../chapter4-customPropertyTypes/piechart.h | 78 +++++++ .../chapter4-customPropertyTypes/pieslice.cpp | 68 ++++++ .../chapter4-customPropertyTypes/pieslice.h | 66 ++++++ .../tutorials/extending/chapter5-plugins/app.qml | 16 +- .../chapter5-plugins/chapter5-plugins.pro | 12 +- .../extending/chapter5-plugins/chartsplugin.cpp | 54 +++++ .../extending/chapter5-plugins/chartsplugin.h | 55 +++++ .../extending/chapter5-plugins/instrument.cpp | 56 ----- .../extending/chapter5-plugins/instrument.h | 61 ----- .../extending/chapter5-plugins/musician.cpp | 67 ------ .../extending/chapter5-plugins/musician.h | 68 ------ .../extending/chapter5-plugins/musicplugin.cpp | 54 ----- .../extending/chapter5-plugins/musicplugin.h | 55 ----- .../extending/chapter5-plugins/piechart.cpp | 68 ++++++ .../extending/chapter5-plugins/piechart.h | 68 ++++++ .../extending/chapter5-plugins/pieslice.cpp | 67 ++++++ .../extending/chapter5-plugins/pieslice.h | 64 ++++++ 47 files changed, 1401 insertions(+), 1252 deletions(-) delete mode 100644 examples/declarative/tutorials/extending/chapter1-basics/musician.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter1-basics/musician.h create mode 100644 examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter1-basics/piechart.h delete mode 100644 examples/declarative/tutorials/extending/chapter2-methods/musician.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter2-methods/musician.h create mode 100644 examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter2-methods/piechart.h delete mode 100644 examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter3-bindings/musician.h create mode 100644 examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter3-bindings/piechart.h delete mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h delete mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h create mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h create mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp create mode 100644 examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/instrument.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/musician.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/piechart.h create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h diff --git a/doc/src/declarative/extending-tutorial.qdoc b/doc/src/declarative/extending-tutorial.qdoc index 2cf00b9..9170c5c 100644 --- a/doc/src/declarative/extending-tutorial.qdoc +++ b/doc/src/declarative/extending-tutorial.qdoc @@ -59,61 +59,94 @@ Tutorial chapters: \example declarative/tutorials/extending/chapter1-basics -Let's create a new QML type called "Musician" that has two properties: a name -and an instrument. We will make it available in a \l {Modules}{module} called "Music", with +A common task when extending QML is to provide a new QML type that supports some + custom functionality beyond what is provided by the built-in \l {QML Elements}. +For example, this could be done to implement particular data models, or provide +elements with custom painting and drawing capabilities, or access system features +like network programming that are not accessible through built-in QML features. + +In this tutorial, we will show how to use the C++ classes in the QtDeclarative +module to extend QML. The end result will be a simple Pie Chart display implemented by +several custom QML types connected together through QML features like bindings and +signals, and made available to the QML runtime through a plugin. + +To begin with, let's create a new QML type called "PieChart" that has two properties: a name +and a color. We will make it available in a \l {Modules}{module} called "Charts", with a module version of 1.0. -We want this \c Musician type to be usable from QML like this: + +We want this \c PieChart type to be usable from QML like this: \code - import Music 1.0 + import Charts 1.0 - Musician { - name: "Reddy the Rocker" - instrument: "Guitar" + PieChart { + width: 100; height: 100 + name: "A simple pie chart" + color: "red" } \endcode -To do this, we need a C++ class that encapsulates this \c Musician type and its two -properties. Since QML relies heavily on Qt's \l{Meta-Object System}{meta object system}, +To do this, we need a C++ class that encapsulates this \c PieChart type and its two +properties. Since QML makes extensive use of Qt's \l{Meta-Object System}{meta object system}, this new class must: \list -\o inherit from QObject -\o declare its properties using the Q_PROPERTY() macro +\o Inherit from QObject +\o Declare its properties using the Q_PROPERTY macro \endlist -Here is our \c Musician class, defined in \c musician.h: +Here is our \c PieChart class, defined in \c piechart.h: + +\snippet declarative/tutorials/extending/chapter1-basics/piechart.h 0 -\snippet declarative/tutorials/extending/chapter1-basics/musician.h 0 +The class inherits from QDeclarativeItem because we want to override +QDeclarativeItem::paint() in order to draw. If the class just represented some +data type and was not an item that actually needed to be displayed, it could simply inherit +from QObject. Or, if we want to extend the functionality of an existing QObject-based +class, it could inherit from that class instead. -It defines the two properties, \c name and \c instrument, with the Q_PROPERTY() macro. -The class implementation in \c musician.cpp simply sets and returns the \c m_name and -\c m_instrument values as appropriate. +The \c PieChart class defines the two properties, \c name and \c color, with the Q_PROPERTY macro, +and overrides QDeclarativeItem::paint(). The class implementation in \c piechart.cpp +simply sets and returns the \c m_name and \c m_color values as appropriate, and +implements \c paint() to draw a simple pie chart. It also turns off the +QGraphicsItem::ItemHasNoContents flag to enable painting: -Our QML file, \c app.qml, creates a \c Musician item and display the musician's details +\snippet declarative/tutorials/extending/chapter1-basics/piechart.cpp 0 +\dots 0 +\snippet declarative/tutorials/extending/chapter1-basics/piechart.cpp 1 + +Now that we have defined the \c PieChart type, we will use it from QML. The \c app.qml +file creates a \c PieChart item and display the pie chart's details using a standard QML \l Text item: \snippet declarative/tutorials/extending/chapter1-basics/app.qml 0 +Notice that although the color is specified as a string in QML, it is automatically +converted to a QColor object for the PieChart \c color property. Automatic conversions are +provided for various other \l {QML Basic Types}{basic types}; for example, a string +like "640x480" can be automatically converted to a QSize value. + We'll also create a C++ application that uses a QDeclarativeView to run and -display \c app.qml. The application must register the \c Musician type +display \c app.qml. The application must register the \c PieChart type using the qmlRegisterType() function, to allow it to be used from QML. If -you don't register the type, \c app.qml won't be able to create a \c Musician. +you don't register the type, \c app.qml won't be able to create a \c PieChart. Here is the application \c main.cpp: \snippet declarative/tutorials/extending/chapter1-basics/main.cpp 0 -This call to qmlRegisterType() registers the \c Musician type as a type called "Musician", in a module named "Music", +This call to qmlRegisterType() registers the \c PieChart type as a type called "PieChart", in a module named "Charts", with a module version of 1.0. Lastly, we write a \c .pro project file that includes the files and the \c declarative library: \quotefile declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro -Now we can build and run the application. Try it yourself with the code in Qt's \c examples/tutorials/extending/chapter1-basics directory. +Now we can build and run the application: -\example declarative/tutorials/extending/chapter1-basics +\image extending-tutorial-chapter1.png + +Try it yourself with the code in Qt's \c examples/tutorials/extending/chapter1-basics directory. At the moment, the \c app.qml is run from within a C++ application. This may seem odd if you're used to running QML files with the \l {QML Viewer}. @@ -128,39 +161,40 @@ Later on, we'll show how to create a plugin so that you can run \c app.qml using \example declarative/tutorials/extending/chapter2-methods -Suppose we want \c Musician to have a "perform" method that prints a message -to the console and then emits a "performanceEnded" signal. -Other elements would be able to call \c perform() and receive -\c performanceEnded() signals like this: +Suppose we want \c PieChart to have a "clearChart()" method that erases the +chart and then emits a "chartCleared" signal. Our \c app.qml would be able +to call \c clearChart() and receive \c chartCleared() signals like this: \snippet declarative/tutorials/extending/chapter2-methods/app.qml 0 -To do this, we add a \c perform() method and a \c performanceEnded() signal +\image extending-tutorial-chapter2.png + +To do this, we add a \c clearChart() method and a \c chartCleared() signal to our C++ class: -\snippet declarative/tutorials/extending/chapter2-methods/musician.h 0 +\snippet declarative/tutorials/extending/chapter2-methods/piechart.h 0 \dots -\snippet declarative/tutorials/extending/chapter2-methods/musician.h 1 +\snippet declarative/tutorials/extending/chapter2-methods/piechart.h 1 \dots -\snippet declarative/tutorials/extending/chapter2-methods/musician.h 2 +\snippet declarative/tutorials/extending/chapter2-methods/piechart.h 2 \dots -\snippet declarative/tutorials/extending/chapter2-methods/musician.h 3 +\snippet declarative/tutorials/extending/chapter2-methods/piechart.h 3 -The use of Q_INVOKABLE makes the \c perform() method available to the +The use of Q_INVOKABLE makes the \c clearChart() method available to the Qt Meta-Object system, and in turn, to QML. Note that it could have been declared as as a Qt slot instead of using Q_INVOKABLE, as slots are also callable from QML. Both of these approaches are valid. -The \c perform() method simply prints a message to the console and -then emits \c performanceEnded(): +The \c clearChart() method simply changes the color to Qt::transparent, +repaints the chart, then emits the \c chartCleared() signal: -\snippet declarative/tutorials/extending/chapter2-methods/musician.cpp 0 +\snippet declarative/tutorials/extending/chapter2-methods/piechart.cpp 0 -Now when we run the application and click the window, the application outputs: +Now when we run the application and click the window, the pie chart +disappears, and the application outputs: \code - "Reddy the Rocker" is playing the "Guitar" - The performance has now ended + The chart has been cleared \endcode Try out the example yourself with the updated code in Qt's \c examples/tutorials/extending/chapter2-methods directory. @@ -174,45 +208,49 @@ Try out the example yourself with the updated code in Qt's \c examples/tutorials Property bindings is a powerful feature of QML that allows values of different elements to be synchronized automatically. It uses signals to notify and update -other elements' values when property values change. +other elements' values when property values are changed. -Let's enable property bindings for the \c instrument property. That means +Let's enable property bindings for the \c color property. That means if we have code like this: \snippet declarative/tutorials/extending/chapter3-bindings/app.qml 0 -The "instrument: reddy.instrument" statement binds the \c instrument value of -\c craig to the \c instrument of \c reddy. -Whenever \c reddy's \c instrument value changes, \c craig's \c instrument value -updates to the same value. When the window is clicked, the application outputs: +\image extending-tutorial-chapter3.png -\code - "Reddy the Rocker" is playing the "Guitar" - "Craig the Copycat" is playing the "Guitar" - "Reddy the Rocker" is playing the "Drums" - "Craig the Copycat" is playing the "Drums" -\endcode +The "color: chartA.color" statement binds the \c color value of +\c chartB to the \c color of \c chartA. +Whenever \c chartA's \c color value changes, \c chartB's \c color value +updates to the same value. When the window is clicked, the \c onClicked +handler in the MouseArea changes the color of \c chartA, thereby changing +both charts to the color blue. -It's easy to enable property binding for the \c instrument property. -We add a \l{Qt's Property System}{NOTIFY} feature to its Q_PROPERTY() declaration to indicate that a "instrumentChanged" signal +It's easy to enable property binding for the \c color property. +We add a \l{Qt's Property System}{NOTIFY} feature to its Q_PROPERTY() declaration to indicate that a "colorChanged" signal is emitted whenever the value changes. -\snippet declarative/tutorials/extending/chapter3-bindings/musician.h 0 +\snippet declarative/tutorials/extending/chapter3-bindings/piechart.h 0 \dots -\snippet declarative/tutorials/extending/chapter3-bindings/musician.h 1 +\snippet declarative/tutorials/extending/chapter3-bindings/piechart.h 1 \dots -\snippet declarative/tutorials/extending/chapter3-bindings/musician.h 2 +\snippet declarative/tutorials/extending/chapter3-bindings/piechart.h 2 \dots -\snippet declarative/tutorials/extending/chapter3-bindings/musician.h 3 +\snippet declarative/tutorials/extending/chapter3-bindings/piechart.h 3 -Then, we emit this signal in \c setInstrument(): +Then, we emit this signal in \c setPieSlice(): -\snippet declarative/tutorials/extending/chapter3-bindings/musician.cpp 0 +\snippet declarative/tutorials/extending/chapter3-bindings/piechart.cpp 0 -It's important for \c setInstrument() to check that the instrument value has actually changed -before emitting \c instrumentChanged(). This ensures the signal is not emitted unnecessarily and +It's important for \c setColor() to check that the color value has actually changed +before emitting \c colorChanged(). This ensures the signal is not emitted unnecessarily and also prevents loops when other elements respond to the value change. +The use of bindings is essential to QML. You should always add NOTIFY +signals for properties if they are able to be implemented, so that your +properties can be used in bindings. Properties that cannot be bound cannot be +automatically updated and cannot be used as flexibly in QML. Also, since +bindings are invoked so often and relied upon in QML usage, users of your +custom QML types may see unexpected behavior if bindings are not implemented. + */ /*! @@ -220,19 +258,19 @@ also prevents loops when other elements respond to the value change. \example declarative/tutorials/extending/chapter4-customPropertyTypes -The \c Musician type currently has two properties that are both strings. -It could have all sorts of other properties. For example, we could add an -integer-type property to store the age of each musician: +The \c PieChart type currently has a string-type property and a color-type property. +It could have many other types of properties. For example, we could add an +integer-type property to store an identifier for each pie chart: \code - class Musician : public QObject + class PieChart : public QDeclarativeItem { ... - Q_PROPERTY(int age READ age WRITE setAge) + Q_PROPERTY(int id READ id WRITE setId) public: ... - int age() const; - void setAge(int age); + int id() const; + void setId(int id); ... }; \endcode @@ -257,31 +295,39 @@ types: If we want to create a property whose type is not supported by QML by default, we need to register the type with QML. -For example, let's change the type of the \c instrument property from a string to a -new type called "Instrument". Instead of assigning a string value to \c instrument, -we assign an \c Instrument value: +For example, let's replace the use of the \c property with a type called +"PieSlice" that has a \c color property. Instead of assigning a color, +we assign an \c PieSlice value which itself contains a \c color: \snippet declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml 0 -Like \c Musician, this new \c Instrument type has to inherit from QObject and declare +Like \c PieChart, this new \c PieSlice type inherits from QDeclarativeItem and declares its properties with Q_PROPERTY(): -\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h 0 +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h 0 -To use it from \c Musician, we modify the \c instrument property declaration +To use it in \c PieChart, we modify the \c color property declaration and associated method signatures: -\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h 0 +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h 0 \dots -\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h 1 +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h 1 \dots -\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h 2 +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h 2 \dots -\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h 3 +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h 3 + +There is one thing to be aware of when implementing \c setPieSlice(). The \c PieSlice +is a visual item, so it must be set as a child of the \c PieChart using +QDeclarativeItem::setParentItem() so that the \c PieChart knows to paint this child +item when its contents are drawn: -Like the \c Musician type, the \c Instrument type has to be registered -using qmlRegisterType() to be used from QML. As with \c Musician, we'll add the -type to the "Music" module, version 1.0: +\snippet declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp 0 + + +Like the \c PieChart type, the \c PieSlice type has to be registered +using qmlRegisterType() to be used from QML. As with \c PieChart, we'll add the +type to the "Charts" module, version 1.0: \snippet declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp 0 \dots @@ -298,10 +344,10 @@ Try it out with the code in Qt's \c examples/tutorials/extending/chapter4-custom \example declarative/tutorials/extending/chapter5-plugins -Currently the \c Musician and \c Instrument types are used by \c app.qml, +Currently the \c PieChart and \c PieSlice types are used by \c app.qml, which is displayed using a QDeclarativeView in a C++ application. An alternative way to use our QML extension is to create a plugin library to make it available -to the QML engine. This means we could load \c app.qml using the \l {QML Viewer} +to the QML engine. This allows us to load \c app.qml using the \l {QML Viewer} (or some other QML \l{Qt Declarative UI Runtime}{runtime} application) instead of writing a \c main.cpp file and loading our own C++ application. @@ -313,17 +359,17 @@ To create a plugin library, we need: \o A "qmldir" file that tells the QML engine to load the plugin \endlist -First, we create a plugin class named \c MusicPlugin. It subclasses QDeclarativeExtensionPlugin +First, we create a plugin class named \c ChartsPlugin. It subclasses QDeclarativeExtensionPlugin and registers our QML types in the inherited \l{QDeclarativeExtensionPlugin::}{registerTypes()} method. It also calls Q_EXPORT_PLUGIN2 for Qt's \l{How to Create Qt Plugins}{plugin system}. -Here is the \c MusicPlugin definition in \c musicplugin.h: +Here is the \c ChartsPlugin definition in \c chartsplugin.h: -\snippet declarative/tutorials/extending/chapter5-plugins/musicplugin.h 0 +\snippet declarative/tutorials/extending/chapter5-plugins/chartsplugin.h 0 -And its implementation in \c musicplugin.cpp: +And its implementation in \c chartsplugin.cpp: -\snippet declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp 0 +\snippet declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp 0 Then, we write a \c .pro project file that defines the project as a plugin library and specifies with DESTDIR that library files should be built into a "lib" subdirectory: @@ -345,9 +391,9 @@ the project and then load the QML file in the \l {QML Viewer}: (On Mac OS X, you can launch the "QMLViewer" application instead.) -Notice the "import Music 1.0" statement has disappeared from \c app.qml. This is +Notice the "import Charts 1.0" statement has disappeared from \c app.qml. This is because the \c qmldir file is in the same directory as \c app.qml: this is equivalent to -having Musician.qml and Instrument.qml files inside the project directory, which could both +having PieChart.qml and PieSlice.qml files inside the project directory, which could both be used by \c app.qml without import statements. */ @@ -367,42 +413,39 @@ In this tutorial, we've shown the basic steps for creating a QML extension: The \l {Extending QML in C++} reference documentation shows other useful features that can be added to -QML extensions. For example, we could use \l{Object and List Property Types}{list properties} to allow multiple instruments for a \c Musician: +QML extensions. For example, we could use \l{Object and List Property Types}{list properties} to allow multiple slices for a \c PieChart: \code - Musician { - instruments: [ - Instrument { type: "Guitar" } - Instrument { type: "Drums" } - Instrument { type: "Keyboard" } + PieChart { + slices: [ + PieSlice { color: "red" } + PieSlice { color: "blue" } + PieSlice { color: "yellow" } ] } \endcode Or use \l{Default Property}{default properties} and avoid an -\c instruments property altogether: +\c slices property altogether: \code - Musician { - Instrument { type: "Guitar" } - Instrument { type: "Drums" } - Instrument { type: "Keyboard" } + PieChart { + PieSlice { color: "red" } + PieSlice { color: "blue" } + PieSlice { color: "yellow" } } \endcode -Or even change the \c instrument of a \c Musician from time to time using \l{Property Value Sources}{property value sources}: +Or even change the \c color of a \c PieChart from time to time using \l{Property Value Sources}{property value sources}: \code - Musician { - InstrumentRandomizer on instrument {} + PieChart { + PieSliceRandomizer on color {} } \endcode See the \l{Extending QML in C++}{reference documentation} for more information. -Additionally, \l {Integrating QML with existing Qt UI code} shows how to create -and integrate with QML extensions that have drawing and graphical capabilities (through QGraphicsWidget). - */ diff --git a/examples/declarative/tutorials/extending/chapter1-basics/app.qml b/examples/declarative/tutorials/extending/chapter1-basics/app.qml index 9af155c..ada088d 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/app.qml +++ b/examples/declarative/tutorials/extending/chapter1-basics/app.qml @@ -38,21 +38,23 @@ ** ****************************************************************************/ //![0] -import Music 1.0 +import Charts 1.0 import Qt 4.7 -Rectangle { +Item { width: 300; height: 200 - Musician { - id: aMusician - name: "Reddy the Rocker" - instrument: "Guitar" + PieChart { + id: aPieChart + anchors.centerIn: parent + width: 100; height: 100 + name: "A simple pie chart" + color: "red" } Text { - anchors.fill: parent - text: aMusician.name + " plays the " + aMusician.instrument + anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + text: aPieChart.name } } //![0] diff --git a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro index bd05ebe..0f04167 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro +++ b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro @@ -1,5 +1,5 @@ QT += declarative -HEADERS += musician.h -SOURCES += musician.cpp \ +HEADERS += piechart.h +SOURCES += piechart.cpp \ main.cpp diff --git a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp index 8ef6965..a5dbab3 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp +++ b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp @@ -38,7 +38,7 @@ ** ****************************************************************************/ //![0] -#include "musician.h" +#include "piechart.h" #include #include #include @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - qmlRegisterType("Music", 1, 0, "Musician"); + qmlRegisterType("Charts", 1, 0, "PieChart"); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("app.qml")); diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp b/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp deleted file mode 100644 index 6c42f31..0000000 --- a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musician.h" - -Musician::Musician(QObject *parent) - : QObject(parent) -{ -} - -QString Musician::name() const -{ - return m_name; -} - -void Musician::setName(const QString &name) -{ - m_name = name; -} - -QString Musician::instrument() const -{ - return m_instrument; -} - -void Musician::setInstrument(const QString &instrument) -{ - m_instrument = instrument; -} - diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.h b/examples/declarative/tutorials/extending/chapter1-basics/musician.h deleted file mode 100644 index f9a0537..0000000 --- a/examples/declarative/tutorials/extending/chapter1-basics/musician.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICIAN_H -#define MUSICIAN_H - -//![0] -#include - -class Musician : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString instrument READ instrument WRITE setInstrument) - -public: - Musician(QObject *parent = 0); - - QString name() const; - void setName(const QString &name); - - QString instrument() const; - void setInstrument(const QString &instrument); - -private: - QString m_name; - QString m_instrument; -}; -//![0] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp new file mode 100644 index 0000000..3b9ef71 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include + +//![0] +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} +//![0] + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +QColor PieChart::color() const +{ + return m_color; +} + +void PieChart::setColor(const QColor &color) +{ + m_color = color; +} + +//![1] +void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), 90 * 16, 290 * 16); +} +//![1] + diff --git a/examples/declarative/tutorials/extending/chapter1-basics/piechart.h b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h new file mode 100644 index 0000000..aae7b26 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +//![0] +#include +#include + +class PieChart : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + + QColor color() const; + void setColor(const QColor &color); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + QString m_name; + QColor m_color; +}; +//![0] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter2-methods/app.qml b/examples/declarative/tutorials/extending/chapter2-methods/app.qml index 02d33c2..0b55f7c 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/app.qml +++ b/examples/declarative/tutorials/extending/chapter2-methods/app.qml @@ -38,23 +38,29 @@ ** ****************************************************************************/ //![0] -import Music 1.0 +import Charts 1.0 import Qt 4.7 -Rectangle { - width: 200; height: 200 +Item { + width: 300; height: 200 - Musician { - id: aMusician - name: "Reddy the Rocker" - instrument: "Guitar" + PieChart { + id: aPieChart + anchors.centerIn: parent + width: 100; height: 100 + color: "red" - onPerformanceEnded: console.log("The performance has now ended") + onChartCleared: console.log("The chart has been cleared") } MouseArea { anchors.fill: parent - onClicked: aMusician.perform() + onClicked: aPieChart.clearChart() + } + + Text { + anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + text: "Click anywhere to clear the chart" } } //![0] diff --git a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro index bd05ebe..0f04167 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro +++ b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro @@ -1,5 +1,5 @@ QT += declarative -HEADERS += musician.h -SOURCES += musician.cpp \ +HEADERS += piechart.h +SOURCES += piechart.cpp \ main.cpp diff --git a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp index 8ef6965..a5dbab3 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp +++ b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp @@ -38,7 +38,7 @@ ** ****************************************************************************/ //![0] -#include "musician.h" +#include "piechart.h" #include #include #include @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - qmlRegisterType("Music", 1, 0, "Musician"); + qmlRegisterType("Charts", 1, 0, "PieChart"); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("app.qml")); diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp b/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp deleted file mode 100644 index 0ce0022..0000000 --- a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musician.h" -#include - -Musician::Musician(QObject *parent) - : QObject(parent) -{ -} - -QString Musician::name() const -{ - return m_name; -} - -void Musician::setName(const QString &name) -{ - m_name = name; -} - -QString Musician::instrument() const -{ - return m_instrument; -} - -void Musician::setInstrument(const QString &instrument) -{ - m_instrument = instrument; -} - -//![0] -void Musician::perform() -{ - qWarning() << m_name << "is playing the" << m_instrument; - emit performanceEnded(); -} -//![0] diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.h b/examples/declarative/tutorials/extending/chapter2-methods/musician.h deleted file mode 100644 index 86849ba..0000000 --- a/examples/declarative/tutorials/extending/chapter2-methods/musician.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICIAN_H -#define MUSICIAN_H - -#include - -//![0] -class Musician : public QObject -{ -//![0] - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString instrument READ instrument WRITE setInstrument) - -//![1] -public: -//![1] - - Musician(QObject *parent = 0); - - QString name() const; - void setName(const QString &name); - - QString instrument() const; - void setInstrument(const QString &instrument); - -//![2] - Q_INVOKABLE void perform(); - -signals: - void performanceEnded(); -//![2] - -private: - QString m_name; - QString m_instrument; - -//![3] -}; -//![3] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp new file mode 100644 index 0000000..11ff7c8 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include +#include + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +QColor PieChart::color() const +{ + return m_color; +} + +void PieChart::setColor(const QColor &color) +{ + m_color = color; +} + +void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), 90 * 16, 290 * 16); +} + +//![0] +void PieChart::clearChart() +{ + setColor(QColor(Qt::transparent)); + update(); + + emit chartCleared(); +} +//![0] diff --git a/examples/declarative/tutorials/extending/chapter2-methods/piechart.h b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h new file mode 100644 index 0000000..246fd9f --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include +#include + +//![0] +class PieChart : public QDeclarativeItem +{ +//![0] + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QColor color READ color WRITE setColor) + +//![1] +public: +//![1] + + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + + QColor color() const; + void setColor(const QColor &color); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +//![2] + Q_INVOKABLE void clearChart(); + +signals: + void chartCleared(); +//![2] + +private: + QString m_name; + QColor m_color; + +//![3] +}; +//![3] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml index 8bf6ecf..2ff6ae1 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml +++ b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml @@ -38,35 +38,37 @@ ** ****************************************************************************/ //![0] -import Music 1.0 +import Charts 1.0 import Qt 4.7 -Rectangle { - width: 200; height: 200 +Item { + width: 300; height: 200 - Musician { - id: reddy - name: "Reddy the Rocker" - instrument: "Guitar" - } + Row { + anchors.centerIn: parent + spacing: 20 + + PieChart { + id: chartA + width: 100; height: 100 + color: "red" + } - Musician { - id: craig - name: "Craig the Copycat" - instrument: reddy.instrument + PieChart { + id: chartB + width: 100; height: 100 + color: chartA.color + } } MouseArea { anchors.fill: parent - onClicked: { - reddy.perform() - craig.perform() - - reddy.instrument = "Drums" + onClicked: { chartA.color = "blue" } + } - reddy.perform() - craig.perform() - } + Text { + anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + text: "Click anywhere to change the chart color" } } //![0] diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro index bd05ebe..0f04167 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro +++ b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro @@ -1,5 +1,5 @@ QT += declarative -HEADERS += musician.h -SOURCES += musician.cpp \ +HEADERS += piechart.h +SOURCES += piechart.cpp \ main.cpp diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp index 8ef6965..a5dbab3 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp +++ b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp @@ -38,7 +38,7 @@ ** ****************************************************************************/ //![0] -#include "musician.h" +#include "piechart.h" #include #include #include @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - qmlRegisterType("Music", 1, 0, "Musician"); + qmlRegisterType("Charts", 1, 0, "PieChart"); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("app.qml")); diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp deleted file mode 100644 index 5f9ead4..0000000 --- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musician.h" -#include - -Musician::Musician(QObject *parent) - : QObject(parent) -{ -} - -QString Musician::name() const -{ - return m_name; -} - -void Musician::setName(const QString &name) -{ - m_name = name; -} - -QString Musician::instrument() const -{ - return m_instrument; -} - -//![0] -void Musician::setInstrument(const QString &instrument) -{ - if (instrument != m_instrument) { - m_instrument = instrument; - emit instrumentChanged(); - } -} -//![0] - -void Musician::perform() -{ - qWarning() << m_name << "is playing the" << m_instrument; -} diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h b/examples/declarative/tutorials/extending/chapter3-bindings/musician.h deleted file mode 100644 index 0b0addb..0000000 --- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICIAN_H -#define MUSICIAN_H - -#include - -//![0] -class Musician : public QObject -{ -//![0] - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString instrument READ instrument WRITE setInstrument) - -//![1] - Q_PROPERTY(QString instrument READ instrument WRITE setInstrument NOTIFY instrumentChanged) -public: -//![1] - - Musician(QObject *parent = 0); - - QString name() const; - void setName(const QString &name); - - QString instrument() const; - void setInstrument(const QString &instrument); - - Q_INVOKABLE void perform(); - -//![2] -signals: - void instrumentChanged(); -//![2] - -private: - QString m_name; - QString m_instrument; - -//![3] -}; -//![3] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp new file mode 100644 index 0000000..85a9762 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include +#include + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +QColor PieChart::color() const +{ + return m_color; +} + +//![0] +void PieChart::setColor(const QColor &color) +{ + if (color != m_color) { + m_color = color; + update(); // repaint with the new color + emit colorChanged(); + } +} +//![0] + +void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), 90 * 16, 290 * 16); +} + +void PieChart::clearChart() +{ + setColor(QColor(Qt::transparent)); + update(); +} diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h new file mode 100644 index 0000000..164cebb --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include +#include + +//![0] +class PieChart : public QDeclarativeItem +{ +//![0] + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + +//![1] + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) +public: +//![1] + + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + + QColor color() const; + void setColor(const QColor &color); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + + Q_INVOKABLE void clearChart(); + +//![2] +signals: + void colorChanged(); +//![2] + +private: + QString m_name; + QColor m_color; + +//![3] +}; +//![3] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml index d76f801..fcd3806 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml @@ -38,17 +38,23 @@ ** ****************************************************************************/ //![0] -import Music 1.0 +import Charts 1.0 import Qt 4.7 Item { + width: 300; height: 200 - Musician { - id: reddy - name: "Reddy the Rocker" - instrument: Instrument { type: "Guitar" } + PieChart { + id: chart + anchors.centerIn: parent + width: 100; height: 100 + + pieSlice: PieSlice { + anchors.fill: parent + color: "red" + } } - Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type) + Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color) } //![0] diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro index aea07a0..c3f5402 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro @@ -1,7 +1,7 @@ QT += declarative -HEADERS += musician.h \ - instrument.h -SOURCES += musician.cpp \ - instrument.cpp \ +HEADERS += piechart.h \ + pieslice.h +SOURCES += piechart.cpp \ + pieslice.cpp \ main.cpp diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp deleted file mode 100644 index 9ca96f6..0000000 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "instrument.h" - -Instrument::Instrument(QObject *parent) - : QObject(parent) -{ -} - -QString Instrument::type() const -{ - return m_type; -} - -void Instrument::setType(const QString &type) -{ - m_type = type; -} - diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h deleted file mode 100644 index 9971207..0000000 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef INSTRUMENT_H -#define INSTRUMENT_H - -#include - -//![0] -class Instrument : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString type READ type WRITE setType) - -public: - Instrument(QObject *parent = 0); - - QString type() const; - void setType(const QString &type); - -private: - QString m_type; -}; -//![0] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp index d94cb03..fd518a2 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp @@ -37,8 +37,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "musician.h" -#include "instrument.h" +#include "piechart.h" +#include "pieslice.h" #include #include @@ -50,10 +50,10 @@ int main(int argc, char *argv[]) //![0] QApplication app(argc, argv); - qmlRegisterType("Music", 1, 0, "Musician"); + qmlRegisterType("Charts", 1, 0, "PieChart"); //![1] - qmlRegisterType("Music", 1, 0, "Instrument"); + qmlRegisterType("Charts", 1, 0, "PieSlice"); //![1] QDeclarativeView view; diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp deleted file mode 100644 index e62efb1..0000000 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musician.h" -#include "instrument.h" - -Musician::Musician(QObject *parent) - : QObject(parent) -{ -} - -QString Musician::name() const -{ - return m_name; -} - -void Musician::setName(const QString &name) -{ - m_name = name; -} - -Instrument *Musician::instrument() const -{ - return m_instrument; -} - -void Musician::setInstrument(Instrument *instrument) -{ - m_instrument = instrument; -} - diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h deleted file mode 100644 index 8f67f61..0000000 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICIAN_H -#define MUSICIAN_H - -#include - -class Instrument; - -//![0] -class Musician : public QObject -{ - Q_OBJECT - Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument) -//![0] - Q_PROPERTY(QString name READ name WRITE setName) - -//![1] -public: -//![1] - - Musician(QObject *parent = 0); - - QString name() const; - void setName(const QString &name); - -//![2] - Instrument *instrument() const; - void setInstrument(Instrument *instrument); -//![2] - -private: - QString m_name; - Instrument *m_instrument; - -//![3] -}; -//![3] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp new file mode 100644 index 0000000..7098854 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // this doesn't need to disable QGraphicsItem::ItemHasNoContents + // anymore since the drawing is now done in PieSlice +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +PieSlice *PieChart::pieSlice() const +{ + return m_pieSlice; +} + +//![0] +void PieChart::setPieSlice(PieSlice *pieSlice) +{ + m_pieSlice = pieSlice; + pieSlice->setParentItem(this); +} +//![0] + diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h new file mode 100644 index 0000000..448ca7b --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include + +class PieSlice; + +//![0] +class PieChart : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) +//![0] + Q_PROPERTY(QString name READ name WRITE setName) + +//![1] +public: +//![1] + + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + +//![2] + PieSlice *pieSlice() const; + void setPieSlice(PieSlice *pieSlice); +//![2] + +private: + QString m_name; + PieSlice *m_pieSlice; + +//![3] +}; +//![3] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp new file mode 100644 index 0000000..7a420fd --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "pieslice.h" + +#include + +PieSlice::PieSlice(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QColor PieSlice::color() const +{ + return m_color; +} + +void PieSlice::setColor(const QColor &color) +{ + m_color = color; +} + +void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), 90 * 16, 290 * 16); +} + diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h new file mode 100644 index 0000000..085a9b8 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIESLICE_H +#define PIESLICE_H + +#include +#include + +//![0] +class PieSlice : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + PieSlice(QDeclarativeItem *parent = 0); + + QColor color() const; + void setColor(const QColor &color); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + QColor m_color; +}; +//![0] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml b/examples/declarative/tutorials/extending/chapter5-plugins/app.qml index 9c050b8..b06e399 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml +++ b/examples/declarative/tutorials/extending/chapter5-plugins/app.qml @@ -41,13 +41,19 @@ import Qt 4.7 Item { + width: 300; height: 200 - Musician { - id: reddy - name: "Reddy the Rocker" - instrument: Instrument { type: "Guitar" } + PieChart { + id: chart + anchors.centerIn: parent + width: 100; height: 100 + + pieSlice: PieSlice { + anchors.fill: parent + color: "red" + } } - Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type) + Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color) } diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro index 483da8f..1ffbf29 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro +++ b/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro @@ -6,13 +6,13 @@ DESTDIR = lib OBJECTS_DIR = tmp MOC_DIR = tmp -HEADERS += musician.h \ - instrument.h \ - musicplugin.h +HEADERS += piechart.h \ + pieslice.h \ + chartsplugin.h -SOURCES += musician.cpp \ - instrument.cpp \ - musicplugin.cpp +SOURCES += piechart.cpp \ + pieslice.cpp \ + chartsplugin.cpp symbian { include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp new file mode 100644 index 0000000..5aa2a4b --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "chartsplugin.h" +//![0] +#include "piechart.h" +#include "pieslice.h" +#include + +void ChartsPlugin::registerTypes(const char *uri) +{ + qmlRegisterType(uri, 1, 0, "PieChart"); + qmlRegisterType(uri, 1, 0, "PieSlice"); +} + +Q_EXPORT_PLUGIN2(chartsplugin, ChartsPlugin); +//![0] + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h new file mode 100644 index 0000000..797d1e7 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CHARTSPLUGIN_H +#define CHARTSPLUGIN_H + +//![0] +#include + +class ChartsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri); +}; +//![0] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp deleted file mode 100644 index 9ca96f6..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "instrument.h" - -Instrument::Instrument(QObject *parent) - : QObject(parent) -{ -} - -QString Instrument::type() const -{ - return m_type; -} - -void Instrument::setType(const QString &type) -{ - m_type = type; -} - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h deleted file mode 100644 index ce1e7ce..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef INSTRUMENT_H -#define INSTRUMENT_H - -#include - -class Instrument : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString type READ type WRITE setType) - -public: - Instrument(QObject *parent = 0); - - QString type() const; - void setType(const QString &type); - -private: - QString m_type; -}; - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp deleted file mode 100644 index e62efb1..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musician.h" -#include "instrument.h" - -Musician::Musician(QObject *parent) - : QObject(parent) -{ -} - -QString Musician::name() const -{ - return m_name; -} - -void Musician::setName(const QString &name) -{ - m_name = name; -} - -Instrument *Musician::instrument() const -{ - return m_instrument; -} - -void Musician::setInstrument(Instrument *instrument) -{ - m_instrument = instrument; -} - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h b/examples/declarative/tutorials/extending/chapter5-plugins/musician.h deleted file mode 100644 index b920631..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICIAN_H -#define MUSICIAN_H - -#include - -class Instrument; - -class Musician : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument) - -public: - Musician(QObject *parent = 0); - - QString name() const; - void setName(const QString &name); - - Instrument *instrument() const; - void setInstrument(Instrument *instrument); - -private: - QString m_name; - Instrument *m_instrument; -}; - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp deleted file mode 100644 index 76acf01..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "musicplugin.h" -//![0] -#include "musician.h" -#include "instrument.h" -#include - -void MusicPlugin::registerTypes(const char *uri) -{ - qmlRegisterType(uri, 1, 0, "Musician"); - qmlRegisterType(uri, 1, 0, "Instrument"); -} - -Q_EXPORT_PLUGIN2(musicplugin, MusicPlugin); -//![0] - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h b/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h deleted file mode 100644 index d6a5392..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MUSICPLUGIN_H -#define MUSICPLUGIN_H - -//![0] -#include - -class MusicPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - void registerTypes(const char *uri); -}; -//![0] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp new file mode 100644 index 0000000..2d7acf7 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +PieSlice *PieChart::pieSlice() const +{ + return m_pieSlice; +} + +void PieChart::setPieSlice(PieSlice *pieSlice) +{ + m_pieSlice = pieSlice; + m_pieSlice->setParentItem(this); +} + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h new file mode 100644 index 0000000..a8b5b6e --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include + +class PieSlice; + +class PieChart : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) + +public: + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + + PieSlice *pieSlice() const; + void setPieSlice(PieSlice *pieSlice); + +private: + QString m_name; + PieSlice *m_pieSlice; +}; + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp new file mode 100644 index 0000000..a312da3 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "pieslice.h" + +#include + +PieSlice::PieSlice(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QColor PieSlice::color() const +{ + return m_color; +} + +void PieSlice::setColor(const QColor &color) +{ + m_color = color; +} + +void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), 90 * 16, 290 * 16); +} diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h new file mode 100644 index 0000000..6774731 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIESLICE_H +#define PIESLICE_H + +#include +#include + +class PieSlice : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + PieSlice(QDeclarativeItem *parent = 0); + + QColor color() const; + void setColor(const QColor &QColor); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + QColor m_color; +}; + +#endif + -- cgit v0.12 From fb8869e00da635be7660d845d4cb631d230bed6e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 13:23:26 +1000 Subject: fix spelling --- src/declarative/qml/qdeclarativelist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp index 7c89672..9598d98 100644 --- a/src/declarative/qml/qdeclarativelist.cpp +++ b/src/declarative/qml/qdeclarativelist.cpp @@ -306,7 +306,7 @@ int QDeclarativeListReference::count() const /*! \class QDeclarativeListProperty \since 4.7 -\brief The QDeclarativeListProperty class allows applications to explose list-like +\brief The QDeclarativeListProperty class allows applications to expose list-like properties to QML. QML has many list properties, where more than one object value can be assigned. -- cgit v0.12 From 7d0b62158471d46db9902ce0d0d7b7244c743cce Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 15:29:20 +1000 Subject: Add chapter on creating list property types --- doc/src/declarative/extending-tutorial.qdoc | 103 ++++++++++++++------- .../pics/extending-tutorial-chapter1.png | Bin 0 -> 6687 bytes .../pics/extending-tutorial-chapter2.png | Bin 0 -> 7318 bytes .../pics/extending-tutorial-chapter3.png | Bin 0 -> 8145 bytes .../pics/extending-tutorial-chapter5.png | Bin 0 -> 5557 bytes .../tutorials/extending/chapter5-plugins/app.qml | 59 ------------ .../chapter5-plugins/chapter5-plugins.pro | 20 ---- .../extending/chapter5-plugins/chartsplugin.cpp | 54 ----------- .../extending/chapter5-plugins/chartsplugin.h | 55 ----------- .../extending/chapter5-plugins/piechart.cpp | 68 -------------- .../extending/chapter5-plugins/piechart.h | 68 -------------- .../extending/chapter5-plugins/pieslice.cpp | 67 -------------- .../extending/chapter5-plugins/pieslice.h | 64 ------------- .../tutorials/extending/chapter5-plugins/qmldir | 1 - .../tutorials/extending/chapter6-plugins/app.qml | 68 ++++++++++++++ .../chapter6-plugins/chapter6-plugins.pro | 20 ++++ .../extending/chapter6-plugins/chartsplugin.cpp | 54 +++++++++++ .../extending/chapter6-plugins/chartsplugin.h | 55 +++++++++++ .../extending/chapter6-plugins/piechart.cpp | 71 ++++++++++++++ .../extending/chapter6-plugins/piechart.h | 69 ++++++++++++++ .../extending/chapter6-plugins/pieslice.cpp | 88 ++++++++++++++++++ .../extending/chapter6-plugins/pieslice.h | 74 +++++++++++++++ .../tutorials/extending/chapter6-plugins/qmldir | 1 + 23 files changed, 572 insertions(+), 487 deletions(-) create mode 100644 doc/src/declarative/pics/extending-tutorial-chapter1.png create mode 100644 doc/src/declarative/pics/extending-tutorial-chapter2.png create mode 100644 doc/src/declarative/pics/extending-tutorial-chapter3.png create mode 100644 doc/src/declarative/pics/extending-tutorial-chapter5.png delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/app.qml delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/piechart.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h delete mode 100644 examples/declarative/tutorials/extending/chapter5-plugins/qmldir create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/app.qml create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/piechart.h create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h create mode 100644 examples/declarative/tutorials/extending/chapter6-plugins/qmldir diff --git a/doc/src/declarative/extending-tutorial.qdoc b/doc/src/declarative/extending-tutorial.qdoc index 9170c5c..cc93e86 100644 --- a/doc/src/declarative/extending-tutorial.qdoc +++ b/doc/src/declarative/extending-tutorial.qdoc @@ -48,8 +48,9 @@ Tutorial chapters: \o \l{declarative/tutorials/extending/chapter2-methods}{Connecting to C++ Methods and Signals} \o \l{declarative/tutorials/extending/chapter3-bindings}{Adding Property Bindings} \o \l{declarative/tutorials/extending/chapter4-customPropertyTypes}{Using Custom Property Types} -\o \l{declarative/tutorials/extending/chapter5-plugins}{Writing an Extension Plugin} -\o \l{qml-extending-tutorial6.html}{In Summary} +\o \l{declarative/tutorials/extending/chapter5-listproperties}{Using List Property Types} +\o \l{declarative/tutorials/extending/chapter6-plugins}{Writing an Extension Plugin} +\o \l{qml-extending-tutorial7.html}{In Summary} \endlist */ @@ -339,15 +340,65 @@ Try it out with the code in Qt's \c examples/tutorials/extending/chapter4-custom */ + +/*! +\title Chapter 5: Using List Property Types + +\example declarative/tutorials/extending/chapter5-listproperties + +Right now, a \c PieChart can only have one \c PieSlice. Ideally a chart would +have multiple slices, with different colors and sizes. To do this, we could +have a \c slices property that accepts a list of \c PieSlice items: + +\snippet declarative/tutorials/extending/chapter5-listproperties/app.qml 0 + +\image extending-tutorial-chapter5.png + +To do this, we replace the \c pieSlice property in \c PieChart with a \c slices property, +declared as a QDeclarativeListProperty type. The QDeclarativeListProperty class enables the +creation of list properties in QML extensions. We replace the \c pieSlice() +function with a \c slices() function that returns a list of slices, and add +an internal \c append_slice() function (discussed below). We also use a QList to +store the internal list of slices as \c m_slices: + +\snippet declarative/tutorials/extending/chapter5-listproperties/piechart.h 0 +\dots +\snippet declarative/tutorials/extending/chapter5-listproperties/piechart.h 1 +\dots +\snippet declarative/tutorials/extending/chapter5-listproperties/piechart.h 2 + +Although the \c slices property does not have an associated \c WRITE function, +it is still modifiable because of the way QDeclarativeListProperty works. +In the \c PieChart implementation, we implement \c PieChart::slices() to +return a QDeclarativeListProperty value and indicate that the internal +\c PieChart::append_slice() function is to be called whenever a request is made from QML +to add items to the list: + +\snippet declarative/tutorials/extending/chapter5-listproperties/piechart.cpp 0 + +The \c append_slice() function simply sets the parent item as before, +and adds the new item to the \c m_slices list. As you can see, the append function for a +QDeclarativeListProperty is called with two arguments: the list property, and +the item that is to be appended. + +The \c PieSlice class has also been modified to include \c fromAngle and \c angleSpan +properties and to draw the slice according to these values. This is a straightforward +modification if you have read the previous pages in this tutorial, so the code is not shown here. + +The complete code can be seen in the updated \c examples/tutorials/extending/chapter5-listproperties directory. + +*/ + + /*! -\title Chapter 5: Writing an Extension Plugin +\title Chapter 6: Writing an Extension Plugin -\example declarative/tutorials/extending/chapter5-plugins +\example declarative/tutorials/extending/chapter6-plugins Currently the \c PieChart and \c PieSlice types are used by \c app.qml, which is displayed using a QDeclarativeView in a C++ application. An alternative way to use our QML extension is to create a plugin library to make it available -to the QML engine. This allows us to load \c app.qml using the \l {QML Viewer} +to the QML engine. This allows \c app.qml to be loaded with the \l {QML Viewer} (or some other QML \l{Qt Declarative UI Runtime}{runtime} application) instead of writing a \c main.cpp file and loading our own C++ application. @@ -365,22 +416,22 @@ Q_EXPORT_PLUGIN2 for Qt's \l{How to Create Qt Plugins}{plugin system}. Here is the \c ChartsPlugin definition in \c chartsplugin.h: -\snippet declarative/tutorials/extending/chapter5-plugins/chartsplugin.h 0 +\snippet declarative/tutorials/extending/chapter6-plugins/chartsplugin.h 0 And its implementation in \c chartsplugin.cpp: -\snippet declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp 0 +\snippet declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp 0 Then, we write a \c .pro project file that defines the project as a plugin library and specifies with DESTDIR that library files should be built into a "lib" subdirectory: -\quotefile declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro +\quotefile declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro Finally, we add a \c qmldir file that is automatically parsed by the QML engine. -Here, we specify that a plugin named "chapter5-plugin" (the name +Here, we specify that a plugin named "chapter6-plugin" (the name of the example project) can be found in the "lib" subdirectory: -\quotefile declarative/tutorials/extending/chapter5-plugins/qmldir +\quotefile declarative/tutorials/extending/chapter6-plugins/qmldir Now we have a plugin, and instead of having a main.cpp and an executable, we can build the project and then load the QML file in the \l {QML Viewer}: @@ -397,9 +448,10 @@ having PieChart.qml and PieSlice.qml files inside the project directory, which c be used by \c app.qml without import statements. */ + /*! -\page qml-extending-tutorial6.html -\title Chapter 6: In Summary +\page qml-extending-tutorial7.html +\title Chapter 7: In Summary In this tutorial, we've shown the basic steps for creating a QML extension: @@ -408,39 +460,28 @@ In this tutorial, we've shown the basic steps for creating a QML extension: \o Add callable methods using Q_INVOKABLE or Qt slots, and connect to Qt signals with an \c onSignal syntax \o Add property bindings by defining \l{Qt's Property System}{NOTIFY} signals \o Define custom property types if the built-in types are not sufficient +\o Define list property types using QDeclarativeListProperty \o Create a plugin library by defining a Qt plugin and writing a \c qmldir file \endlist The \l {Extending QML in C++} reference documentation shows other useful features that can be added to -QML extensions. For example, we could use \l{Object and List Property Types}{list properties} to allow multiple slices for a \c PieChart: - -\code - PieChart { - slices: [ - PieSlice { color: "red" } - PieSlice { color: "blue" } - PieSlice { color: "yellow" } - ] - } -\endcode - -Or use \l{Default Property}{default properties} and avoid an -\c slices property altogether: +QML extensions. For example, we could use \l{Default Property}{default properties} to allow +slices to be added without using the \c slices property: \code PieChart { - PieSlice { color: "red" } - PieSlice { color: "blue" } - PieSlice { color: "yellow" } + PieSlice { ... } + PieSlice { ... } + PieSlice { ... } } \endcode -Or even change the \c color of a \c PieChart from time to time using \l{Property Value Sources}{property value sources}: +Or randomly add and remove slices from time to time using \l{Property Value Sources}{property value sources}: \code PieChart { - PieSliceRandomizer on color {} + PieSliceRandomizer on slices {} } \endcode diff --git a/doc/src/declarative/pics/extending-tutorial-chapter1.png b/doc/src/declarative/pics/extending-tutorial-chapter1.png new file mode 100644 index 0000000..9f5836b Binary files /dev/null and b/doc/src/declarative/pics/extending-tutorial-chapter1.png differ diff --git a/doc/src/declarative/pics/extending-tutorial-chapter2.png b/doc/src/declarative/pics/extending-tutorial-chapter2.png new file mode 100644 index 0000000..5c8f222 Binary files /dev/null and b/doc/src/declarative/pics/extending-tutorial-chapter2.png differ diff --git a/doc/src/declarative/pics/extending-tutorial-chapter3.png b/doc/src/declarative/pics/extending-tutorial-chapter3.png new file mode 100644 index 0000000..825553f Binary files /dev/null and b/doc/src/declarative/pics/extending-tutorial-chapter3.png differ diff --git a/doc/src/declarative/pics/extending-tutorial-chapter5.png b/doc/src/declarative/pics/extending-tutorial-chapter5.png new file mode 100644 index 0000000..0c2e69e Binary files /dev/null and b/doc/src/declarative/pics/extending-tutorial-chapter5.png differ diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml b/examples/declarative/tutorials/extending/chapter5-plugins/app.qml deleted file mode 100644 index b06e399..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** 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 QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -Item { - width: 300; height: 200 - - PieChart { - id: chart - anchors.centerIn: parent - width: 100; height: 100 - - pieSlice: PieSlice { - anchors.fill: parent - color: "red" - } - } - - Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color) -} - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro deleted file mode 100644 index 1ffbf29..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro +++ /dev/null @@ -1,20 +0,0 @@ -TEMPLATE = lib -CONFIG += qt plugin -QT += declarative - -DESTDIR = lib -OBJECTS_DIR = tmp -MOC_DIR = tmp - -HEADERS += piechart.h \ - pieslice.h \ - chartsplugin.h - -SOURCES += piechart.cpp \ - pieslice.cpp \ - chartsplugin.cpp - -symbian { - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) - TARGET.EPOCALLOWDLLDATA = 1 -} diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp deleted file mode 100644 index 5aa2a4b..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "chartsplugin.h" -//![0] -#include "piechart.h" -#include "pieslice.h" -#include - -void ChartsPlugin::registerTypes(const char *uri) -{ - qmlRegisterType(uri, 1, 0, "PieChart"); - qmlRegisterType(uri, 1, 0, "PieSlice"); -} - -Q_EXPORT_PLUGIN2(chartsplugin, ChartsPlugin); -//![0] - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h b/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h deleted file mode 100644 index 797d1e7..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef CHARTSPLUGIN_H -#define CHARTSPLUGIN_H - -//![0] -#include - -class ChartsPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - void registerTypes(const char *uri); -}; -//![0] - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp deleted file mode 100644 index 2d7acf7..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "piechart.h" -#include "pieslice.h" - -PieChart::PieChart(QDeclarativeItem *parent) - : QDeclarativeItem(parent) -{ -} - -QString PieChart::name() const -{ - return m_name; -} - -void PieChart::setName(const QString &name) -{ - m_name = name; -} - -PieSlice *PieChart::pieSlice() const -{ - return m_pieSlice; -} - -void PieChart::setPieSlice(PieSlice *pieSlice) -{ - m_pieSlice = pieSlice; - m_pieSlice->setParentItem(this); -} - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h deleted file mode 100644 index a8b5b6e..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PIECHART_H -#define PIECHART_H - -#include - -class PieSlice; - -class PieChart : public QDeclarativeItem -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) - -public: - PieChart(QDeclarativeItem *parent = 0); - - QString name() const; - void setName(const QString &name); - - PieSlice *pieSlice() const; - void setPieSlice(PieSlice *pieSlice); - -private: - QString m_name; - PieSlice *m_pieSlice; -}; - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp deleted file mode 100644 index a312da3..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "pieslice.h" - -#include - -PieSlice::PieSlice(QDeclarativeItem *parent) - : QDeclarativeItem(parent) -{ - // need to disable this flag to draw inside a QDeclarativeItem - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QColor PieSlice::color() const -{ - return m_color; -} - -void PieSlice::setColor(const QColor &color) -{ - m_color = color; -} - -void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - QPen pen(m_color, 2); - painter->setPen(pen); - painter->setRenderHints(QPainter::Antialiasing, true); - painter->drawPie(boundingRect(), 90 * 16, 290 * 16); -} diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h deleted file mode 100644 index 6774731..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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 documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PIESLICE_H -#define PIESLICE_H - -#include -#include - -class PieSlice : public QDeclarativeItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - PieSlice(QDeclarativeItem *parent = 0); - - QColor color() const; - void setColor(const QColor &QColor); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - -private: - QColor m_color; -}; - -#endif - diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir b/examples/declarative/tutorials/extending/chapter5-plugins/qmldir deleted file mode 100644 index c3afd6b..0000000 --- a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin chapter5-plugins lib diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/app.qml b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml new file mode 100644 index 0000000..38ceefa --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +import Qt 4.7 + +Item { + width: 300; height: 200 + + PieChart { + anchors.centerIn: parent + width: 100; height: 100 + + slices: [ + PieSlice { + anchors.fill: parent + color: "red" + fromAngle: 0; angleSpan: 110 + }, + PieSlice { + anchors.fill: parent + color: "black" + fromAngle: 110; angleSpan: 50 + }, + PieSlice { + anchors.fill: parent + color: "blue" + fromAngle: 160; angleSpan: 100 + } + ] + } +} + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro new file mode 100644 index 0000000..1ffbf29 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +CONFIG += qt plugin +QT += declarative + +DESTDIR = lib +OBJECTS_DIR = tmp +MOC_DIR = tmp + +HEADERS += piechart.h \ + pieslice.h \ + chartsplugin.h + +SOURCES += piechart.cpp \ + pieslice.cpp \ + chartsplugin.cpp + +symbian { + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.EPOCALLOWDLLDATA = 1 +} diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp new file mode 100644 index 0000000..5aa2a4b --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "chartsplugin.h" +//![0] +#include "piechart.h" +#include "pieslice.h" +#include + +void ChartsPlugin::registerTypes(const char *uri) +{ + qmlRegisterType(uri, 1, 0, "PieChart"); + qmlRegisterType(uri, 1, 0, "PieSlice"); +} + +Q_EXPORT_PLUGIN2(chartsplugin, ChartsPlugin); +//![0] + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h new file mode 100644 index 0000000..797d1e7 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CHARTSPLUGIN_H +#define CHARTSPLUGIN_H + +//![0] +#include + +class ChartsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri); +}; +//![0] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp new file mode 100644 index 0000000..4e6ee5c --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +QDeclarativeListProperty PieChart::slices() +{ + return QDeclarativeListProperty(this, 0, &PieChart::append_slice); +} + +void PieChart::append_slice(QDeclarativeListProperty *list, PieSlice *slice) +{ + PieChart *chart = qobject_cast(list->object); + if (chart) { + slice->setParentItem(chart); + chart->m_slices.append(slice); + } +} + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h new file mode 100644 index 0000000..d6e4439 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include + +class PieSlice; + +class PieChart : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty slices READ slices) + Q_PROPERTY(QString name READ name WRITE setName) + +public: + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + + QDeclarativeListProperty slices(); + +private: + static void append_slice(QDeclarativeListProperty *list, PieSlice *slice); + + QString m_name; + QList m_slices; +}; + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp new file mode 100644 index 0000000..65120f5 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "pieslice.h" + +#include + +PieSlice::PieSlice(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QColor PieSlice::color() const +{ + return m_color; +} + +void PieSlice::setColor(const QColor &color) +{ + m_color = color; +} + +int PieSlice::fromAngle() const +{ + return m_fromAngle; +} + +void PieSlice::setFromAngle(int angle) +{ + m_fromAngle = angle; +} + +int PieSlice::angleSpan() const +{ + return m_angleSpan; +} + +void PieSlice::setAngleSpan(int angle) +{ + m_angleSpan = angle; +} + +void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16); +} + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h new file mode 100644 index 0000000..a3afd25 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIESLICE_H +#define PIESLICE_H + +#include +#include + +class PieSlice : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + +public: + PieSlice(QDeclarativeItem *parent = 0); + + QColor color() const; + void setColor(const QColor &color); + + int fromAngle() const; + void setFromAngle(int angle); + + int angleSpan() const; + void setAngleSpan(int span); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + QColor m_color; + int m_fromAngle; + int m_angleSpan; +}; + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/qmldir b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir new file mode 100644 index 0000000..a83bf85 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir @@ -0,0 +1 @@ +plugin chapter6-plugins lib -- cgit v0.12 From 5be65b4ce744945ba31f110660a4cf58c123742b Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 16:36:26 +1000 Subject: fix doc link --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 110c970..fa422fd 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1732,7 +1732,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) highlight is not moved by the view, and any movement must be implemented by the highlight. - Here is a highlight with its motion defined by a \l {SpringAniamtion} item: + Here is a highlight with its motion defined by a \l {SpringAnimation} item: \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem -- cgit v0.12 From 14ad729f1e2f07a46cdb41f01a6e5267084b8816 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 16:46:22 +1000 Subject: Add files missing from last commit --- .../extending/chapter5-listproperties/app.qml | 70 +++++++++++++++++ .../chapter5-listproperties.pro | 7 ++ .../extending/chapter5-listproperties/main.cpp | 58 ++++++++++++++ .../extending/chapter5-listproperties/piechart.cpp | 72 ++++++++++++++++++ .../extending/chapter5-listproperties/piechart.h | 75 ++++++++++++++++++ .../extending/chapter5-listproperties/pieslice.cpp | 88 ++++++++++++++++++++++ .../extending/chapter5-listproperties/pieslice.h | 76 +++++++++++++++++++ 7 files changed, 446 insertions(+) create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/app.qml create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp create mode 100644 examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml new file mode 100644 index 0000000..f759bc9 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![0] +import Charts 1.0 +import Qt 4.7 + +Item { + width: 300; height: 200 + + PieChart { + anchors.centerIn: parent + width: 100; height: 100 + + slices: [ + PieSlice { + anchors.fill: parent + color: "red" + fromAngle: 0; angleSpan: 110 + }, + PieSlice { + anchors.fill: parent + color: "black" + fromAngle: 110; angleSpan: 50 + }, + PieSlice { + anchors.fill: parent + color: "blue" + fromAngle: 160; angleSpan: 100 + } + ] + } +} +//![0] diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro new file mode 100644 index 0000000..c3f5402 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro @@ -0,0 +1,7 @@ +QT += declarative + +HEADERS += piechart.h \ + pieslice.h +SOURCES += piechart.cpp \ + pieslice.cpp \ + main.cpp diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp new file mode 100644 index 0000000..f73c49f --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterType("Charts", 1, 0, "PieChart"); + qmlRegisterType("Charts", 1, 0, "PieSlice"); + + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("app.qml")); + view.show(); + return app.exec(); +} diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp new file mode 100644 index 0000000..2515b64 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +//![0] +QDeclarativeListProperty PieChart::slices() +{ + return QDeclarativeListProperty(this, 0, &PieChart::append_slice); +} + +void PieChart::append_slice(QDeclarativeListProperty *list, PieSlice *slice) +{ + PieChart *chart = qobject_cast(list->object); + if (chart) { + slice->setParentItem(chart); + chart->m_slices.append(slice); + } +} +//![0] diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h new file mode 100644 index 0000000..4424251 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include + +class PieSlice; + +//![0] +class PieChart : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty slices READ slices) +//![0] + Q_PROPERTY(QString name READ name WRITE setName) + +//![1] +public: +//![1] + PieChart(QDeclarativeItem *parent = 0); + + QString name() const; + void setName(const QString &name); + +//![2] + QDeclarativeListProperty slices(); + +private: + static void append_slice(QDeclarativeListProperty *list, PieSlice *slice); + + QString m_name; + QList m_slices; +}; +//![2] + +#endif + diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp new file mode 100644 index 0000000..65120f5 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "pieslice.h" + +#include + +PieSlice::PieSlice(QDeclarativeItem *parent) + : QDeclarativeItem(parent) +{ + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QColor PieSlice::color() const +{ + return m_color; +} + +void PieSlice::setColor(const QColor &color) +{ + m_color = color; +} + +int PieSlice::fromAngle() const +{ + return m_fromAngle; +} + +void PieSlice::setFromAngle(int angle) +{ + m_fromAngle = angle; +} + +int PieSlice::angleSpan() const +{ + return m_angleSpan; +} + +void PieSlice::setAngleSpan(int angle) +{ + m_angleSpan = angle; +} + +void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16); +} + diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h new file mode 100644 index 0000000..7cd0c74 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIESLICE_H +#define PIESLICE_H + +#include +#include + +//![0] +class PieSlice : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) +//![0] + +public: + PieSlice(QDeclarativeItem *parent = 0); + + QColor color() const; + void setColor(const QColor &color); + + int fromAngle() const; + void setFromAngle(int angle); + + int angleSpan() const; + void setAngleSpan(int span); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +private: + QColor m_color; + int m_fromAngle; + int m_angleSpan; +}; + +#endif + -- cgit v0.12 From 5893e05aa453f1ecbc0ee35d5fca5d671828dfc2 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 15 Jul 2010 16:48:30 +1000 Subject: Fix .pro file --- examples/declarative/tutorials/extending/extending.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/declarative/tutorials/extending/extending.pro b/examples/declarative/tutorials/extending/extending.pro index 0c86fed..967473f 100644 --- a/examples/declarative/tutorials/extending/extending.pro +++ b/examples/declarative/tutorials/extending/extending.pro @@ -5,5 +5,6 @@ SUBDIRS += \ chapter2-methods \ chapter3-bindings \ chapter4-customPropertyTypes \ - chapter5-plugins + chapter5-listproperties \ + chapter6-plugins -- cgit v0.12 From 920980c77269325cc94efd2ff10347bd2745736d Mon Sep 17 00:00:00 2001 From: axis Date: Wed, 14 Jul 2010 08:38:04 +0200 Subject: Fixed install docs for Qt for Symbian on Linux. --- doc/src/snippets/code/doc_src_installation.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/snippets/code/doc_src_installation.qdoc b/doc/src/snippets/code/doc_src_installation.qdoc index 985f3da..c46159c 100644 --- a/doc/src/snippets/code/doc_src_installation.qdoc +++ b/doc/src/snippets/code/doc_src_installation.qdoc @@ -263,7 +263,7 @@ make //! [40] //! [41] -cd src/s60installs +cd src make sis //! [41] -- cgit v0.12 From dcfa4125625c028165c424b5d95cb0795194d6f2 Mon Sep 17 00:00:00 2001 From: axis Date: Wed, 14 Jul 2010 08:38:30 +0200 Subject: Removed README.s60-mkspec. The instructions are old, and should now be found in the qdoc docs. --- README.s60-mkspec | 99 ------------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 README.s60-mkspec diff --git a/README.s60-mkspec b/README.s60-mkspec deleted file mode 100644 index af500e1..0000000 --- a/README.s60-mkspec +++ /dev/null @@ -1,99 +0,0 @@ -How to build Qt for Symbian using the Linux makespec. - -Prerequisites: - - - Working RVCT 2.2 native Linux compiler. The new publicly - available RVCT 4.0 compiler may work, but it hasn't been tested - yet. - - - A working GnuPoc environment. See this page for details: - http://www.martin.st/symbian/ - Download the latest version, unpack it and run the 'install_eka2_tools' script as - described in the last part under the EKA2 part. The part about the your own gcc - are not needed as we use the rvct compiler. - Make sure you do the part about Wine setup as well. - - - Anderson Lizardo's patches for GnuPoc. Look for the - qt_s60_gnupoc_v10.patch on this page: - http://lizardo.wordpress.com/2009/09/24/installing-qt-for-s60-daily-snapshots-on-linux/ - and carry out the instructions under point 8: Installing Open C. - -Compiling: - - 1. First a few environment variables need to be set: - - export RVCT22LIB=/lib/armlib - export EPOCROOT= - export PATH=$PATH:/epoc32/tools:/bin - export PATH=$PATH:/bin - - Replace the s60-root with the installation directory of your SDK, - and the qt-root with the root of your Qt repository. - These are good candidates for putting in a script somewhere. - - 2. Run configure. It needs a bit more switches than usual, so here's - the full line: - - ./configure -developer-build -platform linux-g++ -xplatform \ - symbian/linux-armcc -little-endian -host-little-endian \ - -arch symbian - - 3. Compile Qt - - cd src - make - - and then wait for a while. - - 4. Package and install Qt - - cd s60installs - - Edit Qt_template.pkg and change the first 0x2xxxxxxx to - 0xExxxxxxx. Then execute: - - makesis Qt_template.pkg - signsis Qt_template.sis Qt_template.sisx selfsigned.cer selfsigned.key - - Then put Qt_template.sisx on a memory card and install it from - the phone file manager. - - Alternatively, you can use the runonphone tool found in the tools - directory of Qt. To build, this requires a separately configured - Qt installation for Linux, unfortunately. To use it, you also - need have App TRK running on the phone. At the time of writing, - only bleeding edge Linux kernels are able to autodetect the USB - serial port on the phone, but you can force detection by running: - - modprobe usbserial vendor=0xXXXX product=0xXXXX - - The XXXXs should be replaced with the two values listed for your - device when executing "lsusb". In most distributions, this will - lead to the creation of two devices: /dev/ttyUSB0 and - /dev/ttyUSB1. The latter is usually the one that App TRK responds - to. Then execute: - - runonphone -p /dev/ttyUSB1 -s Qt_template.sisx dummy.exe - - The dummy.exe argument is irrelevant, since we are not executing - anything yet. - - 5. Compile some helloworld application (I leave the details to you - ;-) - - qmake - make - - 6. Package, install and run application. - - makesis helloworld_template.pkg - signsis helloworld_template.sis helloworld_template.sisx \ - /src/s60installs/selfsigned.cer \ - /src/s60installs/selfsigned.key - - Then either install by memory card, or install and run like this: - - runonphone -p /dev/ttyUSB1 -s helloworld_template.sisx \ - helloworld.exe - - 7. Enjoy "hello world" on the phone! -- cgit v0.12 From 12b6275a21076df582e80c422b31560d8ee995d0 Mon Sep 17 00:00:00 2001 From: axis Date: Wed, 14 Jul 2010 08:39:46 +0200 Subject: Allow commenting of individual files in generated pkg files. RevBy: Jason Barron --- bin/patch_capabilities.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/patch_capabilities.pl b/bin/patch_capabilities.pl index 501939a..7d6f5dc 100755 --- a/bin/patch_capabilities.pl +++ b/bin/patch_capabilities.pl @@ -186,7 +186,7 @@ if (@ARGV) } # If the line specifies a file, parse the source and destination locations. - if ($line =~ m|\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|) + if ($line =~ m|^ *\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|) { my $sourcePath = $1; -- cgit v0.12 From 511985fa173daa9b8462dbb72c45a74626e8cba4 Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Thu, 15 Jul 2010 10:18:02 +0200 Subject: Fix for tst_qmdisubwindow::fixedMinMaxSize failure on Cocoa We need to respect the size restrictions for all QWidgets. Previously this was only applied to top levels. Reviewed-by: Bradley T. Hughes --- src/gui/kernel/qwidget_mac.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index e57ec77..c788711 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -4389,6 +4389,13 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM data.window_state = data.window_state & ~Qt::WindowMaximized; const bool visible = q->isVisible(); + // Apply size restrictions, applicable for Windows & Widgets. + if (QWExtra *extra = extraData()) { + w = qMin(w, extra->maxw); + h = qMin(h, extra->maxh); + w = qMax(w, extra->minw); + h = qMax(h, extra->minh); + } data.crect = QRect(x, y, w, h); if (realWindow) { -- cgit v0.12 From 633349982422fec92df4ed06da5d2becf788c494 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 15 Jul 2010 10:39:40 +0200 Subject: Amend previous commit 4e2eb2945dbc3865e2901f12d663ed89e8f0dfbf to fix compilation with QT_NO_DEBUG_STREAM Qt in debug need to stay binary compatible with Qt in release. See also commit cbbd7e084c7e46fd906db26b13032b8368c59093 that introduced the problem Task-number: QTBUG-11510 --- src/gui/styles/qstyle.cpp | 4 +++- src/gui/styles/qstyle.h | 2 +- src/gui/styles/qstyleoption.cpp | 6 +++++- src/gui/styles/qstyleoption.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index 676483e..687e587 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -2421,9 +2421,10 @@ QT_BEGIN_INCLUDE_NAMESPACE #include QT_END_INCLUDE_NAMESPACE -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) QDebug operator<<(QDebug debug, QStyle::State state) { +#if !defined(QT_NO_DEBUG) debug << "QStyle::State("; QStringList states; @@ -2455,6 +2456,7 @@ QDebug operator<<(QDebug debug, QStyle::State state) qSort(states); debug << states.join(QLatin1String(" | ")); debug << ')'; +#endif return debug; } #endif diff --git a/src/gui/styles/qstyle.h b/src/gui/styles/qstyle.h index 1ee262d..439901a 100644 --- a/src/gui/styles/qstyle.h +++ b/src/gui/styles/qstyle.h @@ -878,7 +878,7 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QStyle::State) Q_DECLARE_OPERATORS_FOR_FLAGS(QStyle::SubControls) -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) Q_GUI_EXPORT QDebug operator<<(QDebug debug, QStyle::State state); #endif diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp index eeab316..4780edf 100644 --- a/src/gui/styles/qstyleoption.cpp +++ b/src/gui/styles/qstyleoption.cpp @@ -5419,9 +5419,10 @@ QStyleHintReturnVariant::QStyleHintReturnVariant() : QStyleHintReturn(Version, T Returns a T or 0 depending on the type of \a hint. */ -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) { +#if !defined(QT_NO_DEBUG) switch (optionType) { case QStyleOption::SO_Default: debug << "SO_Default"; break; @@ -5482,17 +5483,20 @@ QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) case QStyleOption::SO_GraphicsItem: debug << "SO_GraphicsItem"; break; } +#endif return debug; } QDebug operator<<(QDebug debug, const QStyleOption &option) { +#if !defined(QT_NO_DEBUG) debug << "QStyleOption("; debug << QStyleOption::OptionType(option.type); debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight"); debug << ',' << option.state; debug << ',' << option.rect; debug << ')'; +#endif return debug; } #endif diff --git a/src/gui/styles/qstyleoption.h b/src/gui/styles/qstyleoption.h index 005b36a..e79d9a4 100644 --- a/src/gui/styles/qstyleoption.h +++ b/src/gui/styles/qstyleoption.h @@ -958,7 +958,7 @@ T qstyleoption_cast(QStyleHintReturn *hint) return 0; } -#if !defined(QT_NO_DEBUG) && !defined(QT_NO_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType); Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QStyleOption &option); #endif -- cgit v0.12 From 518a8ab0fe67965555973788e3eea643882cb80c Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 15 Jul 2010 10:36:18 +0200 Subject: fix for looping crash log on data abort When a thread panics, calling resume allows the thread to proceed to the exit handler and shut down. When a thread takes an exception, calling resume continues from the same point so the exception happens again. To avoid this, we add crashed thread ids to a list. If we see the same thread crash again, we terminate the process without trying to fetch the call stack a second time. Reviewed-by: Jason Barron --- tools/runonphone/trksignalhandler.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/runonphone/trksignalhandler.cpp b/tools/runonphone/trksignalhandler.cpp index b6d446f..898692a 100644 --- a/tools/runonphone/trksignalhandler.cpp +++ b/tools/runonphone/trksignalhandler.cpp @@ -71,8 +71,10 @@ private: QFile crashlogtextfile; QFile crashstackfile; QList queuedCrashes; + QList dyingThreads; QString crashlogPath; bool crashlog; + bool terminateNeeded; }; void TrkSignalHandler::copyingStarted() @@ -201,15 +203,23 @@ void TrkSignalHandler::stopped(uint pc, uint pid, uint tid, const QString& reaso cs.crashPC = pc; cs.crashReason = reason; - d->queuedCrashes.append(cs); - - if (d->queuedCrashes.count() == 1) { - d->err << "Fetching registers and stack..." << endl; - emit getRegistersAndCallStack(pid, tid); + if (d->dyingThreads.contains(tid)) { + if(d->queuedCrashes.isEmpty()) + emit terminate(); + else + d->terminateNeeded = true; + } else { + d->queuedCrashes.append(cs); + d->dyingThreads.append(tid); + + if (d->queuedCrashes.count() == 1) { + d->err << "Fetching registers and stack..." << endl; + emit getRegistersAndCallStack(pid, tid); + } } } else - emit resume(pid, tid); + emit terminate(); } void TrkSignalHandler::registersAndCallStackReadComplete(const QList& registers, const QByteArray& stack) @@ -307,6 +317,8 @@ void TrkSignalHandler::registersAndCallStackReadComplete(const QList& regi d->err << "Fetching registers and stack..." << endl; emit getRegistersAndCallStack(cs.pid, cs.tid); } + else if (d->terminateNeeded) + emit terminate(); } @@ -333,7 +345,8 @@ TrkSignalHandlerPrivate::TrkSignalHandlerPrivate() : out(stdout), err(stderr), loglevel(0), - lastpercent(0) + lastpercent(0), + terminateNeeded(false) { } -- cgit v0.12 From 910b8fe6222011b8f94259f165bcf4d4002172c0 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Thu, 15 Jul 2010 11:08:17 +0200 Subject: QFileDialog : Fix completer showing up on the MyComputer view. Only complete if there is a text to complete Reviewed-by:janarve --- src/gui/util/qcompleter.cpp | 4 +++- tests/auto/qfiledialog2/tst_qfiledialog2.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index 1abc2d9..04d6de9 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -154,6 +154,7 @@ #include "QtGui/qevent.h" #include "QtGui/qheaderview.h" #include "QtGui/qdesktopwidget.h" +#include "QtGui/qlineedit.h" QT_BEGIN_NAMESPACE @@ -920,8 +921,9 @@ void QCompleterPrivate::showPopup(const QRect& rect) void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path) { Q_Q(QCompleter); + QLineEdit *lineEdit = qobject_cast(widget); //the path given by QFileSystemModel does not end with / - if (!q->completionPrefix().isEmpty() && q->completionPrefix() != path + QLatin1Char('/')) + if (lineEdit && !lineEdit->text().isEmpty() && !q->completionPrefix().isEmpty() && q->completionPrefix() != path + QLatin1Char('/')) q->complete(); } diff --git a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp index eee495f..6299c24 100644 --- a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp @@ -140,6 +140,7 @@ private slots: void QTBUG4419_lineEditSelectAll(); void QTBUG6558_showDirsOnly(); void QTBUG4842_selectFilterWithHideNameFilterDetails(); + void dontShowCompleterOnRoot(); private: QByteArray userSettings; @@ -1194,5 +1195,26 @@ void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails() } +void tst_QFileDialog2::dontShowCompleterOnRoot() +{ + QNonNativeFileDialog fd(0, "TestFileDialog"); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.show(); + + QApplication::setActiveWindow(&fd); + QTest::qWaitForWindowShown(&fd); + QTRY_COMPARE(fd.isVisible(), true); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(&fd)); + + fd.setDirectory(""); + QLineEdit *lineEdit = qFindChild(&fd, "fileNameEdit"); + QTRY_VERIFY(lineEdit->text().isEmpty()); + + //The gatherer thread will then return the result + QApplication::processEvents(); + + QTRY_VERIFY(lineEdit->completer()->popup()->isHidden()); +} + QTEST_MAIN(tst_QFileDialog2) #include "tst_qfiledialog2.moc" -- cgit v0.12 From 73473634b706548d603dafe22c9424a007d1bf3b Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 15 Jul 2010 11:20:07 +0200 Subject: Revert BIC change "Build Qt with option -Zc:wchar_t under MSVC" This reverts commit a9c8decc741d8c2b340f38d7a854ef206672ab3e. Postponed for Qt5. Or different makespecs. --- mkspecs/win32-msvc2005/qmake.conf | 2 +- mkspecs/win32-msvc2008/qmake.conf | 2 +- mkspecs/win32-msvc2010/qmake.conf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mkspecs/win32-msvc2005/qmake.conf b/mkspecs/win32-msvc2005/qmake.conf index a5999cc..0406fd0 100644 --- a/mkspecs/win32-msvc2005/qmake.conf +++ b/mkspecs/win32-msvc2005/qmake.conf @@ -16,7 +16,7 @@ QMAKE_LEX = flex QMAKE_LEXFLAGS = QMAKE_YACC = byacc QMAKE_YACCFLAGS = -d -QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t +QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- QMAKE_CFLAGS_WARN_ON = -W3 QMAKE_CFLAGS_WARN_OFF = -W0 QMAKE_CFLAGS_RELEASE = -O2 -MD diff --git a/mkspecs/win32-msvc2008/qmake.conf b/mkspecs/win32-msvc2008/qmake.conf index 1aab8e1..9805e90 100644 --- a/mkspecs/win32-msvc2008/qmake.conf +++ b/mkspecs/win32-msvc2008/qmake.conf @@ -16,7 +16,7 @@ QMAKE_LEX = flex QMAKE_LEXFLAGS = QMAKE_YACC = byacc QMAKE_YACCFLAGS = -d -QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t +QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- QMAKE_CFLAGS_WARN_ON = -W3 QMAKE_CFLAGS_WARN_OFF = -W0 QMAKE_CFLAGS_RELEASE = -O2 -MD diff --git a/mkspecs/win32-msvc2010/qmake.conf b/mkspecs/win32-msvc2010/qmake.conf index 34a7782..28d4d3c 100644 --- a/mkspecs/win32-msvc2010/qmake.conf +++ b/mkspecs/win32-msvc2010/qmake.conf @@ -16,7 +16,7 @@ QMAKE_LEX = flex QMAKE_LEXFLAGS = QMAKE_YACC = byacc QMAKE_YACCFLAGS = -d -QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t +QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t- QMAKE_CFLAGS_WARN_ON = -W3 QMAKE_CFLAGS_WARN_OFF = -W0 QMAKE_CFLAGS_RELEASE = -O2 -MD -- cgit v0.12 From 367aa34cbcfa109926087e89d49f9223c1409d44 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jul 2010 13:23:56 +0200 Subject: Add a QAuthenticatorPrivate parsing for the headers without QHttpResponseHeader Reviewed-by: Markus Goetz --- src/network/access/qhttpnetworkconnection.cpp | 9 ++----- src/network/kernel/qauthenticator.cpp | 39 ++++++++++++++++++--------- src/network/kernel/qauthenticator_p.h | 1 + 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 1afabec..9e2b85e 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -286,13 +286,8 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket resend = false; //create the response header to be used with QAuthenticatorPrivate. - QHttpResponseHeader responseHeader; QList > fields = reply->header(); - QList >::const_iterator it = fields.constBegin(); - while (it != fields.constEnd()) { - responseHeader.addValue(QString::fromLatin1(it->first), QString::fromUtf8(it->second)); - it++; - } + //find out the type of authentication protocol requested. QAuthenticatorPrivate::Method authMethod = reply->d_func()->authenticationMethod(isProxy); if (authMethod != QAuthenticatorPrivate::None) { @@ -310,7 +305,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket if (auth->isNull()) auth->detach(); QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*auth); - priv->parseHttpResponse(responseHeader, isProxy); + priv->parseHttpResponse(fields, isProxy); if (priv->phase == QAuthenticatorPrivate::Done) { if ((isProxy && pendingProxyAuthSignal) ||(!isProxy && pendingAuthSignal)) { diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index e7442c0..0ea4fd4 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -241,7 +241,20 @@ QAuthenticatorPrivate::QAuthenticatorPrivate() #ifndef QT_NO_HTTP void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, bool isProxy) { - QList > values = header.values(); + const QList > values = header.values(); + QList > rawValues; + + QList >::const_iterator it, end; + for (it = values.constBegin(), end = values.constEnd(); it != end; ++it) + rawValues.append(qMakePair(it->first.toLatin1(), it->second.toUtf8())); + + // continue in byte array form + parseHttpResponse(rawValues, isProxy); +} +#endif + +void QAuthenticatorPrivate::parseHttpResponse(const QList > &values, bool isProxy) +{ const char *search = isProxy ? "proxy-authenticate" : "www-authenticate"; method = None; @@ -255,24 +268,25 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, authentication parameters. */ - QString headerVal; + QByteArray headerVal; for (int i = 0; i < values.size(); ++i) { - const QPair ¤t = values.at(i); - if (current.first.toLower() != QLatin1String(search)) + const QPair ¤t = values.at(i); + if (current.first.toLower() != search) continue; - QString str = current.second; - if (method < Basic && str.startsWith(QLatin1String("Basic"), Qt::CaseInsensitive)) { - method = Basic; headerVal = str.mid(6); - } else if (method < Ntlm && str.startsWith(QLatin1String("NTLM"), Qt::CaseInsensitive)) { + QByteArray str = current.second.toLower(); + if (method < Basic && str.startsWith("basic")) { + method = Basic; + headerVal = current.second.mid(6); + } else if (method < Ntlm && str.startsWith("ntlm")) { method = Ntlm; - headerVal = str.mid(5); - } else if (method < DigestMd5 && str.startsWith(QLatin1String("Digest"), Qt::CaseInsensitive)) { + headerVal = current.second.mid(5); + } else if (method < DigestMd5 && str.startsWith("digest")) { method = DigestMd5; - headerVal = str.mid(7); + headerVal = current.second.mid(7); } } - challenge = headerVal.trimmed().toLatin1(); + challenge = headerVal.trimmed(); QHash options = parseDigestAuthenticationChallenge(challenge); switch(method) { @@ -300,7 +314,6 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, phase = Invalid; } } -#endif QByteArray QAuthenticatorPrivate::calculateResponse(const QByteArray &requestMethod, const QByteArray &path) { diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h index e9ce9ac..abb1cda 100644 --- a/src/network/kernel/qauthenticator_p.h +++ b/src/network/kernel/qauthenticator_p.h @@ -102,6 +102,7 @@ public: #ifndef QT_NO_HTTP void parseHttpResponse(const QHttpResponseHeader &, bool isProxy); #endif + void parseHttpResponse(const QList >&, bool isProxy); }; -- cgit v0.12 From 69027cdb2ab9b89673edf29d5034bed33e614a05 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jul 2010 12:58:04 +0200 Subject: Expose the QAuthenticator map of options in the API. Task-number: QT-3573 Reviewed-By: Markus Goetz --- src/network/kernel/qauthenticator.cpp | 45 +++++++++++++++++++++++++++++++++-- src/network/kernel/qauthenticator.h | 5 ++++ src/network/kernel/qauthenticator_p.h | 3 ++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 0ea4fd4..ca8ec1c 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -140,7 +140,8 @@ bool QAuthenticator::operator==(const QAuthenticator &other) const return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm - && d->method == other.d->method; + && d->method == other.d->method + && d->options == other.d->options; } /*! @@ -218,9 +219,49 @@ QString QAuthenticator::realm() const return d ? d->realm : QString(); } +/*! + \since 4.7 + Returns the value related to option \a opt if it was set by the server. + See \l{QAuthenticator#Options} for more information on incoming options. + If option \a opt isn't found, an invalid QVariant will be returned. + + \sa options(), QAuthenticator#Options +*/ +QVariant QAuthenticator::option(const QString &opt) const +{ + return d ? d->options.value(opt) : QVariant(); +} + +/*! + \since 4.7 + Returns all incoming options set in this QAuthenticator object by parsing + the server reply. See \l{QAuthenticator#Options} for more information + on incoming options. + + \sa option(), QAuthenticator#Options +*/ +QVariantHash QAuthenticator::options() const +{ + return d ? d->options : QVariantHash(); +} + +/*! + \since 4.7 + + Sets the outgoing option \a opt to value \a value. + See \l{QAuthenticator#Options} for more information on outgoing options. + + \sa options(), option(), QAuthenticator#Options +*/ +void QAuthenticator::setOption(const QString &opt, const QVariant &value) +{ + detach(); + d->options.insert(opt, value); +} + /*! - returns true if the authenticator is null. + Returns true if the authenticator is null. */ bool QAuthenticator::isNull() const { diff --git a/src/network/kernel/qauthenticator.h b/src/network/kernel/qauthenticator.h index 13ce593..983b7c0 100644 --- a/src/network/kernel/qauthenticator.h +++ b/src/network/kernel/qauthenticator.h @@ -43,6 +43,7 @@ #define QAUTHENTICATOR_H #include +#include QT_BEGIN_HEADER @@ -73,6 +74,10 @@ public: QString realm() const; + QVariant option(const QString &opt) const; + QVariantHash options() const; + void setOption(const QString &opt, const QVariant &value); + bool isNull() const; void detach(); private: diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h index abb1cda..665afef 100644 --- a/src/network/kernel/qauthenticator_p.h +++ b/src/network/kernel/qauthenticator_p.h @@ -57,6 +57,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -71,7 +72,7 @@ public: QAtomicInt ref; QString user; QString password; - QHash options; + QVariantHash options; Method method; QString realm; QByteArray challenge; -- cgit v0.12 From 1af3362a321dd055798173737d3aede367a1d30c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jul 2010 13:01:33 +0200 Subject: Add documentation for the QAuthenticator options. Task-number: QT-3573 Reviewed-by: Markus Goetz --- src/network/kernel/qauthenticator.cpp | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index ca8ec1c..d61c686 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -85,6 +85,44 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas Note that, in particular, NTLM version 2 is not supported. + \section1 Options + + In addition to the username and password required for authentication, a + QAuthenticator object can also contain additional options. The + options() function can be used to query incoming options sent by + the server; the setOption() function can + be used to set outgoing options, to be processed by the authenticator + calculation. The options accepted and provided depend on the authentication + type (see method()). + + The following tables list known incoming options as well as accepted + outgoing options. The list of incoming options is not exhaustive, since + servers may include additional information at any time. The list of + outgoing options is exhaustive, however, and no unknown options will be + treated or sent back to the server. + + \section2 Basic + + \table + \header \o Option \o Direction \o Description + \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm() + \endtable + + The Basic authentication mechanism supports no outgoing options. + + \section2 NTLM version 1 + + The NTLM authentication mechanism currently supports no incoming or outgoing options. + + \section2 Digest-MD5 + + \table + \header \o Option \o Direction \o Description + \row \o \tt{realm} \o Incoming \o Contains the realm of the authentication, the same as realm() + \endtable + + The Digest-MD5 authentication mechanism supports no outgoing options. + \sa QSslSocket */ @@ -333,7 +371,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QListoptions[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm")); if (user.isEmpty()) phase = Done; break; @@ -342,7 +380,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QListoptions[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm")); if (options.value("stale").toLower() == "true") phase = Start; if (user.isEmpty()) -- cgit v0.12 From 648f8a05abac5fbf851fff18d1c34ff7c4a7a027 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jul 2010 17:21:25 +0200 Subject: Autotest: add a small, boring test for QAuthenticator --- src/network/kernel/qauthenticator_p.h | 2 +- tests/auto/qauthenticator/qauthenticator.pro | 5 + tests/auto/qauthenticator/tst_qauthenticator.cpp | 155 +++++++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qauthenticator/qauthenticator.pro create mode 100644 tests/auto/qauthenticator/tst_qauthenticator.cpp diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h index 665afef..1096601 100644 --- a/src/network/kernel/qauthenticator_p.h +++ b/src/network/kernel/qauthenticator_p.h @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE class QHttpResponseHeader; -class QAuthenticatorPrivate +class Q_AUTOTEST_EXPORT QAuthenticatorPrivate { public: enum Method { None, Basic, Plain, Login, Ntlm, CramMd5, DigestMd5 }; diff --git a/tests/auto/qauthenticator/qauthenticator.pro b/tests/auto/qauthenticator/qauthenticator.pro new file mode 100644 index 0000000..05f83bc --- /dev/null +++ b/tests/auto/qauthenticator/qauthenticator.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +requires(contains(QT_CONFIG,private_tests)) +QT = core network +SOURCES += tst_qauthenticator.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/qauthenticator/tst_qauthenticator.cpp b/tests/auto/qauthenticator/tst_qauthenticator.cpp new file mode 100644 index 0000000..37d6774 --- /dev/null +++ b/tests/auto/qauthenticator/tst_qauthenticator.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** 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 FOO module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include + +#include + +class tst_QAuthenticator : public QObject +{ + Q_OBJECT + +public: + tst_QAuthenticator(); + +private Q_SLOTS: + void basicAuth(); + void basicAuth_data(); + + void ntlmAuth_data(); + void ntlmAuth(); +}; + +tst_QAuthenticator::tst_QAuthenticator() +{ +} + +void tst_QAuthenticator::basicAuth_data() +{ + QTest::addColumn("data"); + QTest::addColumn("realm"); + QTest::addColumn("user"); + QTest::addColumn("password"); + QTest::addColumn("expectedReply"); + + QTest::newRow("just-user") << "" << "" << "foo" << "" << QByteArray("foo:").toBase64(); + QTest::newRow("user-password") << "" << "" << "foo" << "bar" << QByteArray("foo:bar").toBase64(); + QTest::newRow("user-password-realm") << "realm=\"secure area\"" << "secure area" << "foo" << "bar" << QByteArray("foo:bar").toBase64(); +} + +void tst_QAuthenticator::basicAuth() +{ + QFETCH(QString, data); + QFETCH(QString, realm); + QFETCH(QString, user); + QFETCH(QString, password); + QFETCH(QByteArray, expectedReply); + + QAuthenticator auth; + auth.detach(); + QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(auth); + QVERIFY(priv->phase == QAuthenticatorPrivate::Start); + + QList > headers; + headers << qMakePair(QByteArray("WWW-Authenticate"), "Basic " + data.toUtf8()); + priv->parseHttpResponse(headers, /*isProxy = */ false); + + QCOMPARE(auth.realm(), realm); + QCOMPARE(auth.option("realm").toString(), realm); + + auth.setUser(user); + auth.setPassword(password); + + QVERIFY(priv->phase == QAuthenticatorPrivate::Start); + + QCOMPARE(priv->calculateResponse("GET", "/").constData(), ("Basic " + expectedReply).constData()); +} + +void tst_QAuthenticator::ntlmAuth_data() +{ + QTest::addColumn("data"); + QTest::addColumn("realm"); + + QTest::newRow("no-realm") << "TlRMTVNTUAACAAAAHAAcADAAAAAFAoEATFZ3OLRQADIAAAAAAAAAAJYAlgBMAAAAUQBUAC0AVABFAFMAVAAtAEQATwBNAEEASQBOAAIAHABRAFQALQBUAEUAUwBUAC0ARABPAE0AQQBJAE4AAQAcAFEAVAAtAFQARQBTAFQALQBTAEUAUgBWAEUAUgAEABYAcQB0AC0AdABlAHMAdAAtAG4AZQB0AAMANABxAHQALQB0AGUAcwB0AC0AcwBlAHIAdgBlAHIALgBxAHQALQB0AGUAcwB0AC0AbgBlAHQAAAAAAA==" << ""; + QTest::newRow("with-realm") << "TlRMTVNTUAACAAAADAAMADgAAAAFAoECWCZkccFFAzwAAAAAAAAAAL4AvgBEAAAABQLODgAAAA9NAEcARABOAE8ASwACAAwATQBHAEQATgBPAEsAAQAcAE4ATwBLAC0AQQBNAFMAUwBTAEYARQAtADAAMQAEACAAbQBnAGQAbgBvAGsALgBuAG8AawBpAGEALgBjAG8AbQADAD4AbgBvAGsALQBhAG0AcwBzAHMAZgBlAC0AMAAxAC4AbQBnAGQAbgBvAGsALgBuAG8AawBpAGEALgBjAG8AbQAFACAAbQBnAGQAbgBvAGsALgBuAG8AawBpAGEALgBjAG8AbQAAAAAA" << "NOE"; +} + +void tst_QAuthenticator::ntlmAuth() +{ + QFETCH(QString, data); + QFETCH(QString, realm); + + QAuthenticator auth; + auth.detach(); + QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(auth); + QVERIFY(priv->phase == QAuthenticatorPrivate::Start); + + QList > headers; + + // NTLM phase 1: negotiate + // This phase of NTLM contains no information, other than what we're willing to negotiate + // Current implementation uses flags: + // NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_REQUEST_TARGET + headers << qMakePair("WWW-Authenticate", "NTLM"); + priv->parseHttpResponse(headers, /*isProxy = */ false); + QCOMPARE(priv->calculateResponse("GET", "/").constData(), "NTLM TlRMTVNTUAABAAAABQIAAAAAAAAAAAAAAAAAAAAAAAA="); + + // NTLM phase 2: challenge + headers.clear(); + headers << qMakePair(QByteArray("WWW-Authenticate"), "NTLM " + data.toUtf8()); + priv->parseHttpResponse(headers, /*isProxy = */ false); + + QEXPECT_FAIL("with-realm", "NTLM authentication code doesn't extract the realm", Continue); + QCOMPARE(auth.realm(), realm); + + auth.setUser("unimportant"); + auth.setPassword("unimportant"); + + QVERIFY(!priv->calculateResponse("GET", "/").isEmpty()); +} + +QTEST_MAIN(tst_QAuthenticator); + +#include "tst_qauthenticator.moc" -- cgit v0.12 From 01978218333aab792e32d7c69bbaea849b3b8d15 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jul 2010 17:19:27 +0200 Subject: Autotest: reenable the NTLM proxy test on tst_QTcpSocket --- tests/auto/qtcpsocket/tst_qtcpsocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp index 31cae40..e3b2ca5 100644 --- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp @@ -275,7 +275,7 @@ void tst_QTcpSocket::initTestCase_data() QTest::newRow("WithHttpProxy") << true << int(HttpProxy) << false; QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic) << false; -// QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm) << false; + QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm) << false; #ifndef QT_NO_OPENSSL QTest::newRow("WithoutProxy SSL") << false << 0 << true; @@ -284,7 +284,7 @@ void tst_QTcpSocket::initTestCase_data() QTest::newRow("WithHttpProxy SSL") << true << int(HttpProxy) << true; QTest::newRow("WithHttpProxyBasicAuth SSL") << true << int(HttpProxy | AuthBasic) << true; -// QTest::newRow("WithHttpProxyNtlmAuth SSL") << true << int(HttpProxy | AuthNtlm) << true; + QTest::newRow("WithHttpProxyNtlmAuth SSL") << true << int(HttpProxy | AuthNtlm) << true; #endif } -- cgit v0.12 From b9c2853a0fd1876f30a410fe8dac5c477cef9d0e Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Thu, 15 Jul 2010 14:08:20 +0200 Subject: Add a testcase for QTBUG-11213 to prevent future regressions. Merge-request: 2427 Reviewed-by: Bradley T. Hughes --- tests/auto/quuid/quuid.pro | 9 ++-- tests/auto/quuid/test/test.pro | 29 ++++++++++ tests/auto/quuid/testProcessUniqueness/main.cpp | 62 ++++++++++++++++++++++ .../testProcessUniqueness.pro | 8 +++ tests/auto/quuid/tst_quuid.cpp | 29 ++++++++++ 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 tests/auto/quuid/test/test.pro create mode 100644 tests/auto/quuid/testProcessUniqueness/main.cpp create mode 100644 tests/auto/quuid/testProcessUniqueness/testProcessUniqueness.pro diff --git a/tests/auto/quuid/quuid.pro b/tests/auto/quuid/quuid.pro index f7608fa..25e2456 100644 --- a/tests/auto/quuid/quuid.pro +++ b/tests/auto/quuid/quuid.pro @@ -1,3 +1,6 @@ -load(qttest_p4) -QT = core -SOURCES += tst_quuid.cpp +TEMPLATE = subdirs + +SUBDIRS = testProcessUniqueness + +SUBDIRS += test + diff --git a/tests/auto/quuid/test/test.pro b/tests/auto/quuid/test/test.pro new file mode 100644 index 0000000..123aa50 --- /dev/null +++ b/tests/auto/quuid/test/test.pro @@ -0,0 +1,29 @@ +load(qttest_p4) + +QT = core +SOURCES += ../tst_quuid.cpp +TARGET = tst_quuid + +CONFIG(debug_and_release_target) { + CONFIG(debug, debug|release) { + DESTDIR = ../debug + } else { + DESTDIR = ../release + } +} else { + DESTDIR = .. +} + +wince* { + addFile_processUniqueness.sources = $$OUT_PWD/../testProcessUniqueness/testProcessUniqueness.exe + addFile_processUniqueness.path = testProcessUniqueness + + DEPLOYMENT += addFile_processUniqueness +} + +symbian { + binDep.sources = testProcessUniqueness.exe + binDep.path = \\sys\\bin + + DEPLOYMENT += binDep +} diff --git a/tests/auto/quuid/testProcessUniqueness/main.cpp b/tests/auto/quuid/testProcessUniqueness/main.cpp new file mode 100644 index 0000000..4d33c84 --- /dev/null +++ b/tests/auto/quuid/testProcessUniqueness/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +// This is a testcase for QTBUG-11213 +int main(int argc, char **argv) +{ + Q_UNUSED(argc) + Q_UNUSED(argv) + + // First, break QUuid. + qrand(); + + // Now print a few uuids. + printf("%s", qPrintable(QUuid::createUuid().toString())); + printf("%s", qPrintable(QUuid::createUuid().toString())); + printf("%s", qPrintable(QUuid::createUuid().toString())); + + // Done + return 0; +} + diff --git a/tests/auto/quuid/testProcessUniqueness/testProcessUniqueness.pro b/tests/auto/quuid/testProcessUniqueness/testProcessUniqueness.pro new file mode 100644 index 0000000..88df1a2 --- /dev/null +++ b/tests/auto/quuid/testProcessUniqueness/testProcessUniqueness.pro @@ -0,0 +1,8 @@ +SOURCES = main.cpp +CONFIG += console + +DESTDIR = ./ + +# no install rule for application used by test +INSTALLS = + diff --git a/tests/auto/quuid/tst_quuid.cpp b/tests/auto/quuid/tst_quuid.cpp index 47f356a..409d8cf 100644 --- a/tests/auto/quuid/tst_quuid.cpp +++ b/tests/auto/quuid/tst_quuid.cpp @@ -73,6 +73,7 @@ private slots: void versions(); void threadUniqueness(); + void processUniqueness(); public: // Variables @@ -196,5 +197,33 @@ void tst_QUuid::threadUniqueness() qDeleteAll(threads); } +void tst_QUuid::processUniqueness() +{ + QProcess process; + QString processOneOutput; + QString processTwoOutput; + + // Start it once +#ifdef Q_OS_MAC + process.start("testProcessUniqueness/testProcessUniqueness.app"); +#else + process.start("testProcessUniqueness/testProcessUniqueness"); +#endif + QVERIFY(process.waitForFinished()); + processOneOutput = process.readAllStandardOutput(); + + // Start it twice +#ifdef Q_OS_MAC + process.start("testProcessUniqueness/testProcessUniqueness.app"); +#else + process.start("testProcessUniqueness/testProcessUniqueness"); +#endif + QVERIFY(process.waitForFinished()); + processTwoOutput = process.readAllStandardOutput(); + + // They should be *different*! + QVERIFY(processOneOutput != processTwoOutput); +} + QTEST_MAIN(tst_QUuid) #include "tst_quuid.moc" -- cgit v0.12 From 1c34bf050da3c4d6c303e1dd1dad9eb99e7ccbf4 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 15 Jul 2010 14:56:54 +0200 Subject: QNAM HTTP: Fix problem with cached files and metaDataChanged() Reviewed-by: Peter Hartmann --- src/network/access/qnetworkaccesshttpbackend.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index a6c5c02..f617244 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -944,10 +944,10 @@ bool QNetworkAccessHttpBackend::sendCacheContents(const QNetworkCacheMetaData &m checkForRedirect(status); - emit metaDataChanged(); - - // invoke this asynchronously, else Arora/QtDemoBrowser don't like cached downloads - // see task 250221 / 251801 + // This needs to be emitted in the event loop because it can be reached at + // the direct code path of qnam.get(...) before the user has a chance + // to connect any signals. + QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); qRegisterMetaType("QIODevice*"); QMetaObject::invokeMethod(this, "writeDownstreamData", Qt::QueuedConnection, Q_ARG(QIODevice*, contents)); -- cgit v0.12 From 30630cf2bf8c7604efc3a52f74983c2237f309c3 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Thu, 15 Jul 2010 16:50:28 +0200 Subject: Unbreak the Maemo 5 build after the Symbian fix Reviewed-by: Robert Griebl --- tools/qml/qml.pri | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index fcd0c33..80afb45 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -17,16 +17,16 @@ SOURCES += $$PWD/qmlruntime.cpp \ $$PWD/loggerwidget.cpp RESOURCES = $$PWD/qmlruntime.qrc -maemo5 { +symbian:!contains(S60_VERSION, 3.1):!contains(S60_VERSION, 3.2) { + SOURCES += $$PWD/deviceorientation_symbian.cpp + FORMS = $$PWD/recopts.ui \ + $$PWD/proxysettings.ui +} else:maemo5 { QT += dbus HEADERS += $$PWD/texteditautoresizer_maemo5.h SOURCES += $$PWD/deviceorientation_maemo5.cpp FORMS = $$PWD/recopts_maemo5.ui \ $$PWD/proxysettings_maemo5.ui -} symbian:!contains(S60_VERSION, 3.1):!contains(S60_VERSION, 3.2) { - SOURCES += $$PWD/deviceorientation_symbian.cpp - FORMS = $$PWD/recopts.ui \ - $$PWD/proxysettings.ui } else { SOURCES += $$PWD/deviceorientation.cpp FORMS = $$PWD/recopts.ui \ -- cgit v0.12 From b863daec96868731412bd8f89b960bc7395911ae Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 13 Jul 2010 11:34:44 +0200 Subject: split qt_help out into an own ts target the combined target would be too hard to transform in the next commit --- translations/translations.pri | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/translations/translations.pri b/translations/translations.pri index f5e54ca..6a13dff 100644 --- a/translations/translations.pri +++ b/translations/translations.pri @@ -52,11 +52,15 @@ ts-linguist.depends = sub-tools ###### Assistant ts-assistant.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/assistant/tools/assistant/assistant.pro \ - && $$LUPDATE \ - ../tools/assistant/lib/lib.pro) + ../tools/assistant/tools/assistant/assistant.pro) ts-assistant.depends = sub-tools +###### Qt Help Lib + +ts-qt_help.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ + ../tools/assistant/lib/lib.pro) +ts-qt_help.depends = sub-tools + ###### Qtconfig ts-qtconfig.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ @@ -71,10 +75,10 @@ ts-qvfb.depends = sub-tools ###### Overall Rules -ts.depends = ts-qt ts-designer ts-linguist ts-assistant ts-qtconfig ts-qvfb +ts.depends = ts-qt ts-designer ts-linguist ts-assistant ts-qt_help ts-qtconfig ts-qvfb check-ts.commands = (cd $$PWD && perl check-ts.pl) check-ts.depends = ts -QMAKE_EXTRA_TARGETS += ts-qt ts-designer ts-linguist ts-assistant ts-qtconfig ts-qvfb \ +QMAKE_EXTRA_TARGETS += ts-qt ts-designer ts-linguist ts-assistant ts-qt_help ts-qtconfig ts-qvfb \ ts check-ts -- cgit v0.12 From 807bc3aca8a0b07ee1dfe1e398044d32756e5de0 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 13 Jul 2010 12:55:31 +0200 Subject: more fine-grained ts targets there are now per-language ts-- and ts- targets to update only the files relevant for a given language. there is also a ts-all target which does what the old ts target did. the ts- targets are now named ts--all and should not be used manually - they exist for the convenience of the ts-all target. the ts target is now only a help blurb. --- tools/assistant/lib/lib.pro | 13 --- tools/assistant/tools/assistant/assistant.pro | 13 --- tools/designer/designer.pro | 13 --- tools/linguist/linguist/linguist.pro | 12 --- tools/qtconfig/qtconfig.pro | 8 -- tools/qvfb/qvfb.pro | 8 -- translations/translations.pri | 132 +++++++++++--------------- 7 files changed, 56 insertions(+), 143 deletions(-) diff --git a/tools/assistant/lib/lib.pro b/tools/assistant/lib/lib.pro index e84cf31..26d3456 100644 --- a/tools/assistant/lib/lib.pro +++ b/tools/assistant/lib/lib.pro @@ -69,16 +69,3 @@ HEADERS += qhelpenginecore.h \ # access to clucene HEADERS += qhelpsearchindexwriter_clucene_p.h \ qhelpsearchindexreader_clucene_p.h - -TR_DIR = $$PWD/../../../translations -TRANSLATIONS = \ - $$TR_DIR/qt_help_cs.ts \ - $$TR_DIR/qt_help_da.ts \ - $$TR_DIR/qt_help_de.ts \ - $$TR_DIR/qt_help_hu.ts \ - $$TR_DIR/qt_help_ja.ts \ - $$TR_DIR/qt_help_pl.ts \ - $$TR_DIR/qt_help_ru.ts \ - $$TR_DIR/qt_help_zh_CN.ts \ - $$TR_DIR/qt_help_zh_TW.ts \ - $$TR_DIR/qt_help_fr.ts diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro index 16a520e..d9aff7a 100644 --- a/tools/assistant/tools/assistant/assistant.pro +++ b/tools/assistant/tools/assistant/assistant.pro @@ -108,16 +108,3 @@ contains(CONFIG, static): { DEFINES += USE_STATIC_SQLITE_PLUGIN } } - -TR_DIR = $$PWD/../../../../translations -TRANSLATIONS = \ - $$TR_DIR/assistant_cs.ts \ - $$TR_DIR/assistant_da.ts \ - $$TR_DIR/assistant_de.ts \ - $$TR_DIR/assistant_fr.ts \ - $$TR_DIR/assistant_hu.ts \ - $$TR_DIR/assistant_ja.ts \ - $$TR_DIR/assistant_pl.ts \ - $$TR_DIR/assistant_ru.ts \ - $$TR_DIR/assistant_zh_CN.ts \ - $$TR_DIR/assistant_zh_TW.ts diff --git a/tools/designer/designer.pro b/tools/designer/designer.pro index 31c8622..721c4fc 100644 --- a/tools/designer/designer.pro +++ b/tools/designer/designer.pro @@ -3,16 +3,3 @@ TEMPLATE = subdirs CONFIG += qt SUBDIRS = src - -TR_DIR = $$PWD/../../translations -TRANSLATIONS = \ - $$TR_DIR/designer_cs.ts \ - $$TR_DIR/designer_de.ts \ - $$TR_DIR/designer_fr.ts \ - $$TR_DIR/designer_hu.ts \ - $$TR_DIR/designer_ja.ts \ - $$TR_DIR/designer_pl.ts \ - $$TR_DIR/designer_ru.ts \ - $$TR_DIR/designer_sl.ts \ - $$TR_DIR/designer_zh_CN.ts \ - $$TR_DIR/designer_zh_TW.ts diff --git a/tools/linguist/linguist/linguist.pro b/tools/linguist/linguist/linguist.pro index 4f7ed8a..ce8d585 100644 --- a/tools/linguist/linguist/linguist.pro +++ b/tools/linguist/linguist/linguist.pro @@ -94,15 +94,3 @@ FORMS += statistics.ui \ translationsettings.ui \ finddialog.ui RESOURCES += linguist.qrc - -TR_DIR = $$PWD/../../../translations -TRANSLATIONS = \ - $$TR_DIR/linguist_cs.ts \ - $$TR_DIR/linguist_de.ts \ - $$TR_DIR/linguist_fr.ts \ - $$TR_DIR/linguist_hu.ts \ - $$TR_DIR/linguist_ja.ts \ - $$TR_DIR/linguist_pl.ts \ - $$TR_DIR/linguist_ru.ts \ - $$TR_DIR/linguist_zh_CN.ts \ - $$TR_DIR/linguist_zh_TW.ts diff --git a/tools/qtconfig/qtconfig.pro b/tools/qtconfig/qtconfig.pro index 3a24e85..d1fd320 100644 --- a/tools/qtconfig/qtconfig.pro +++ b/tools/qtconfig/qtconfig.pro @@ -29,11 +29,3 @@ target.path=$$[QT_INSTALL_BINS] INSTALLS += target INCLUDEPATH += . DBFILE = qtconfig.db - -TR_DIR = $$PWD/../../translations -TRANSLATIONS = \ - $$TR_DIR/qtconfig_hu.ts \ - $$TR_DIR/qtconfig_pl.ts \ - $$TR_DIR/qtconfig_ru.ts \ - $$TR_DIR/qtconfig_zh_CN.ts \ - $$TR_DIR/qtconfig_zh_TW.ts diff --git a/tools/qvfb/qvfb.pro b/tools/qvfb/qvfb.pro index df69817..c101d00 100644 --- a/tools/qvfb/qvfb.pro +++ b/tools/qvfb/qvfb.pro @@ -62,11 +62,3 @@ unix:x11 { } RESOURCES += qvfb.qrc - -TR_DIR = $$PWD/../../translations -TRANSLATIONS = \ - $$TR_DIR/qvfb_hu.ts \ - $$TR_DIR/qvfb_pl.ts \ - $$TR_DIR/qvfb_ru.ts \ - $$TR_DIR/qvfb_zh_CN.ts \ - $$TR_DIR/qvfb_zh_TW.ts diff --git a/translations/translations.pri b/translations/translations.pri index 6a13dff..b41f2a0 100644 --- a/translations/translations.pri +++ b/translations/translations.pri @@ -1,84 +1,64 @@ -defineReplace(prependAll) { - prepend = $$1 - arglist = $$2 - append = $$3 - for(a,arglist) { - result += $${prepend}$${a}$${append} - } - return ($$result) -} - qtPrepareTool(LUPDATE, lupdate) LUPDATE += -locations relative -no-ui-lines -###### Qt Libraries - -QT_TS = ar cs da de es fr he hu ja pl pt ru sk sl sv uk zh_CN zh_TW - -ts-qt.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - -I../include -I../include/Qt \ - 3rdparty/phonon \ - 3rdparty/webkit \ - activeqt \ - corelib \ - declarative \ - gui \ - multimedia \ - network \ - opengl \ - plugins \ - qt3support \ - script \ - scripttools \ - sql \ - svg \ - xml \ - xmlpatterns \ - -ts $$prependAll($$QT_SOURCE_TREE/translations/qt_,$$QT_TS,.ts)) -ts-qt.depends = sub-tools - -###### Designer - -ts-designer.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/designer/designer.pro) -ts-designer.depends = sub-tools - -###### Linguist - -ts-linguist.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/linguist/linguist/linguist.pro) -ts-linguist.depends = sub-tools - -###### Assistant - -ts-assistant.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/assistant/tools/assistant/assistant.pro) -ts-assistant.depends = sub-tools - -###### Qt Help Lib - -ts-qt_help.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/assistant/lib/lib.pro) -ts-qt_help.depends = sub-tools - -###### Qtconfig - -ts-qtconfig.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/qtconfig/qtconfig.pro) -ts-qtconfig.depends = sub-tools - -###### Qvfp - -ts-qvfb.commands = (cd $$QT_SOURCE_TREE/src && $$LUPDATE \ - ../tools/qvfb/qvfb.pro) -ts-qvfb.depends = sub-tools +TS_TARGETS = + +# meta target name, target name, lupdate base options, files +defineTest(addTsTarget) { + cv = $${2}.commands + dv = $${2}.depends + $$cv = cd $$QT_SOURCE_TREE/src && $$LUPDATE $$3 -ts $$4 + $$dv = sub-tools + export($$cv) + export($$dv) + dv = $${1}.depends + $$dv += $$2 + export($$dv) + TS_TARGETS += $$1 $$2 + export(TS_TARGETS) +} -###### Overall Rules +# target basename, lupdate base options +defineTest(addTsTargets) { + files = $$files($$PWD/$${1}_??.ts) $$files($$PWD/$${1}_??_??.ts) + for(file, files) { + lang = $$replace(file, .*_((.._)?..)\\.ts$, \\1) + addTsTarget(ts-$$lang, ts-$$1-$$lang, $$2, $$file) + } + addTsTarget(ts-all, ts-$$1-all, $$2, $$files) +} -ts.depends = ts-qt ts-designer ts-linguist ts-assistant ts-qt_help ts-qtconfig ts-qvfb +addTsTargets(qt, -I../include -I../include/Qt \ + 3rdparty/phonon \ + 3rdparty/webkit \ + activeqt \ + corelib \ + declarative \ + gui \ + multimedia \ + network \ + opengl \ + plugins \ + qt3support \ + script \ + scripttools \ + sql \ + svg \ + xml \ + xmlpatterns \ +) +addTsTargets(designer, ../tools/designer/designer.pro) +addTsTargets(linguist, ../tools/linguist/linguist/linguist.pro) +addTsTargets(assistant, ../tools/assistant/tools/assistant/assistant.pro) +addTsTargets(qt_help, ../tools/assistant/lib/lib.pro) +addTsTargets(qtconfig, ../tools/qtconfig/qtconfig.pro) +addTsTargets(qvfb, ../tools/qvfb/qvfb.pro) check-ts.commands = (cd $$PWD && perl check-ts.pl) -check-ts.depends = ts +check-ts.depends = ts-all + +ts.commands = \ + @echo \"The \'ts\' target has been removed in favor of more fine-grained targets.\" && \ + echo \"Use \'ts--\' or \'ts-\' instead.\" -QMAKE_EXTRA_TARGETS += ts-qt ts-designer ts-linguist ts-assistant ts-qt_help ts-qtconfig ts-qvfb \ - ts check-ts +QMAKE_EXTRA_TARGETS += $$unique(TS_TARGETS) ts check-ts -- cgit v0.12 From 511a838afdb1d028bf184bb56c9ead39312987ca Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 13 Jul 2010 12:57:07 +0200 Subject: (re-)add 'untranslated' ts targets these files are not meant for commit, but it's good to have a quick way to create templates. --- .gitignore | 1 + translations/check-ts.pl | 2 +- translations/translations.pri | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fdb6843..4d5aa9b 100644 --- a/.gitignore +++ b/.gitignore @@ -114,6 +114,7 @@ tools/qtestlib/chart/chart* tools/qtestlib/updater/updater* tools/activeqt/testcon/testcon.tlb translations/*.qm +translations/*_untranslated.ts qrc_*.cpp # xemacs temporary files diff --git a/translations/check-ts.pl b/translations/check-ts.pl index 5f38703..0ff9d17 100755 --- a/translations/check-ts.pl +++ b/translations/check-ts.pl @@ -49,7 +49,7 @@ my @groups = ("assistant", "designer", "linguist", "qt_help", "qtconfig", "qvfb" my %scores = (); my %langs = (); -my $files = join("\n", <*.ts>); +my $files = join("\n", <*_??.ts>); my $res = `xmlpatterns -param files=\"$files\" check-ts.xq`; for my $i (split(/ /, $res)) { $i =~ /^([^.]+).ts:(.*)$/; diff --git a/translations/translations.pri b/translations/translations.pri index b41f2a0..735411e 100644 --- a/translations/translations.pri +++ b/translations/translations.pri @@ -25,7 +25,8 @@ defineTest(addTsTargets) { lang = $$replace(file, .*_((.._)?..)\\.ts$, \\1) addTsTarget(ts-$$lang, ts-$$1-$$lang, $$2, $$file) } - addTsTarget(ts-all, ts-$$1-all, $$2, $$files) + addTsTarget(ts-untranslated, ts-$$1-untranslated, $$2, $$PWD/$${1}_untranslated.ts) + addTsTarget(ts-all, ts-$$1-all, $$2, $$PWD/$${1}_untranslated.ts $$files) } addTsTargets(qt, -I../include -I../include/Qt \ @@ -59,6 +60,7 @@ check-ts.depends = ts-all ts.commands = \ @echo \"The \'ts\' target has been removed in favor of more fine-grained targets.\" && \ - echo \"Use \'ts--\' or \'ts-\' instead.\" + echo \"Use \'ts--\' or \'ts-\' instead. To add a language,\" && \ + echo \"use \'untranslated\' for , rename the files and re-run \'qmake\'.\" QMAKE_EXTRA_TARGETS += $$unique(TS_TARGETS) ts check-ts -- cgit v0.12 From 468eb186427067549191f3b921c9f9d75a6947ef Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 13 Jul 2010 20:39:37 +0200 Subject: add commit-ts target to commit ts files without line number info it is pretty pointless to commit the extracted line number information, as it needs to be refreshed after pulling source code changes anyway. on top of it, it bloats the repository. --- translations/translations.pri | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/translations/translations.pri b/translations/translations.pri index 735411e..c27e955 100644 --- a/translations/translations.pri +++ b/translations/translations.pri @@ -1,3 +1,4 @@ +qtPrepareTool(LCONVERT, lconvert) qtPrepareTool(LUPDATE, lupdate) LUPDATE += -locations relative -no-ui-lines @@ -58,9 +59,25 @@ addTsTargets(qvfb, ../tools/qvfb/qvfb.pro) check-ts.commands = (cd $$PWD && perl check-ts.pl) check-ts.depends = ts-all +isEqual(QMAKE_DIR_SEP, /) { + commit-ts.commands = \ + cd $$PWD/..; \ + for f in `git diff-files --name-only translations/*_??.ts`; do \ + $$LCONVERT -locations none -i \$\$f -o \$\$f; \ + done; \ + git add translations/*_??.ts && git commit +} else { + wd = $$replace(PWD, /, \\)\\.. + commit-ts.commands = \ + cd $$wd && \ + for /f usebackq %%f in (`git diff-files --name-only translations/*_??.ts`) do \ + $$LCONVERT -locations none -i %%f -o %%f $$escape_expand(\\n\\t) \ + cd $$wd && git add translations/*_??.ts && git commit +} + ts.commands = \ @echo \"The \'ts\' target has been removed in favor of more fine-grained targets.\" && \ echo \"Use \'ts--\' or \'ts-\' instead. To add a language,\" && \ echo \"use \'untranslated\' for , rename the files and re-run \'qmake\'.\" -QMAKE_EXTRA_TARGETS += $$unique(TS_TARGETS) ts check-ts +QMAKE_EXTRA_TARGETS += $$unique(TS_TARGETS) ts commit-ts check-ts -- cgit v0.12 From 63f1fc5e7aac3b9b088b90577a2c5208be571183 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 14 Jul 2010 11:21:11 +0200 Subject: remove dependency of ts targets on sub-tools it is pretty pointless, really. these are manual targets, so if they fail because of missing tools, the user can just make sub-tools manually. way better than wasting time waiting for make to run through the whole qt tree each time. --- translations/translations.pri | 3 --- 1 file changed, 3 deletions(-) diff --git a/translations/translations.pri b/translations/translations.pri index c27e955..fbc1596 100644 --- a/translations/translations.pri +++ b/translations/translations.pri @@ -7,11 +7,8 @@ TS_TARGETS = # meta target name, target name, lupdate base options, files defineTest(addTsTarget) { cv = $${2}.commands - dv = $${2}.depends $$cv = cd $$QT_SOURCE_TREE/src && $$LUPDATE $$3 -ts $$4 - $$dv = sub-tools export($$cv) - export($$dv) dv = $${1}.depends $$dv += $$2 export($$dv) -- cgit v0.12 From 4fc1008163907459d921c4089512268495245976 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 15 Jul 2010 18:42:28 +0200 Subject: cosmetics: quote the dot in the regexp --- translations/check-ts.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translations/check-ts.pl b/translations/check-ts.pl index 0ff9d17..500be15 100755 --- a/translations/check-ts.pl +++ b/translations/check-ts.pl @@ -52,7 +52,7 @@ my %langs = (); my $files = join("\n", <*_??.ts>); my $res = `xmlpatterns -param files=\"$files\" check-ts.xq`; for my $i (split(/ /, $res)) { - $i =~ /^([^.]+).ts:(.*)$/; + $i =~ /^([^.]+)\.ts:(.*)$/; my ($fn, $pc) = ($1, $2); for my $g (@groups) { if ($fn =~ /^${g}_(.*)$/) { -- cgit v0.12 From 40d2b2e30a526b46b17072ba8bdc38f30cd3c624 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 15 Jul 2010 18:44:18 +0200 Subject: remove nasty hack by using a stricter regexp (for language codes) --- translations/check-ts.pl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/translations/check-ts.pl b/translations/check-ts.pl index 500be15..067cad8 100755 --- a/translations/check-ts.pl +++ b/translations/check-ts.pl @@ -43,8 +43,7 @@ use strict; -# "qt" must come last to avoid prefix matching. -my @groups = ("assistant", "designer", "linguist", "qt_help", "qtconfig", "qvfb", "qt"); +my @groups = ("qt", "assistant", "designer", "linguist", "qt_help", "qtconfig", "qvfb"); my %scores = (); my %langs = (); @@ -55,7 +54,7 @@ for my $i (split(/ /, $res)) { $i =~ /^([^.]+)\.ts:(.*)$/; my ($fn, $pc) = ($1, $2); for my $g (@groups) { - if ($fn =~ /^${g}_(.*)$/) { + if ($fn =~ /^${g}_((.._)?..)$/) { my $lang = $1; $scores{$g}{$lang} = $pc; $langs{$lang} = 1; @@ -64,10 +63,6 @@ for my $i (split(/ /, $res)) { } } -# now we move "qt" to the front, as it should be the first column. -pop @groups; -unshift @groups, "qt"; - my $code = ""; print "L10n "; -- cgit v0.12 From 062a504010534d5e899f042b27c8ace82b556426 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Fri, 16 Jul 2010 09:56:19 +1000 Subject: Fixed tst_maketestselftest::tests_pro_files failure Add qauthenticator to tests/auto/network.pro --- tests/auto/network.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/network.pro b/tests/auto/network.pro index 4f205fe..e1898f1 100644 --- a/tests/auto/network.pro +++ b/tests/auto/network.pro @@ -7,6 +7,7 @@ SUBDIRS=\ networkselftest \ qabstractnetworkcache \ qabstractsocket \ + qauthenticator \ qeventloop \ qftp \ qhostaddress \ @@ -36,6 +37,7 @@ SUBDIRS=\ qsslsocket \ contains(QT_CONFIG, private_tests): SUBDIRS -= \ + qauthenticator \ qhttpnetworkconnection \ qhttpnetworkreply \ qnativesocketengine \ -- cgit v0.12