Browse Source

Simplify various if-else and QString::number.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
0f298397b3
  1. 17
      src/properties/propertieswidget.cpp
  2. 2
      src/rss/feedlistwidget.cpp
  3. 4
      src/rss/rss_imp.cpp
  4. 1
      src/searchengine/searchlistdelegate.h
  5. 21
      src/transferlistdelegate.h
  6. 10
      src/webui/btjson.cpp

17
src/properties/propertieswidget.cpp

@ -317,14 +317,8 @@ void PropertiesWidget::loadDynamicData() {
wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes())); wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes()));
upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")"); upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")");
dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")"); dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")");
if (h.upload_limit() <= 0) lbl_uplimit->setText(h.upload_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
lbl_uplimit->setText(QString::fromUtf8("")); lbl_dllimit->setText(h.download_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
else
lbl_uplimit->setText(misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
if (h.download_limit() <= 0)
lbl_dllimit->setText(QString::fromUtf8(""));
else
lbl_dllimit->setText(misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
QString elapsed_txt = misc::userFriendlyDuration(h.active_time()); QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
if (h.is_seed()) { if (h.is_seed()) {
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")"; elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";
@ -338,10 +332,9 @@ void PropertiesWidget::loadDynamicData() {
reannounce_lbl->setText(h.next_announce()); reannounce_lbl->setText(h.next_announce());
// Update ratio info // Update ratio info
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash()); const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
if (ratio > QBtSession::MAX_RATIO) /* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
shareRatio->setText(QString::fromUtf8("")); ** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
else shareRatio->setText(ratio > QBtSession::MAX_RATIO ? QString::fromUtf8("") : QString::number((int)(ratio*100)/100.0, 'f', 2));
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 2)));
if (!h.is_seed()) { if (!h.is_seed()) {
showPiecesDownloaded(true); showPiecesDownloaded(true);
// Downloaded pieces // Downloaded pieces

2
src/rss/feedlistwidget.cpp

@ -40,7 +40,7 @@ FeedListWidget::FeedListWidget(QWidget *parent, const RssManagerPtr& rssmanager)
setColumnCount(1); setColumnCount(1);
headerItem()->setText(0, tr("RSS feeds")); headerItem()->setText(0, tr("RSS feeds"));
m_unreadStickyItem = new QTreeWidgetItem(this); m_unreadStickyItem = new QTreeWidgetItem(this);
m_unreadStickyItem->setText(0, tr("Unread") + QString::fromUtf8(" (") + QString::number(rssmanager->unreadCount(), 10)+ QString(")")); m_unreadStickyItem->setText(0, tr("Unread") + QString::fromUtf8(" (") + QString::number(rssmanager->unreadCount())+ QString(")"));
m_unreadStickyItem->setData(0,Qt::DecorationRole, IconProvider::instance()->getIcon("mail-folder-inbox")); m_unreadStickyItem->setData(0,Qt::DecorationRole, IconProvider::instance()->getIcon("mail-folder-inbox"));
itemAdded(m_unreadStickyItem, rssmanager); itemAdded(m_unreadStickyItem, rssmanager);
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(updateCurrentFeed(QTreeWidgetItem*))); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(updateCurrentFeed(QTreeWidgetItem*)));

4
src/rss/rss_imp.cpp

@ -456,7 +456,7 @@ QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile)
{ {
Q_ASSERT(rssFile); Q_ASSERT(rssFile);
QTreeWidgetItem* item = new QTreeWidgetItem; QTreeWidgetItem* item = new QTreeWidgetItem;
item->setData(0, Qt::DisplayRole, QVariant(rssFile->displayName()+ QString::fromUtf8(" (")+QString::number(rssFile->unreadCount(), 10)+QString(")"))); item->setData(0, Qt::DisplayRole, QVariant(rssFile->displayName()+ QString::fromUtf8(" (")+QString::number(rssFile->unreadCount())+QString(")")));
item->setData(0, Qt::DecorationRole, rssFile->icon()); item->setData(0, Qt::DecorationRole, rssFile->icon());
return item; return item;
@ -619,7 +619,7 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item)
name = tr("Unread"); name = tr("Unread");
else else
name = rss_item->displayName(); name = rss_item->displayName();
item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount(), 10)+ QString(")")); item->setText(0, name + QString::fromUtf8(" (") + QString::number(rss_item->unreadCount())+ QString(")"));
// If item has a parent, update it too // If item has a parent, update it too
if (item->parent()) if (item->parent())
updateItemInfos(item->parent()); updateItemInfos(item->parent());

1
src/searchengine/searchlistdelegate.h

@ -32,7 +32,6 @@
#define SEARCHLISTDELEGATE_H #define SEARCHLISTDELEGATE_H
#include <QItemDelegate> #include <QItemDelegate>
#include <QStyleOptionProgressBarV2>
#include <QStyleOptionViewItemV2> #include <QStyleOptionViewItemV2>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>

21
src/transferlistdelegate.h

@ -33,12 +33,9 @@
#include <QItemDelegate> #include <QItemDelegate>
#include <QModelIndex> #include <QModelIndex>
#include <QByteArray>
#include <QStyleOptionViewItem>
#include <QStyleOptionViewItemV2> #include <QStyleOptionViewItemV2>
#include <QApplication> #include <QApplication>
#include <QPainter> #include <QPainter>
#include <QDateTime>
#include "misc.h" #include "misc.h"
#include "torrentmodel.h" #include "torrentmodel.h"
#include "qbtsession.h" #include "qbtsession.h"
@ -133,12 +130,9 @@ public:
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
const qlonglong limit = index.data().toLongLong(); const qlonglong limit = index.data().toLongLong();
opt.displayAlignment = Qt::AlignRight; opt.displayAlignment = Qt::AlignRight;
if (limit > 0) /* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9 ** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */ QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? QString::number((int)((limit/1024.)*10)/10.0, 'f', 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)") : QString::fromUtf8(""));
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number((int)((limit/1024.)*10)/10.0, 'f', 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)"));
else
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(""));
break; break;
} }
case TorrentModelItem::TR_TIME_ELAPSED: { case TorrentModelItem::TR_TIME_ELAPSED: {
@ -159,12 +153,9 @@ public:
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
opt.displayAlignment = Qt::AlignRight; opt.displayAlignment = Qt::AlignRight;
const qreal ratio = index.data().toDouble(); const qreal ratio = index.data().toDouble();
if (ratio > QBtSession::MAX_RATIO) /* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("")); ** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
else QItemDelegate::drawDisplay(painter, opt, opt.rect, ratio > QBtSession::MAX_RATIO ? QString::fromUtf8("") : QString::number((int)(ratio*100)/100.0, 'f', 2));
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number((int)(ratio*100)/100.0, 'f', 2));
break; break;
} }
case TorrentModelItem::TR_PRIORITY: { case TorrentModelItem::TR_PRIORITY: {

10
src/webui/btjson.cpp

@ -299,14 +299,8 @@ QString btjson::getPropertiesForTorrent(const QString& hash)
data.add(KEY_PROP_WASTED, misc::friendlyUnit(h.total_failed_bytes() + h.total_redundant_bytes())); data.add(KEY_PROP_WASTED, misc::friendlyUnit(h.total_failed_bytes() + h.total_redundant_bytes()));
data.add(KEY_PROP_UPLOADED, QString(misc::friendlyUnit(h.all_time_upload()) + " (" + misc::friendlyUnit(h.total_payload_upload()) + " " + tr("this session") + ")")); data.add(KEY_PROP_UPLOADED, QString(misc::friendlyUnit(h.all_time_upload()) + " (" + misc::friendlyUnit(h.total_payload_upload()) + " " + tr("this session") + ")"));
data.add(KEY_PROP_DOWNLOADED, QString(misc::friendlyUnit(h.all_time_download()) + " (" + misc::friendlyUnit(h.total_payload_download()) + " " + tr("this session") + ")")); data.add(KEY_PROP_DOWNLOADED, QString(misc::friendlyUnit(h.all_time_download()) + " (" + misc::friendlyUnit(h.total_payload_download()) + " " + tr("this session") + ")"));
if (h.upload_limit() <= 0) data.add(KEY_PROP_UP_LIMIT, h.upload_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.upload_limit(), true));
data.add(KEY_PROP_UP_LIMIT, QString::fromUtf8("")); data.add(KEY_PROP_DL_LIMIT, h.download_limit() <= 0 ? QString::fromUtf8("") : misc::friendlyUnit(h.download_limit(), true));
else
data.add(KEY_PROP_UP_LIMIT, misc::friendlyUnit(h.upload_limit(), true));
if (h.download_limit() <= 0)
data.add(KEY_PROP_DL_LIMIT, QString::fromUtf8(""));
else
data.add(KEY_PROP_DL_LIMIT, misc::friendlyUnit(h.download_limit(), true));
QString elapsed_txt = misc::userFriendlyDuration(h.active_time()); QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
if (h.is_seed()) if (h.is_seed())
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")"; elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";

Loading…
Cancel
Save