Browse Source

Use Qt::GlobalColor to refer to color instead of string

Qt uses binary search to convert string to QColor, we don't need that
binary search at all. This patch could be considered as optimization, but
in reality creating QColor takes only 0.2% of time. So it should be visible
at all.

This could be considered as cleanup for not calling expensive functions
from non-expensive ones.
adaptive-webui-19844
Ivan Sorokin 10 years ago
parent
commit
ad116edac7
  1. 26
      src/qtlibtorrent/torrentmodel.cpp

26
src/qtlibtorrent/torrentmodel.cpp

@ -102,7 +102,7 @@ TorrentModelItem::State TorrentModelItem::state() const {
// Pause or Queued // Pause or Queued
if (m_torrent.is_paused(m_lastStatus)) { if (m_torrent.is_paused(m_lastStatus)) {
m_icon = get_paused_icon(); m_icon = get_paused_icon();
m_fgColor = QColor("red"); m_fgColor = QColor(Qt::red);
return m_torrent.is_seed(m_lastStatus) ? STATE_PAUSED_UP : STATE_PAUSED_DL; return m_torrent.is_seed(m_lastStatus) ? STATE_PAUSED_UP : STATE_PAUSED_DL;
} }
if (m_torrent.is_queued(m_lastStatus)) { if (m_torrent.is_queued(m_lastStatus)) {
@ -110,7 +110,7 @@ TorrentModelItem::State TorrentModelItem::state() const {
&& m_lastStatus.state != torrent_status::checking_resume_data && m_lastStatus.state != torrent_status::checking_resume_data
&& m_lastStatus.state != torrent_status::checking_files) { && m_lastStatus.state != torrent_status::checking_files) {
m_icon = get_queued_icon(); m_icon = get_queued_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return m_torrent.is_seed(m_lastStatus) ? STATE_QUEUED_UP : STATE_QUEUED_DL; return m_torrent.is_seed(m_lastStatus) ? STATE_QUEUED_UP : STATE_QUEUED_DL;
} }
} }
@ -118,20 +118,20 @@ TorrentModelItem::State TorrentModelItem::state() const {
switch(m_lastStatus.state) { switch(m_lastStatus.state) {
case torrent_status::allocating: case torrent_status::allocating:
m_icon = get_stalled_downloading_icon(); m_icon = get_stalled_downloading_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return STATE_ALLOCATING; return STATE_ALLOCATING;
case torrent_status::downloading_metadata: case torrent_status::downloading_metadata:
m_icon = get_downloading_icon(); m_icon = get_downloading_icon();
m_fgColor = QColor("green"); m_fgColor = QColor(Qt::green);
return STATE_DOWNLOADING_META; return STATE_DOWNLOADING_META;
case torrent_status::downloading: { case torrent_status::downloading: {
if (m_lastStatus.download_payload_rate > 0) { if (m_lastStatus.download_payload_rate > 0) {
m_icon = get_downloading_icon(); m_icon = get_downloading_icon();
m_fgColor = QColor("green"); m_fgColor = QColor(Qt::green);
return STATE_DOWNLOADING; return STATE_DOWNLOADING;
} else { } else {
m_icon = get_stalled_downloading_icon(); m_icon = get_stalled_downloading_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return STATE_STALLED_DL; return STATE_STALLED_DL;
} }
} }
@ -139,33 +139,33 @@ TorrentModelItem::State TorrentModelItem::state() const {
case torrent_status::seeding: case torrent_status::seeding:
if (m_lastStatus.upload_payload_rate > 0) { if (m_lastStatus.upload_payload_rate > 0) {
m_icon = get_uploading_icon(); m_icon = get_uploading_icon();
m_fgColor = QColor("orange"); m_fgColor = QColor(255, 165, 0);
return STATE_SEEDING; return STATE_SEEDING;
} else { } else {
m_icon = get_stalled_uploading_icon(); m_icon = get_stalled_uploading_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return STATE_STALLED_UP; return STATE_STALLED_UP;
} }
case torrent_status::queued_for_checking: case torrent_status::queued_for_checking:
m_icon = get_checking_icon(); m_icon = get_checking_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return STATE_QUEUED_CHECK; return STATE_QUEUED_CHECK;
case torrent_status::checking_resume_data: case torrent_status::checking_resume_data:
m_icon = get_checking_icon(); m_icon = get_checking_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return STATE_QUEUED_FASTCHECK; return STATE_QUEUED_FASTCHECK;
case torrent_status::checking_files: case torrent_status::checking_files:
m_icon = get_checking_icon(); m_icon = get_checking_icon();
m_fgColor = QColor("grey"); m_fgColor = QColor(Qt::gray);
return m_torrent.is_seed(m_lastStatus) ? STATE_CHECKING_UP : STATE_CHECKING_DL; return m_torrent.is_seed(m_lastStatus) ? STATE_CHECKING_UP : STATE_CHECKING_DL;
default: default:
m_icon = get_error_icon(); m_icon = get_error_icon();
m_fgColor = QColor("red"); m_fgColor = QColor(Qt::red);
return STATE_INVALID; return STATE_INVALID;
} }
} catch(invalid_handle&) { } catch(invalid_handle&) {
m_icon = get_error_icon(); m_icon = get_error_icon();
m_fgColor = QColor("red"); m_fgColor = QColor(Qt::red);
return STATE_INVALID; return STATE_INVALID;
} }
} }

Loading…
Cancel
Save