(qt) #5252 'file-renaming issues in Qt client': fix renaming flicker error reported by rb07

This commit is contained in:
Jordan Lee 2013-02-01 22:40:08 +00:00
parent e12890e78e
commit bb0bdc6f7e
2 changed files with 23 additions and 21 deletions

View File

@ -10,6 +10,7 @@
* $Id$
*/
#include <algorithm>
#include <cassert>
#include <QApplication>
@ -187,14 +188,15 @@ FileTreeItem :: fileSizeName () const
#include <iostream>
bool
std::pair<int,int>
FileTreeItem :: update (const QString& name,
bool wanted,
int priority,
uint64_t haveSize,
bool updateFields)
{
bool changed = false;
int changed_count = 0;
int changed_fields[3];
if (myName != name)
{
@ -202,33 +204,38 @@ FileTreeItem :: update (const QString& name,
myParent->myFirstUnhashedRow = row();
myName = name;
changed = true;
changed_fields[changed_count++] = COL_NAME;
}
if (fileIndex() != -1)
{
if (myHaveSize != haveSize)
{
myHaveSize = haveSize;
changed = true;
}
myHaveSize = haveSize;
if (updateFields)
{
if (myIsWanted != wanted)
{
myIsWanted = wanted;
changed = true;
changed_fields[changed_count++] = COL_WANTED;
}
if (myPriority != priority)
{
myPriority = priority;
changed = true;
changed_fields[changed_count++] = COL_PRIORITY;
}
}
}
std::pair<int,int> changed (-1, -1);
if (changed_count > 0)
{
std::sort (changed_fields, changed_fields+changed_count);
changed.first = changed_fields[0];
changed.second = changed_fields [changed_count-1];
std::cerr << "changed.first " << changed.first << " changed.second " << changed.second << std::endl;
}
return changed;
}
@ -568,12 +575,6 @@ FileTreeModel :: findItemForFileIndex (int fileIndex) const
return ret;
}
void
FileTreeModel :: itemChanged (FileTreeItem * item)
{
dataChanged (indexOf(item, FIRST_VISIBLE_COLUMN), indexOf(item, LAST_VISIBLE_COLUMN));
}
void
FileTreeModel :: addFile (int fileIndex,
const QString & filename,
@ -595,8 +596,9 @@ FileTreeModel :: addFile (int fileIndex,
while (!tokens.isEmpty())
{
const QString token = tokens.takeLast();
if (item->update (token, wanted, priority, have, updateFields))
itemChanged (item);
const std::pair<int,int> changed = item->update (token, wanted, priority, have, updateFields);
if (changed.first >= 0)
dataChanged (indexOf (item, changed.first), indexOf (item, changed.second));
item = item->parent();
}
assert (item == myRootItem);
@ -632,8 +634,9 @@ FileTreeModel :: addFile (int fileIndex,
assert (item->fileIndex() == fileIndex);
assert (item->totalSize() == totalSize);
if (item->update (item->name(), wanted, priority, have, added || updateFields))
itemChanged (item);
const std::pair<int,int> changed = item->update (item->name(), wanted, priority, have, added || updateFields);
if (changed.first >= 0)
dataChanged (indexOf (item, changed.first), indexOf (item, changed.second));
}
}
}

View File

@ -63,7 +63,7 @@ class FileTreeItem: public QObject
int row () const;
const QString& name () const { return myName; }
QVariant data (int column, int role) const;
bool update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
std::pair<int,int> update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
void twiddleWanted (QSet<int>& fileIds, bool&);
void twiddlePriority (QSet<int>& fileIds, int&);
int fileIndex () const { return myFileIndex; }
@ -125,7 +125,6 @@ class FileTreeModel: public QAbstractItemModel
bool torrentChanged);
private:
void itemChanged (FileTreeItem *);
void clearSubtree (const QModelIndex &);
QModelIndex indexOf (FileTreeItem *, int column) const;
void parentsChanged (const QModelIndex &, int column);