summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2014-09-26 12:15:59 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2014-10-07 11:27:20 +0200
commit3ab084b95d7b6f751473e43b4641e3b5deda2dfa (patch)
tree855e3d81d2432d4273b6cb1fe4d27a79c18b96de
parente83a2e0fa6f428223445defbd4730a39b4d6df7f (diff)
Make sure the content widget never replaces valid data with empty data.
This could happen because insertContents() is called once for every run of the content provider, even if an invalidation happens in between. Example sequence: run() invalidate() [removes result of first run] run() insertContents() [queued for first run, retrieves result of second run] insertContents() [queued for second run, retrieves empty data] We now check in insertContents() whether the content provider has a valid root item and do nothing if it does not. This means that insertContents() will never replace the current model data with empty data; only invalidateContents() can do that from now on. Further improvements: - Only call insertContents() if the run was not aborted; this reduces the number of useless objects in the event queue. - Remove the m_rootItem member; it was only used in the run() function. - Only add the root item to the list at the end of a successful run; there is no reason this object should be accessible from the outside while there are still children being added to it. Change-Id: I80e2ea93dd9bbc8ab7f406c989b61f16f11b6eea Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
-rw-r--r--tools/assistant/lib/qhelpcontentwidget.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/assistant/lib/qhelpcontentwidget.cpp b/tools/assistant/lib/qhelpcontentwidget.cpp
index 8697cdfc4f..ff599f8e21 100644
--- a/tools/assistant/lib/qhelpcontentwidget.cpp
+++ b/tools/assistant/lib/qhelpcontentwidget.cpp
@@ -72,6 +72,7 @@ public:
class QHelpContentProvider : public QThread
{
+ Q_OBJECT
public:
QHelpContentProvider(QHelpEnginePrivate *helpEngine);
~QHelpContentProvider();
@@ -80,11 +81,13 @@ public:
QHelpContentItem *rootItem();
int nextChildCount() const;
+signals:
+ void finishedSuccessFully();
+
private:
void run();
QHelpEnginePrivate *m_helpEngine;
- QHelpContentItem *m_rootItem;
QStringList m_filterAttributes;
QQueue<QHelpContentItem*> m_rootItems;
QMutex m_mutex;
@@ -195,7 +198,6 @@ QHelpContentProvider::QHelpContentProvider(QHelpEnginePrivate *helpEngine)
: QThread(helpEngine)
{
m_helpEngine = helpEngine;
- m_rootItem = 0;
m_abort = false;
}
@@ -252,8 +254,7 @@ void QHelpContentProvider::run()
QHelpContentItem *item = 0;
m_mutex.lock();
- m_rootItem = new QHelpContentItem(QString(), QString(), 0);
- m_rootItems.enqueue(m_rootItem);
+ QHelpContentItem * const rootItem = new QHelpContentItem(QString(), QString(), 0);
QStringList atts = m_filterAttributes;
const QStringList fileNames = m_helpEngine->orderedFileNameList;
m_mutex.unlock();
@@ -261,9 +262,10 @@ void QHelpContentProvider::run()
foreach (const QString &dbFileName, fileNames) {
m_mutex.lock();
if (m_abort) {
+ delete rootItem;
m_abort = false;
m_mutex.unlock();
- break;
+ return;
}
m_mutex.unlock();
QHelpDBReader reader(dbFileName,
@@ -291,8 +293,8 @@ CHECK_DEPTH:
if (depth == 0) {
m_mutex.lock();
item = new QHelpContentItem(title, link,
- m_helpEngine->fileNameReaderMap.value(dbFileName), m_rootItem);
- m_rootItem->appendChild(item);
+ m_helpEngine->fileNameReaderMap.value(dbFileName), rootItem);
+ rootItem->appendChild(item);
m_mutex.unlock();
stack.push(item);
_depth = 1;
@@ -316,8 +318,10 @@ CHECK_DEPTH:
}
}
m_mutex.lock();
+ m_rootItems.enqueue(rootItem);
m_abort = false;
m_mutex.unlock();
+ emit finishedSuccessFully();
}
@@ -352,7 +356,7 @@ QHelpContentModel::QHelpContentModel(QHelpEnginePrivate *helpEngine)
d->rootItem = 0;
d->qhelpContentProvider = new QHelpContentProvider(helpEngine);
- connect(d->qhelpContentProvider, SIGNAL(finished()),
+ connect(d->qhelpContentProvider, SIGNAL(finishedSuccessFully()),
this, SLOT(insertContents()), Qt::QueuedConnection);
connect(helpEngine->q, SIGNAL(readersAboutToBeInvalidated()), this, SLOT(invalidateContents()));
}
@@ -391,6 +395,9 @@ void QHelpContentModel::createContents(const QString &customFilterName)
void QHelpContentModel::insertContents()
{
+ QHelpContentItem * const newRootItem = d->qhelpContentProvider->rootItem();
+ if (!newRootItem)
+ return;
int count;
if (d->rootItem) {
count = d->rootItem->childCount() - 1;
@@ -402,7 +409,7 @@ void QHelpContentModel::insertContents()
count = d->qhelpContentProvider->nextChildCount() - 1;
beginInsertRows(QModelIndex(), 0, count > 0 ? count : 0);
- d->rootItem = d->qhelpContentProvider->rootItem();
+ d->rootItem = newRootItem;
endInsertRows();
reset();
emit contentsCreated();
@@ -589,3 +596,5 @@ void QHelpContentWidget::showLink(const QModelIndex &index)
}
QT_END_NAMESPACE
+
+#include "qhelpcontentwidget.moc"