From 9fc5de5b57bc993048d32c31f3de486b6d5e9444 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Wed, 23 Jan 2013 20:44:13 +0000 Subject: [PATCH] (qt) #1220: 'change file and folder names': fix Qt renaming issue reported by taem in https://trac.transmissionbt.com/ticket/1220#comment:97 --- qt/file-tree.cc | 46 +++++++++++++++++++++++++++++++++------------- qt/file-tree.h | 2 +- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/qt/file-tree.cc b/qt/file-tree.cc index b48312e0e..c3788c47f 100644 --- a/qt/file-tree.cc +++ b/qt/file-tree.cc @@ -110,18 +110,38 @@ FileTreeItem :: row( ) const } QVariant -FileTreeItem :: data( int column ) const +FileTreeItem :: data (int column, int role) const { - QVariant value; + QVariant value; - switch( column ) { - case COL_NAME: value.setValue( fileSizeName( ) ); break; - case COL_PROGRESS: value.setValue( progress( ) ); break; - case COL_WANTED: value.setValue( isSubtreeWanted( ) ); break; - case COL_PRIORITY: value.setValue( priorityString( ) ); break; + if (role == Qt::EditRole) + { + if (column == 0) + value.setValue (name()); + } + else if (role == Qt::DisplayRole) + { + switch( column ) + { + case COL_NAME: + value.setValue (fileSizeName()); + break; + + case COL_PROGRESS: + value.setValue (progress()); + break; + + case COL_WANTED: + value.setValue (isSubtreeWanted()); + break; + + case COL_PRIORITY: + value.setValue (priorityString()); + break; + } } - return value; + return value; } void @@ -304,11 +324,11 @@ FileTreeModel :: data( const QModelIndex &index, int role ) const { QVariant value; - if( index.isValid() && role==Qt::DisplayRole ) - { - FileTreeItem *item = static_cast(index.internalPointer()); - value = item->data( index.column( ) ); - } + if (index.isValid()) + { + FileTreeItem * i = static_cast(index.internalPointer()); + value = i->data (index.column(), role); + } return value; } diff --git a/qt/file-tree.h b/qt/file-tree.h index 5f0f87501..b66adf2d9 100644 --- a/qt/file-tree.h +++ b/qt/file-tree.h @@ -56,7 +56,7 @@ class FileTreeItem: public QObject const FileTreeItem * parent( ) const { return myParent; } int row( ) const; const QString& name( ) const { return myName; } - QVariant data( int column ) const; + QVariant data( int column, int role ) const; bool update( int index, bool want, int priority, uint64_t total, uint64_t have, bool torrentChanged ); void twiddleWanted( QSet& fileIds, bool& ); void twiddlePriority( QSet& fileIds, int& ); -- 2.40.0