modify more files to the new indentation/whitespace formatting

This commit is contained in:
Jordan Lee 2013-01-25 18:37:11 +00:00
parent 797976b336
commit 4356ade034
2 changed files with 586 additions and 523 deletions

View File

@ -159,9 +159,11 @@ FileTreeItem :: progress( ) const
{
double d(0);
uint64_t have(0), total(0);
getSubtreeSize(have, total);
if (total)
d = have / (double)total;
return d;
}
@ -176,7 +178,12 @@ FileTreeItem :: fileSizeName( ) const
}
bool
FileTreeItem :: update( int index, bool wanted, int priority, uint64_t totalSize, uint64_t haveSize, bool torrentChanged )
FileTreeItem :: update (int index,
bool wanted,
int priority,
uint64_t totalSize,
uint64_t haveSize,
bool torrentChanged)
{
bool changed = false;
@ -185,21 +192,25 @@ FileTreeItem :: update( int index, bool wanted, int priority, uint64_t totalSize
myIndex = index;
changed = true;
}
if (torrentChanged && myIsWanted != wanted)
{
myIsWanted = wanted;
changed = true;
}
if (torrentChanged && myPriority != priority)
{
myPriority = priority;
changed = true;
}
if (myTotalSize != totalSize)
{
myTotalSize = totalSize;
changed = true;
}
if (myHaveSize != haveSize)
{
myHaveSize = haveSize;
@ -224,10 +235,19 @@ FileTreeItem :: priority( ) const
{
int i(0);
if( myChildren.isEmpty( ) ) switch( myPriority ) {
case TR_PRI_LOW: i |= LOW; break;
case TR_PRI_HIGH: i |= HIGH; break;
default: i |= NORMAL; break;
if(myChildren.isEmpty()) switch(myPriority)
{
case TR_PRI_LOW:
i |= LOW;
break;
case TR_PRI_HIGH:
i |= HIGH;
break;
default:
i |= NORMAL;
break;
}
foreach(const FileTreeItem * child, myChildren)
@ -239,8 +259,10 @@ FileTreeItem :: priority( ) const
void
FileTreeItem :: setSubtreePriority (int i, QSet<int>& ids)
{
if( myPriority != i ) {
if (myPriority != i)
{
myPriority = i;
if (myIndex >= 0)
ids.insert (myIndex);
}
@ -254,9 +276,12 @@ FileTreeItem :: twiddlePriority( QSet<int>& ids, int& p )
{
const int old(priority());
if ( old & LOW ) p = TR_PRI_NORMAL;
else if( old & NORMAL ) p = TR_PRI_HIGH;
else p = TR_PRI_LOW;
if (old & LOW)
p = TR_PRI_NORMAL;
else if (old & NORMAL)
p = TR_PRI_HIGH;
else
p = TR_PRI_LOW;
setSubtreePriority (p, ids);
}
@ -268,12 +293,16 @@ FileTreeItem :: isSubtreeWanted( ) const
return myIsWanted ? Qt::Checked : Qt::Unchecked;
int wanted(-1);
foreach( const FileTreeItem * child, myChildren ) {
foreach (const FileTreeItem * child, myChildren)
{
const int childWanted = child->isSubtreeWanted();
if(wanted == -1)
wanted = childWanted;
if(wanted != childWanted)
wanted = Qt::PartiallyChecked;
if(wanted == Qt::PartiallyChecked)
return wanted;
}
@ -284,8 +313,10 @@ FileTreeItem :: isSubtreeWanted( ) const
void
FileTreeItem :: setSubtreeWanted (bool b, QSet<int>& ids)
{
if( myIsWanted != b ) {
if(myIsWanted != b)
{
myIsWanted = b;
if (myIndex >= 0)
ids.insert(myIndex);
}
@ -376,13 +407,28 @@ FileTreeModel :: headerData( int column, Qt::Orientation orientation, int role )
{
QVariant data;
if( orientation==Qt::Horizontal && role==Qt::DisplayRole ) {
switch( column ) {
case COL_NAME: data.setValue( tr( "File" ) ); break;
case COL_PROGRESS: data.setValue( tr( "Progress" ) ); break;
case COL_WANTED: data.setValue( tr( "Download" ) ); break;
case COL_PRIORITY: data.setValue( tr( "Priority" ) ); break;
default: break;
if(orientation==Qt::Horizontal && role==Qt::DisplayRole)
{
switch (column)
{
case COL_NAME:
data.setValue (tr("File"));
break;
case COL_PROGRESS:
data.setValue (tr("Progress"));
break;
case COL_WANTED:
data.setValue (tr("Download"));
break;
case COL_PRIORITY:
data.setValue (tr("Priority"));
break;
default:
break;
}
}
@ -411,8 +457,6 @@ FileTreeModel :: index( int row, int column, const QModelIndex& parent ) const
if (childItem)
i = createIndex(row, column, childItem);
//std::cerr << "FileTreeModel::index(row("<<row<<"),col("<<column<<"),parent("<<qPrintable(parentItem->name())<<")) is returning " << qPrintable(childItem->name()) << ": internalPointer " << i.internalPointer() << " row " << i.row() << " col " << i.column() << std::endl;
}
return i;
@ -521,10 +565,12 @@ FileTreeModel :: parentsChanged( const QModelIndex& index, int column )
{
QModelIndex walk = index;
for( ;; ) {
for (;;)
{
walk = parent(walk, column);
if(!walk.isValid())
break;
dataChanged(walk, walk);
}
}
@ -554,11 +600,13 @@ FileTreeModel :: clicked( const QModelIndex& index )
if (column == COL_WANTED)
{
FileTreeItem * item( static_cast<FileTreeItem*>(index.internalPointer()));
bool want;
QSet<int> fileIds;
item->twiddleWanted( fileIds, want );
emit wantedChanged( fileIds, want );
QSet<int> file_ids;
FileTreeItem * item;
item = static_cast<FileTreeItem*>(index.internalPointer());
item->twiddleWanted (file_ids, want);
emit wantedChanged (file_ids, want);
dataChanged (index, index);
parentsChanged (index, column);
@ -566,11 +614,13 @@ FileTreeModel :: clicked( const QModelIndex& index )
}
else if (column == COL_PRIORITY)
{
FileTreeItem * item( static_cast<FileTreeItem*>(index.internalPointer()));
int priority;
QSet<int>fileIds;
item->twiddlePriority( fileIds, priority );
emit priorityChanged( fileIds, priority );
QSet<int> file_ids;
FileTreeItem * item;
item = static_cast<FileTreeItem*>(index.internalPointer());
item->twiddlePriority (file_ids, priority);
emit priorityChanged (file_ids, priority);
dataChanged(index, index);
parentsChanged(index, column);
@ -589,7 +639,8 @@ FileTreeDelegate :: sizeHint( const QStyleOptionViewItem& item, const QModelInde
switch(index.column())
{
case COL_NAME: {
case COL_NAME:
{
const QFontMetrics fm(item.font);
const QString text = index.data().toString();
const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
@ -603,7 +654,8 @@ FileTreeDelegate :: sizeHint( const QStyleOptionViewItem& item, const QModelInde
size = QSize(20, 1);
break;
default: {
default:
{
const QFontMetrics fm(item.font);
const QString text = index.data().toString();
size = fm.size(0, text);
@ -644,7 +696,9 @@ FileTreeDelegate :: paint( QPainter * painter,
iconSize, iconSize);
QIcon icon;
if (index.model()->hasChildren(index))
{
icon = style->standardIcon(QStyle::StandardPixmap(QStyle::SP_DirOpenIcon));
}
else
{
QString name = index.data().toString();
@ -683,7 +737,8 @@ FileTreeDelegate :: paint( QPainter * painter,
o.rect.setSize(QSize(20, option.rect.height()));
o.rect.moveCenter(option.rect.center());
o.fontMetrics = QApplication::fontMetrics();
switch( index.data().toInt() ) {
switch(index.data().toInt())
{
case Qt::Unchecked: o.state |= QStyle::State_Off; break;
case Qt::Checked: o.state |= QStyle::State_On; break;
default: o.state |= QStyle::State_NoChange;break;
@ -759,7 +814,8 @@ FileTreeView :: eventFilter( QObject * o, QEvent * event )
QResizeEvent * r = dynamic_cast<QResizeEvent*>(event);
int left = r->size().width();
const QFontMetrics fontMetrics(font());
for( int column=0; column<NUM_COLUMNS; ++column ) {
for (int column=0; column<NUM_COLUMNS; ++column)
{
if (column == COL_NAME)
continue;
if (isColumnHidden(column))
@ -805,7 +861,8 @@ FileTreeView :: update( const FileList& files )
void
FileTreeView :: update (const FileList& files, bool torrentChanged)
{
foreach( const TrFile file, files ) {
foreach (const TrFile file, files)
{
QList<QModelIndex> added;
myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, torrentChanged);
foreach (QModelIndex i, added)

View File

@ -40,11 +40,17 @@ class FileTreeItem: public QObject
enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) };
public:
virtual ~FileTreeItem();
FileTreeItem (int fileIndex, const QString& name=""):
myIndex(fileIndex), myParent(0), myName(name),
myPriority(0), myIsWanted(0),
myHaveSize(0), myTotalSize(0),
myIndex (fileIndex),
myParent (0),
myName (name),
myPriority (0),
myIsWanted (0),
myHaveSize (0),
myTotalSize (0),
myFirstUnhashedRow (0) { }
public: