Changeset 13894


Ignore:
Timestamp:
Jan 28, 2013, 6:20:20 PM (8 years ago)
Author:
jordan
Message:

(qt) more futzing with file-tree

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/file-tree.cc

    r13893 r13894  
    5353  while (myFirstUnhashedRow < n)
    5454    {
    55       myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), myFirstUnhashedRow);
    56       myFirstUnhashedRow++;
     55      myChildRows.insert (myChildren[myFirstUnhashedRow]->name(),
     56                          myFirstUnhashedRow);
     57      ++myFirstUnhashedRow;
    5758    }
    5859
     
    120121  if (column == COL_FILE_INDEX)
    121122    {
    122       return myIndex;
     123      return myFileIndex;
    123124    }
    124125  else if (role == Qt::EditRole)
     
    235236FileTreeItem :: priorityString () const
    236237{
    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    }
    242247}
    243248
     
    278283      myPriority = i;
    279284
    280       if (myIndex >= 0)
    281         ids.insert (myIndex);
     285      if (myFileIndex >= 0)
     286        ids.insert (myFileIndex);
    282287    }
    283288
     
    332337      myIsWanted = b;
    333338
    334       if (myIndex >= 0)
    335         ids.insert(myIndex);
     339      if (myFileIndex >= 0)
     340        ids.insert(myFileIndex);
    336341    }
    337342
     
    366371}
    367372
     373FileTreeItem *
     374FileTreeModel :: itemFromIndex (const QModelIndex& index) const
     375{
     376  return static_cast<FileTreeItem*>(index.internalPointer());
     377}
     378
    368379QVariant
    369380FileTreeModel :: data (const QModelIndex &index, int role) const
     
    372383
    373384  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);
    378386
    379387  return value;
     
    401409      QString oldpath;
    402410      QModelIndex walk = index;
    403       FileTreeItem * item = static_cast<FileTreeItem*>(index.internalPointer());
     411      FileTreeItem * item = itemFromIndex (index);
    404412
    405413      while (item && !item->name().isEmpty())
     
    467475        parentItem = myRootItem;
    468476      else
    469         parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
     477        parentItem = itemFromIndex (parent);
    470478
    471479      FileTreeItem * childItem = parentItem->child(row);
     
    487495FileTreeModel :: parent (const QModelIndex& child, int column) const
    488496{
    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;
    495503}
    496504
     
    500508  FileTreeItem * parentItem;
    501509
    502   if (!parent.isValid())
     510  if (parent.isValid())
     511    parentItem = itemFromIndex (parent);
     512  else
    503513    parentItem = myRootItem;
    504   else
    505     parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
    506514
    507515  return parentItem->childCount();
     
    533541    clearSubtree(index(--i, 0, top));
    534542
    535   delete static_cast<FileTreeItem*>(top.internalPointer());
     543  delete static_cast<FileTreeItem*>(itemFromIndex(top));
    536544}
    537545
     
    559567      QModelIndex& index = indices.front ();
    560568      if (index.isValid())
    561         ret = static_cast<FileTreeItem*>(index.internalPointer());
     569        ret = itemFromIndex (index);
    562570    }
    563571
     
    679687      FileTreeItem * item;
    680688
    681       item = static_cast<FileTreeItem*>(index.internalPointer());
     689      item = itemFromIndex (index);
    682690      item->twiddleWanted (file_ids, want);
    683691      emit wantedChanged (file_ids, want);
     
    693701      FileTreeItem * item;
    694702
    695       item = static_cast<FileTreeItem*>(index.internalPointer());
     703      item = itemFromIndex (index);
    696704      item->twiddlePriority (file_ids, priority);
    697705      emit priorityChanged (file_ids, priority);
     
    906914
    907915void
    908 FileTreeView :: update (const FileList& files)
    909 {
    910   update (files, true);
    911 }
    912 
    913 void
    914916FileTreeView :: update (const FileList& files, bool updateFields)
    915917{
  • trunk/qt/file-tree.h

    r13893 r13894  
    1111 */
    1212
    13 #ifndef QTR_TREE_FILE_MODEL
    14 #define QTR_TREE_FILE_MODEL
     13#ifndef QTR_FILE_TREE
     14#define QTR_FILE_TREE
    1515
    1616#include <QAbstractItemModel>
     
    4545
    4646    FileTreeItem (const QString& name="", int fileIndex=-1, uint64_t size=0):
    47       myIndex (fileIndex),
     47      myFileIndex (fileIndex),
    4848      myParent (0),
    4949      myName (name),
     
    6767    void twiddleWanted (QSet<int>& fileIds, bool&);
    6868    void twiddlePriority (QSet<int>& fileIds, int&);
    69     int fileIndex () const { return myIndex; }
     69    int fileIndex () const { return myFileIndex; }
    7070    uint64_t totalSize () const { return myTotalSize; }
    71    
    72    
    7371
    7472  private:
     
    8280    int isSubtreeWanted () const;
    8381
    84     const int myIndex;
     82    const int myFileIndex;
    8583    FileTreeItem * myParent;
    8684    QList<FileTreeItem*> myChildren;
     
    134132    void subtreeChanged (const QModelIndex &, int column);
    135133    FileTreeItem * findItemForFileIndex (int fileIndex) const;
    136 
    137 
     134    FileTreeItem * itemFromIndex (const QModelIndex&) const;
    138135
    139136  private:
     
    166163    virtual ~FileTreeView ();
    167164    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);
    170166
    171167  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);
    174170    void pathEdited (const QString& oldpath, const QString& newname);
    175171
     
    183179
    184180  public slots:
    185     void onClicked (const QModelIndex & index);
     181    void onClicked (const QModelIndex& index);
    186182};
    187183
Note: See TracChangeset for help on using the changeset viewer.