PeerListDelegate: fix coding style in whole file

This commit is contained in:
thalieht 2016-06-22 21:13:30 +03:00
parent a90100a0b7
commit f523685414

View file

@ -33,69 +33,89 @@
#include <QItemDelegate> #include <QItemDelegate>
#include <QPainter> #include <QPainter>
#include "base/preferences.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "base/preferences.h"
class PeerListDelegate: public QItemDelegate { class PeerListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT
public: public:
enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED, enum PeerListColumns
TOT_DOWN, TOT_UP, RELEVANCE, DOWNLOADING_PIECE, IP_HIDDEN, COL_COUNT}; {
COUNTRY,
IP,
PORT,
CONNECTION,
FLAGS,
CLIENT,
PROGRESS,
DOWN_SPEED,
UP_SPEED,
TOT_DOWN,
TOT_UP, RELEVANCE,
DOWNLOADING_PIECE,
IP_HIDDEN,
COL_COUNT
};
public: public:
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
~PeerListDelegate() {} ~PeerListDelegate() {}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
painter->save(); {
const bool hideValues = Preferences::instance()->getHideZeroValues(); painter->save();
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); const bool hideValues = Preferences::instance()->getHideZeroValues();
switch(index.column()) { QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
case PORT: switch(index.column()) {
QItemDelegate::drawBackground(painter, opt, index); case PORT: {
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
break; QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString());
case TOT_DOWN: }
case TOT_UP: {
qlonglong size = index.data().toLongLong();
if (hideValues && (size <= 0))
break; break;
QItemDelegate::drawBackground(painter, opt, index); case TOT_DOWN:
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; case TOT_UP: {
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); qlonglong size = index.data().toLongLong();
} if (hideValues && (size <= 0))
break; break;
case DOWN_SPEED: QItemDelegate::drawBackground(painter, opt, index);
case UP_SPEED:{ opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size));
qreal speed = index.data().toDouble(); }
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; break;
if (speed > 0.0) case DOWN_SPEED:
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); case UP_SPEED:{
break; QItemDelegate::drawBackground(painter, opt, index);
qreal speed = index.data().toDouble();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
if (speed > 0.0)
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
}
break;
case PROGRESS:
case RELEVANCE: {
QItemDelegate::drawBackground(painter, opt, index);
qreal progress = index.data().toDouble();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%");
}
break;
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
} }
case PROGRESS:
case RELEVANCE:{
QItemDelegate::drawBackground(painter, opt, index);
qreal progress = index.data().toDouble();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%");
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
}
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const
// No editor here {
return 0; // No editor here
} return 0;
}
}; };