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

View File

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