Changeset 14551
- Timestamp:
- Jul 12, 2015, 8:48:54 PM (8 years ago)
- Location:
- trunk/qt
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/FileTreeItem.cc
r14541 r14551 120 120 value.setValue (sizeString()); 121 121 else 122 value.setValue (size ());122 value.setValue<quint64> (size ()); 123 123 break; 124 124 -
trunk/qt/FileTreeModel.cc
r14539 r14551 10 10 #include <cassert> 11 11 12 #include <QStringList>13 14 12 #include "FileTreeItem.h" 15 13 #include "FileTreeModel.h" 14 15 namespace 16 { 17 class PathIteratorBase 18 { 19 protected: 20 PathIteratorBase(const QString& path, int slashIndex): 21 myPath (path), 22 mySlashIndex (slashIndex), 23 myToken () 24 { 25 myToken.reserve (path.size () / 2); 26 } 27 28 protected: 29 const QString& myPath; 30 int mySlashIndex; 31 QString myToken; 32 33 static const QChar SlashChar; 34 }; 35 36 const QChar PathIteratorBase::SlashChar = QLatin1Char ('/'); 37 38 class ForwardPathIterator: public PathIteratorBase 39 { 40 public: 41 ForwardPathIterator (const QString& path): 42 PathIteratorBase (path, path.size () - 1) 43 { 44 } 45 46 bool hasNext () const 47 { 48 return mySlashIndex > 0; 49 } 50 51 const QString& next () 52 { 53 int newSlashIndex = myPath.lastIndexOf (SlashChar, mySlashIndex); 54 myToken.truncate (0); 55 myToken += myPath.midRef (newSlashIndex + 1, mySlashIndex - newSlashIndex); 56 mySlashIndex = newSlashIndex - 1; 57 return myToken; 58 } 59 }; 60 61 class BackwardPathIterator: public PathIteratorBase 62 { 63 public: 64 BackwardPathIterator (const QString& path): 65 PathIteratorBase (path, 0) 66 { 67 } 68 69 bool hasNext () const 70 { 71 return mySlashIndex < myPath.size (); 72 } 73 74 const QString& next () 75 { 76 int newSlashIndex = myPath.indexOf (SlashChar, mySlashIndex); 77 if (newSlashIndex == -1) 78 newSlashIndex = myPath.size (); 79 myToken.truncate (0); 80 myToken += myPath.midRef (mySlashIndex, newSlashIndex - mySlashIndex); 81 mySlashIndex = newSlashIndex + 1; 82 return myToken; 83 } 84 }; 85 } 16 86 17 87 FileTreeModel::FileTreeModel (QObject * parent, bool isEditable): … … 222 292 223 293 void 224 FileTreeModel::addFile (int fileIndex, 225 const QString & filename, 226 bool wanted, 227 int priority, 228 uint64_t totalSize, 229 uint64_t have, 230 QList<QModelIndex> & rowsAdded, 231 bool updateFields) 294 FileTreeModel::addFile (int fileIndex, 295 const QString& filename, 296 bool wanted, 297 int priority, 298 uint64_t totalSize, 299 uint64_t have, 300 bool updateFields) 232 301 { 233 302 FileTreeItem * item; 234 QStringList tokens = filename.split (QChar::fromLatin1('/'));235 303 236 304 item = findItemForFileIndex (fileIndex); … … 239 307 { 240 308 QModelIndex indexWithChangedParents; 241 while (!tokens.isEmpty()) 309 ForwardPathIterator filenameIt (filename); 310 while (filenameIt.hasNext ()) 242 311 { 243 const QString token = tokens.takeLast();312 const QString& token = filenameIt.next (); 244 313 const std::pair<int,int> changed = item->update (token, wanted, priority, have, updateFields); 245 314 if (changed.first >= 0) … … 261 330 262 331 item = myRootItem; 263 while (!tokens.isEmpty()) 332 BackwardPathIterator filenameIt (filename); 333 while (filenameIt.hasNext ()) 264 334 { 265 const QString token = tokens.takeFirst();335 const QString& token = filenameIt.next (); 266 336 FileTreeItem * child(item->child(token)); 267 337 if (!child) … … 272 342 273 343 beginInsertRows (parentIndex, n, n); 274 if ( tokens.isEmpty())344 if (!filenameIt.hasNext ()) 275 345 child = new FileTreeItem (token, fileIndex, totalSize); 276 346 else … … 278 348 item->appendChild (child); 279 349 endInsertRows (); 280 281 rowsAdded.append (indexOf(child, 0));282 350 } 283 351 item = child; -
trunk/qt/FileTreeModel.h
r14541 r14551 54 54 bool wanted, int priority, 55 55 uint64_t size, uint64_t have, 56 QList<QModelIndex>& rowsAdded,57 56 bool torrentChanged); 58 57 -
trunk/qt/FileTreeView.cc
r14541 r14551 170 170 FileTreeView::update (const FileList& files, bool updateFields) 171 171 { 172 const bool modelWasEmpty = myProxy->rowCount () == 0; 173 172 174 for (const TorrentFile& file: files) 175 myModel->addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, updateFields); 176 177 if (modelWasEmpty) 173 178 { 174 QList<QModelIndex> added; 175 myModel->addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields); 176 for (const QModelIndex& i: added) 177 expand (myProxy->mapFromSource(i)); 179 // expand up until the item with more than one expandable child 180 for (QModelIndex index = myProxy->index (0, 0); index.isValid ();) 181 { 182 const QModelIndex oldIndex = index; 183 184 expand (oldIndex); 185 186 index = QModelIndex (); 187 for (int i = 0, count = myProxy->rowCount (oldIndex); i < count; ++i) 188 { 189 const QModelIndex newIndex = myProxy->index (i, 0, oldIndex); 190 if (myProxy->rowCount (newIndex) == 0) 191 continue; 192 if (index.isValid ()) 193 { 194 index = QModelIndex (); 195 break; 196 } 197 index = newIndex; 198 } 199 } 178 200 } 201 202 myProxy->sort (header ()->sortIndicatorSection (), header ()->sortIndicatorOrder ()); 179 203 } 180 204
Note: See TracChangeset
for help on using the changeset viewer.