Cleanup & refactor

This commit is contained in:
Chocobo1 2017-03-08 13:22:50 +08:00 committed by sledgehammer999
commit cdcafecb44
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
4 changed files with 30 additions and 28 deletions

View file

@ -82,18 +82,18 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
switch(index.column()) { switch(index.column()) {
case PCSIZE: case PCSIZE:
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break;
case REMAINING: case REMAINING:
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break; break;
case PROGRESS: case PROGRESS: {
if (index.data().toDouble() >= 0) { if (index.data().toDouble() < 0)
break;
QStyleOptionProgressBar newopt; QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.; qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.progress = (int)progress; newopt.progress = int(progress);
newopt.maximum = 100; newopt.maximum = 100;
newopt.minimum = 0; newopt.minimum = 0;
newopt.textVisible = true; newopt.textVisible = true;
@ -101,8 +101,10 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
newopt.state &= ~QStyle::State_Enabled; newopt.state &= ~QStyle::State_Enabled;
newopt.palette = progressBarDisabledPalette(); newopt.palette = progressBarDisabledPalette();
} }
else else {
newopt.state |= QStyle::State_Enabled; newopt.state |= QStyle::State_Enabled;
}
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else #else

View file

@ -56,13 +56,13 @@ class PropListDelegate : public QItemDelegate
public: public:
PropListDelegate(PropertiesWidget *properties); PropListDelegate(PropertiesWidget *properties);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const override;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const override;
public slots: public slots:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const override;
signals: signals:
void filteredFilesChanged() const; void filteredFilesChanged() const;

View file

@ -69,5 +69,5 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
{ {
// No editor here // No editor here
return 0; return nullptr;
} }

View file

@ -38,8 +38,8 @@ class SearchListDelegate: public QItemDelegate
public: public:
explicit SearchListDelegate(QObject *parent); explicit SearchListDelegate(QObject *parent);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const override;
}; };
#endif #endif