Changeset 13894
- Timestamp:
- Jan 28, 2013, 6:20:20 PM (9 years ago)
- Location:
- trunk/qt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/file-tree.cc
r13893 r13894 53 53 while (myFirstUnhashedRow < n) 54 54 { 55 myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), myFirstUnhashedRow); 56 myFirstUnhashedRow++; 55 myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), 56 myFirstUnhashedRow); 57 ++myFirstUnhashedRow; 57 58 } 58 59 … … 120 121 if (column == COL_FILE_INDEX) 121 122 { 122 return my Index;123 return myFileIndex; 123 124 } 124 125 else if (role == Qt::EditRole) … … 235 236 FileTreeItem :: priorityString () const 236 237 { 237 const int i(priority()); 238 if(i == LOW) return tr("Low"); 239 if(i == HIGH) return tr("High"); 240 if(i == NORMAL) return tr("Normal"); 241 return tr("Mixed"); 238 const int i = priority(); 239 240 switch (i) 241 { 242 case LOW: return tr("Low"); 243 case HIGH: return tr("High"); 244 case NORMAL: return tr("Normal"); 245 default: return tr("Mixed"); 246 } 242 247 } 243 248 … … 278 283 myPriority = i; 279 284 280 if (my Index >= 0)281 ids.insert (my Index);285 if (myFileIndex >= 0) 286 ids.insert (myFileIndex); 282 287 } 283 288 … … 332 337 myIsWanted = b; 333 338 334 if (my Index >= 0)335 ids.insert(my Index);339 if (myFileIndex >= 0) 340 ids.insert(myFileIndex); 336 341 } 337 342 … … 366 371 } 367 372 373 FileTreeItem * 374 FileTreeModel :: itemFromIndex (const QModelIndex& index) const 375 { 376 return static_cast<FileTreeItem*>(index.internalPointer()); 377 } 378 368 379 QVariant 369 380 FileTreeModel :: data (const QModelIndex &index, int role) const … … 372 383 373 384 if (index.isValid()) 374 { 375 FileTreeItem * i = static_cast<FileTreeItem*>(index.internalPointer()); 376 value = i->data (index.column(), role); 377 } 385 value = itemFromIndex(index)->data (index.column(), role); 378 386 379 387 return value; … … 401 409 QString oldpath; 402 410 QModelIndex walk = index; 403 FileTreeItem * item = static_cast<FileTreeItem*>(index.internalPointer());411 FileTreeItem * item = itemFromIndex (index); 404 412 405 413 while (item && !item->name().isEmpty()) … … 467 475 parentItem = myRootItem; 468 476 else 469 parentItem = static_cast<FileTreeItem*>(parent.internalPointer());477 parentItem = itemFromIndex (parent); 470 478 471 479 FileTreeItem * childItem = parentItem->child(row); … … 487 495 FileTreeModel :: parent (const QModelIndex& child, int column) const 488 496 { 489 if (!child.isValid())490 return QModelIndex(); 491 492 FileTreeItem * childItem = static_cast<FileTreeItem*>(child.internalPointer());493 494 return indexOf (childItem->parent(), column);497 QModelIndex parent; 498 499 if (child.isValid()) 500 parent = indexOf (itemFromIndex(child)->parent(), column); 501 502 return parent; 495 503 } 496 504 … … 500 508 FileTreeItem * parentItem; 501 509 502 if (!parent.isValid()) 510 if (parent.isValid()) 511 parentItem = itemFromIndex (parent); 512 else 503 513 parentItem = myRootItem; 504 else505 parentItem = static_cast<FileTreeItem*>(parent.internalPointer());506 514 507 515 return parentItem->childCount(); … … 533 541 clearSubtree(index(--i, 0, top)); 534 542 535 delete static_cast<FileTreeItem*>( top.internalPointer());543 delete static_cast<FileTreeItem*>(itemFromIndex(top)); 536 544 } 537 545 … … 559 567 QModelIndex& index = indices.front (); 560 568 if (index.isValid()) 561 ret = static_cast<FileTreeItem*>(index.internalPointer());569 ret = itemFromIndex (index); 562 570 } 563 571 … … 679 687 FileTreeItem * item; 680 688 681 item = static_cast<FileTreeItem*>(index.internalPointer());689 item = itemFromIndex (index); 682 690 item->twiddleWanted (file_ids, want); 683 691 emit wantedChanged (file_ids, want); … … 693 701 FileTreeItem * item; 694 702 695 item = static_cast<FileTreeItem*>(index.internalPointer());703 item = itemFromIndex (index); 696 704 item->twiddlePriority (file_ids, priority); 697 705 emit priorityChanged (file_ids, priority); … … 906 914 907 915 void 908 FileTreeView :: update (const FileList& files)909 {910 update (files, true);911 }912 913 void914 916 FileTreeView :: update (const FileList& files, bool updateFields) 915 917 { -
trunk/qt/file-tree.h
r13893 r13894 11 11 */ 12 12 13 #ifndef QTR_ TREE_FILE_MODEL14 #define QTR_ TREE_FILE_MODEL13 #ifndef QTR_FILE_TREE 14 #define QTR_FILE_TREE 15 15 16 16 #include <QAbstractItemModel> … … 45 45 46 46 FileTreeItem (const QString& name="", int fileIndex=-1, uint64_t size=0): 47 my Index (fileIndex),47 myFileIndex (fileIndex), 48 48 myParent (0), 49 49 myName (name), … … 67 67 void twiddleWanted (QSet<int>& fileIds, bool&); 68 68 void twiddlePriority (QSet<int>& fileIds, int&); 69 int fileIndex () const { return my Index; }69 int fileIndex () const { return myFileIndex; } 70 70 uint64_t totalSize () const { return myTotalSize; } 71 72 73 71 74 72 private: … … 82 80 int isSubtreeWanted () const; 83 81 84 const int my Index;82 const int myFileIndex; 85 83 FileTreeItem * myParent; 86 84 QList<FileTreeItem*> myChildren; … … 134 132 void subtreeChanged (const QModelIndex &, int column); 135 133 FileTreeItem * findItemForFileIndex (int fileIndex) const; 136 137 134 FileTreeItem * itemFromIndex (const QModelIndex&) const; 138 135 139 136 private: … … 166 163 virtual ~FileTreeView (); 167 164 void clear (); 168 void update (const FileList& files); 169 void update (const FileList& files, bool torrentChanged); 165 void update (const FileList& files, bool updateProperties=true); 170 166 171 167 signals: 172 void priorityChanged (const QSet<int>& fileIndices, int );173 void wantedChanged (const QSet<int>& fileIndices, bool );168 void priorityChanged (const QSet<int>& fileIndices, int priority); 169 void wantedChanged (const QSet<int>& fileIndices, bool wanted); 174 170 void pathEdited (const QString& oldpath, const QString& newname); 175 171 … … 183 179 184 180 public slots: 185 void onClicked (const QModelIndex 181 void onClicked (const QModelIndex& index); 186 182 }; 187 183
Note: See TracChangeset
for help on using the changeset viewer.