// ensure that all the rows are hashed
while (myFirstUnhashedRow < n)
{
- myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), myFirstUnhashedRow);
- myFirstUnhashedRow++;
+ myChildRows.insert (myChildren[myFirstUnhashedRow]->name(),
+ myFirstUnhashedRow);
+ ++myFirstUnhashedRow;
}
return myChildRows;
if (column == COL_FILE_INDEX)
{
- return myIndex;
+ return myFileIndex;
}
else if (role == Qt::EditRole)
{
QString
FileTreeItem :: priorityString () const
{
- const int i(priority());
- if(i == LOW) return tr("Low");
- if(i == HIGH) return tr("High");
- if(i == NORMAL) return tr("Normal");
- return tr("Mixed");
+ const int i = priority();
+
+ switch (i)
+ {
+ case LOW: return tr("Low");
+ case HIGH: return tr("High");
+ case NORMAL: return tr("Normal");
+ default: return tr("Mixed");
+ }
}
int
{
myPriority = i;
- if (myIndex >= 0)
- ids.insert (myIndex);
+ if (myFileIndex >= 0)
+ ids.insert (myFileIndex);
}
foreach (FileTreeItem * child, myChildren)
{
myIsWanted = b;
- if (myIndex >= 0)
- ids.insert(myIndex);
+ if (myFileIndex >= 0)
+ ids.insert(myFileIndex);
}
foreach (FileTreeItem * child, myChildren)
delete myRootItem;
}
+FileTreeItem *
+FileTreeModel :: itemFromIndex (const QModelIndex& index) const
+{
+ return static_cast<FileTreeItem*>(index.internalPointer());
+}
+
QVariant
FileTreeModel :: data (const QModelIndex &index, int role) const
{
QVariant value;
if (index.isValid())
- {
- FileTreeItem * i = static_cast<FileTreeItem*>(index.internalPointer());
- value = i->data (index.column(), role);
- }
+ value = itemFromIndex(index)->data (index.column(), role);
return value;
}
{
QString oldpath;
QModelIndex walk = index;
- FileTreeItem * item = static_cast<FileTreeItem*>(index.internalPointer());
+ FileTreeItem * item = itemFromIndex (index);
while (item && !item->name().isEmpty())
{
if(!parent.isValid())
parentItem = myRootItem;
else
- parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
+ parentItem = itemFromIndex (parent);
FileTreeItem * childItem = parentItem->child(row);
QModelIndex
FileTreeModel :: parent (const QModelIndex& child, int column) const
{
- if (!child.isValid())
- return QModelIndex();
+ QModelIndex parent;
- FileTreeItem * childItem = static_cast<FileTreeItem*>(child.internalPointer());
+ if (child.isValid())
+ parent = indexOf (itemFromIndex(child)->parent(), column);
- return indexOf (childItem->parent(), column);
+ return parent;
}
int
{
FileTreeItem * parentItem;
- if (!parent.isValid())
- parentItem = myRootItem;
+ if (parent.isValid())
+ parentItem = itemFromIndex (parent);
else
- parentItem = static_cast<FileTreeItem*>(parent.internalPointer());
+ parentItem = myRootItem;
return parentItem->childCount();
}
while (i > 0)
clearSubtree(index(--i, 0, top));
- delete static_cast<FileTreeItem*>(top.internalPointer());
+ delete static_cast<FileTreeItem*>(itemFromIndex(top));
}
void
{
QModelIndex& index = indices.front ();
if (index.isValid())
- ret = static_cast<FileTreeItem*>(index.internalPointer());
+ ret = itemFromIndex (index);
}
return ret;
QSet<int> file_ids;
FileTreeItem * item;
- item = static_cast<FileTreeItem*>(index.internalPointer());
+ item = itemFromIndex (index);
item->twiddleWanted (file_ids, want);
emit wantedChanged (file_ids, want);
QSet<int> file_ids;
FileTreeItem * item;
- item = static_cast<FileTreeItem*>(index.internalPointer());
+ item = itemFromIndex (index);
item->twiddlePriority (file_ids, priority);
emit priorityChanged (file_ids, priority);
return false;
}
-void
-FileTreeView :: update (const FileList& files)
-{
- update (files, true);
-}
-
void
FileTreeView :: update (const FileList& files, bool updateFields)
{
* $Id$
*/
-#ifndef QTR_TREE_FILE_MODEL
-#define QTR_TREE_FILE_MODEL
+#ifndef QTR_FILE_TREE
+#define QTR_FILE_TREE
#include <QAbstractItemModel>
#include <QObject>
virtual ~FileTreeItem();
FileTreeItem (const QString& name="", int fileIndex=-1, uint64_t size=0):
- myIndex (fileIndex),
+ myFileIndex (fileIndex),
myParent (0),
myName (name),
myPriority (0),
bool 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 myIndex; }
+ int fileIndex () const { return myFileIndex; }
uint64_t totalSize () const { return myTotalSize; }
-
-
private:
void setSubtreePriority (int priority, QSet<int>& fileIds);
int priority () const;
int isSubtreeWanted () const;
- const int myIndex;
+ const int myFileIndex;
FileTreeItem * myParent;
QList<FileTreeItem*> myChildren;
QHash<QString,int> myChildRows;
void parentsChanged (const QModelIndex &, int column);
void subtreeChanged (const QModelIndex &, int column);
FileTreeItem * findItemForFileIndex (int fileIndex) const;
-
-
+ FileTreeItem * itemFromIndex (const QModelIndex&) const;
private:
FileTreeItem * myRootItem;
FileTreeView (QWidget * parent=0, bool editable=true);
virtual ~FileTreeView ();
void clear ();
- void update (const FileList& files);
- void update (const FileList& files, bool torrentChanged);
+ void update (const FileList& files, bool updateProperties=true);
signals:
- void priorityChanged (const QSet<int>& fileIndices, int);
- void wantedChanged (const QSet<int>& fileIndices, bool);
+ void priorityChanged (const QSet<int>& fileIndices, int priority);
+ void wantedChanged (const QSet<int>& fileIndices, bool wanted);
void pathEdited (const QString& oldpath, const QString& newname);
protected:
FileTreeDelegate myDelegate;
public slots:
- void onClicked (const QModelIndex & index);
+ void onClicked (const QModelIndex& index);
};
#endif