summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeir Vattekar <geir.vattekar@trolltech.com>2009-06-18 12:05:24 (GMT)
committerGeir Vattekar <geir.vattekar@trolltech.com>2009-06-18 12:05:24 (GMT)
commitf41887f827cb5011ffb2215d70679b9421745c94 (patch)
tree80aeb94e1bd72ce758fc91479a3858ca66bbe17c /src
parent2114754f8f86e0b653b6057d9b46a30f97d51aef (diff)
parentc23d4d6644bff2195fbb6aa84d3425dc2d31491a (diff)
downloadQt-f41887f827cb5011ffb2215d70679b9421745c94.zip
Qt-f41887f827cb5011ffb2215d70679b9421745c94.tar.gz
Qt-f41887f827cb5011ffb2215d70679b9421745c94.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstring.cpp68
-rw-r--r--src/corelib/tools/qstringbuilder.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h8
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp18
-rw-r--r--src/gui/itemviews/qlistview.cpp2
-rw-r--r--src/gui/widgets/qmenubar.cpp3
-rw-r--r--src/opengl/qpaintengine_opengl.cpp23
-rw-r--r--src/opengl/qpaintengine_opengl_p.h1
8 files changed, 111 insertions, 14 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index ced6dd5..3b70f44 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -663,6 +663,74 @@ const QString::Null QString::null = { };
formats, the \e precision represents the maximum number of
significant digits (trailing zeroes are omitted).
+ \section1 More Efficient String Construction
+
+ Using the QString \c{'+'} operator, it is easy to construct a
+ complex string from multiple substrings. You will often write code
+ like this:
+
+ \snippet doc/src/snippets/qstring/stringbuilder.cpp 0
+
+ There is nothing wrong with either of these string constructions,
+ but there are a few hidden inefficiencies. Beginning with Qt 4.6,
+ you can eliminate them.
+
+ First, multiple uses of the \c{'+'} operator usually means
+ multiple memory allocations. When concatenating \e{n} substrings,
+ where \e{n > 2}, there can be as many as \e{n - 1} calls to the
+ memory allocator.
+
+ Second, QLatin1String does not store its length internally but
+ calls qstrlen() when it needs to know its length.
+
+ In 4.6, an internal template class \c{QStringBuilder} has been
+ added along with a few helper functions. This class is marked
+ internal and does not appear in the documentation, because you
+ aren't meant to instantiate it in your code. Its use will be
+ automatic, as described below. The class is found in
+ \c {src/corelib/tools/qstringbuilder.cpp} if you want to have a
+ look at it.
+
+ \c{QStringBuilder} uses expression templates and reimplements the
+ \c{'%'} operator so that when you use \c{'%'} for string
+ concatenation instead of \c{'+'}, multiple substring
+ concatenations will be postponed until the final result is about
+ to be assigned to a QString. At this point, the amount of memory
+ required for the final result is known. The memory allocator is
+ then called \e{once} to get the required space, and the substrings
+ are copied into it one by one.
+
+ \c{QLatin1Literal} is a second internal class that can replace
+ QLatin1String, which can't be changed for compatibility reasons.
+ \c{QLatin1Literal} stores its length, thereby saving time when
+ \c{QStringBuilder} computes the amount of memory required for the
+ final string.
+
+ Additional efficiency is gained by inlining and reduced reference
+ counting (the QString created from a \c{QStringBuilder} typically
+ has a ref count of 1, whereas QString::append() needs an extra
+ test).
+
+ There are three ways you can access this improved method of string
+ construction. The straightforward way is to include
+ \c{QStringBuilder} wherever you want to use it, and use the
+ \c{'%'} operator instead of \c{'+'} when concatenating strings:
+
+ \snippet doc/src/snippets/qstring/stringbuilder.cpp 5
+
+ A more global approach is to include this define:
+
+ \snippet doc/src/snippets/qstring/stringbuilder.cpp 3
+
+ and use \c{'%'} instead of \c{'+'} for string concatenation
+ everywhere. The third approach, which is the most convenient but
+ not entirely source compatible, is to include two defines:
+
+ \snippet doc/src/snippets/qstring/stringbuilder.cpp 4
+
+ and the \c{'+'} will automatically be performed as the
+ \c{QStringBuilder} \c{'%'} everywhere.
+
\sa fromRawData(), QChar, QLatin1String, QByteArray, QStringRef
*/
diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp
index 17e2cec..fbb784e 100644
--- a/src/corelib/tools/qstringbuilder.cpp
+++ b/src/corelib/tools/qstringbuilder.cpp
@@ -43,6 +43,7 @@
/*!
\class QLatin1Literal
+ \internal
\reentrant
\since 4.6
@@ -83,6 +84,7 @@
/*!
\class QStringBuilder
+ \internal
\reentrant
\since 4.6
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index b7fb122..b9e7041 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -366,14 +366,6 @@ public:
|| (childrenCombineOpacity() && isFullyTransparent());
}
- inline bool updateHelper(QGraphicsViewPrivate *view, const QRectF &rect, const QTransform &xform) const
- {
- Q_ASSERT(view);
- if (hasBoundingRegionGranularity)
- return view->updateRegion(xform.map(QRegion(rect.toRect())));
- return view->updateRect(xform.mapRect(rect).toRect());
- }
-
inline QTransform transformToParent() const;
QPainterPath cachedClipPath;
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 71a4f08..d9d31ef 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -5306,6 +5306,16 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b
}
}
+static inline bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item,
+ const QRectF &rect, const QTransform &xform)
+{
+ Q_ASSERT(view);
+ Q_ASSERT(item);
+ if (item->hasBoundingRegionGranularity)
+ return view->updateRegion(xform.map(QRegion(rect.toRect())));
+ return view->updateRect(xform.mapRect(rect).toRect());
+}
+
void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren,
qreal parentOpacity)
{
@@ -5401,14 +5411,14 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
bool valid = false;
if (untransformableItem) {
- valid = item->d_ptr->updateHelper(viewPrivate, dirtyRect,
- item->deviceTransform(view->viewportTransform()));
+ valid = updateHelper(viewPrivate, item->d_ptr, dirtyRect,
+ item->deviceTransform(view->viewportTransform()));
} else if (!view->isTransformed()) {
- valid = item->d_ptr->updateHelper(viewPrivate, dirtyRect, item->d_ptr->sceneTransform);
+ valid = updateHelper(viewPrivate, item->d_ptr, dirtyRect, item->d_ptr->sceneTransform);
} else {
QTransform deviceTransform = item->d_ptr->sceneTransform;
deviceTransform *= view->viewportTransform();
- valid = !item->d_ptr->updateHelper(viewPrivate, dirtyRect, deviceTransform);
+ valid = updateHelper(viewPrivate, item->d_ptr, dirtyRect, deviceTransform);
}
if (!valid)
paintedViewBoundingRect = QRect();
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 9b25730..f1b0d19 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -827,6 +827,8 @@ void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e
*/
void QListView::mouseMoveEvent(QMouseEvent *e)
{
+ if (!isVisible())
+ return;
Q_D(QListView);
QAbstractItemView::mouseMoveEvent(e);
if (state() == DragSelectingState
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index 3857e30..34de252 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -1253,7 +1253,8 @@ void QMenuBar::mouseMoveEvent(QMouseEvent *e)
void QMenuBar::leaveEvent(QEvent *)
{
Q_D(QMenuBar);
- if(!hasFocus() && !d->popupState)
+ if((!hasFocus() && !d->popupState) ||
+ (d->currentAction && d->currentAction->menu() == 0))
d->setCurrentAction(0);
}
diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index 84ad4d5..b594f5b 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -662,6 +662,7 @@ public:
, txop(QTransform::TxNone)
, inverseScale(1)
, moveToCount(0)
+ , last_created_state(0)
, shader_ctx(0)
, grad_palette(0)
, drawable_texture(0)
@@ -788,6 +789,8 @@ public:
void updateGLMatrix() const;
+ mutable QPainterState *last_created_state;
+
QGLContext *shader_ctx;
GLuint grad_palette;
@@ -2219,6 +2222,8 @@ void QOpenGLPaintEnginePrivate::updateDepthClip()
{
Q_Q(QOpenGLPaintEngine);
+ ++q->state()->depthClipId;
+
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
@@ -5501,9 +5506,20 @@ void QOpenGLPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
void QOpenGLPaintEngine::setState(QPainterState *s)
{
Q_D(QOpenGLPaintEngine);
+ QOpenGLPaintEngineState *new_state = static_cast<QOpenGLPaintEngineState *>(s);
+ QOpenGLPaintEngineState *old_state = state();
+
QPaintEngineEx::setState(s);
+
+ // are we in a save() ?
+ if (s == d->last_created_state) {
+ d->last_created_state = 0;
+ return;
+ }
+
if (isActive()) {
- d->updateDepthClip();
+ if (old_state->depthClipId != new_state->depthClipId)
+ d->updateDepthClip();
penChanged();
brushChanged();
opacityChanged();
@@ -5515,12 +5531,15 @@ void QOpenGLPaintEngine::setState(QPainterState *s)
QPainterState *QOpenGLPaintEngine::createState(QPainterState *orig) const
{
+ const Q_D(QOpenGLPaintEngine);
+
QOpenGLPaintEngineState *s;
if (!orig)
s = new QOpenGLPaintEngineState();
else
s = new QOpenGLPaintEngineState(*static_cast<QOpenGLPaintEngineState *>(orig));
+ d->last_created_state = s;
return s;
}
@@ -5534,11 +5553,13 @@ QOpenGLPaintEngineState::QOpenGLPaintEngineState(QOpenGLPaintEngineState &other)
clipRegion = other.clipRegion;
hasClipping = other.hasClipping;
fastClip = other.fastClip;
+ depthClipId = other.depthClipId;
}
QOpenGLPaintEngineState::QOpenGLPaintEngineState()
{
hasClipping = false;
+ depthClipId = 0;
}
QOpenGLPaintEngineState::~QOpenGLPaintEngineState()
diff --git a/src/opengl/qpaintengine_opengl_p.h b/src/opengl/qpaintengine_opengl_p.h
index 891cbd6..439782b 100644
--- a/src/opengl/qpaintengine_opengl_p.h
+++ b/src/opengl/qpaintengine_opengl_p.h
@@ -69,6 +69,7 @@ public:
QRegion clipRegion;
bool hasClipping;
QRect fastClip;
+ uint depthClipId;
};
class QOpenGLPaintEngine : public QPaintEngineEx