Show the right version states for expanded items.

BUG: 267171
FIXED-IN: 4.11.3
REVIEW: 112980
This commit is contained in:
Emmanuel Pescosta 2013-09-29 18:08:06 +02:00
parent befa646f8f
commit bbbfeb28c5
4 changed files with 85 additions and 36 deletions

View file

@ -24,7 +24,7 @@
#include <QMutexLocker>
UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin,
const QList<VersionControlObserver::ItemState>& itemStates) :
const QMap<QString, QVector<VersionControlObserver::ItemState> >& itemStates) :
QThread(),
m_globalPluginMutex(0),
m_plugin(plugin),
@ -47,27 +47,29 @@ void UpdateItemStatesThread::run()
Q_ASSERT(!m_itemStates.isEmpty());
Q_ASSERT(m_plugin);
const QString directory = m_itemStates.first().item.url().directory(KUrl::AppendTrailingSlash);
m_retrievedItems = false;
QMutexLocker pluginLocker(m_globalPluginMutex);
if (m_plugin->beginRetrieval(directory)) {
const int count = m_itemStates.count();
foreach (const QString& directory, m_itemStates.keys()) {
if (m_plugin->beginRetrieval(directory)) {
QVector<VersionControlObserver::ItemState>& items = m_itemStates[directory];
const int count = items.count();
KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
if (pluginV2) {
for (int i = 0; i < count; ++i) {
m_itemStates[i].version = pluginV2->itemVersion(m_itemStates[i].item);
}
} else {
for (int i = 0; i < count; ++i) {
const KVersionControlPlugin::VersionState state = m_plugin->versionState(m_itemStates[i].item);
m_itemStates[i].version = static_cast<KVersionControlPlugin2::ItemVersion>(state);
KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
if (pluginV2) {
for (int i = 0; i < count; ++i) {
items[i].version = pluginV2->itemVersion(items[i].item);
}
} else {
for (int i = 0; i < count; ++i) {
const KVersionControlPlugin::VersionState state = m_plugin->versionState(items[i].item);
items[i].version = static_cast<KVersionControlPlugin2::ItemVersion>(state);
}
}
m_plugin->endRetrieval();
m_retrievedItems = true;
}
m_plugin->endRetrieval();
m_retrievedItems = true;
}
}
@ -81,7 +83,7 @@ void UpdateItemStatesThread::unlockPlugin()
m_globalPluginMutex->unlock();
}
QList<VersionControlObserver::ItemState> UpdateItemStatesThread::itemStates() const
QMap<QString, QVector<VersionControlObserver::ItemState> > UpdateItemStatesThread::itemStates() const
{
return m_itemStates;
}

View file

@ -47,7 +47,7 @@ public:
* @param itemStates List of items, where the states get updated.
*/
UpdateItemStatesThread(KVersionControlPlugin* plugin,
const QList<VersionControlObserver::ItemState>& itemStates);
const QMap<QString, QVector<VersionControlObserver::ItemState> >& itemStates);
virtual ~UpdateItemStatesThread();
/**
@ -63,7 +63,7 @@ public:
*/
void unlockPlugin();
QList<VersionControlObserver::ItemState> itemStates() const;
QMap<QString, QVector<VersionControlObserver::ItemState> > itemStates() const;
bool retrievedItems() const;
@ -75,7 +75,7 @@ private:
KVersionControlPlugin* m_plugin;
bool m_retrievedItems;
QList<VersionControlObserver::ItemState> m_itemStates;
QMap<QString, QVector<VersionControlObserver::ItemState> > m_itemStates;
};
#endif // UPDATEITEMSTATESTHREAD_H

View file

@ -204,11 +204,15 @@ void VersionControlObserver::slotThreadFinished()
return;
}
const QList<ItemState> itemStates = thread->itemStates();
foreach (const ItemState& itemState, itemStates) {
QHash<QByteArray, QVariant> values;
values.insert("version", QVariant(itemState.version));
m_model->setData(itemState.index, values);
const QMap<QString, QVector<ItemState> >& itemStates = thread->itemStates();
foreach (const QString& directory, itemStates.keys()) {
const QVector<ItemState>& items = itemStates.value(directory);
foreach (const ItemState& item, items) {
QHash<QByteArray, QVariant> values;
values.insert("version", QVariant(item.version));
m_model->setData(item.index, values);
}
}
if (!m_silentUpdate) {
@ -233,18 +237,9 @@ void VersionControlObserver::updateItemStates()
m_pendingItemStatesUpdate = true;
return;
}
QList<ItemState> itemStates;
const int itemCount = m_model->count();
itemStates.reserve(itemCount);
for (int i = 0; i < itemCount; ++i) {
ItemState itemState;
itemState.index = i;
itemState.item = m_model->fileItem(i);
itemState.version = KVersionControlPlugin2::UnversionedVersion;
itemStates.append(itemState);
}
QMap<QString, QVector<ItemState> > itemStates;
createItemStatesList(itemStates);
if (!itemStates.isEmpty()) {
if (!m_silentUpdate) {
@ -260,6 +255,42 @@ void VersionControlObserver::updateItemStates()
}
}
int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState> >& itemStates,
const int firstIndex)
{
const int itemCount = m_model->count();
const int currentExpansionLevel = m_model->expandedParentsCount(firstIndex);
QVector<ItemState> items;
items.reserve(itemCount - firstIndex);
int index;
for (index = firstIndex; index < itemCount; ++index) {
const int expansionLevel = m_model->expandedParentsCount(index);
if (expansionLevel == currentExpansionLevel) {
ItemState itemState;
itemState.index = index;
itemState.item = m_model->fileItem(index);
itemState.version = KVersionControlPlugin2::UnversionedVersion;
items.append(itemState);
} else if (expansionLevel > currentExpansionLevel) {
// Sub folder
index += createItemStatesList(itemStates, index) - 1;
} else {
break;
}
}
if (items.count() > 0) {
const KUrl& url = items.first().item.url();
itemStates.insert(url.directory(KUrl::AppendTrailingSlash), items);
}
return index - firstIndex; // number of processed items
}
KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& directory) const
{
static bool pluginsAvailable = true;

View file

@ -109,6 +109,22 @@ private:
void updateItemStates();
/**
* It creates a item state list for every expanded directory and stores
* this list together with the directory url in the \a itemStates map.
*
* @itemStates A map of item state lists for every expanded directory
* and its items, where the "key" is the directory url and
* the "value" is a list of ItemStates for every item
* within this directory.
* @firstIndex The index to start the processing from, this is needed
* because this function is recursively called.
*
* @return The number of (recursive) processed items.
*/
int createItemStatesList(QMap<QString, QVector<ItemState> >& itemStates,
const int firstIndex = 0);
/**
* Returns a matching plugin for the given directory.
* 0 is returned, if no matching plugin has been found.