qBittorrent
SpeedWidget Class Reference

#include <speedwidget.h>

Inheritance diagram for SpeedWidget:
Collaboration diagram for SpeedWidget:

Public Member Functions

 SpeedWidget (PropertiesWidget *parent)
 
 ~SpeedWidget ()
 

Private Slots

void onPeriodChange (int period)
 
void onGraphChange (int id)
 
void update ()
 

Private Member Functions

void loadSettings ()
 
void saveSettings () const
 

Private Attributes

QVBoxLayout * m_layout
 
QHBoxLayout * m_hlayout
 
QLabel * m_periodLabel
 
QComboBox * m_periodCombobox
 
SpeedPlotViewm_plot
 
ComboBoxMenuButtonm_graphsButton
 
QMenu * m_graphsMenu
 
QList< QAction * > m_graphsMenuActions
 

Detailed Description

Definition at line 55 of file speedwidget.h.

Constructor & Destructor Documentation

◆ SpeedWidget()

SpeedWidget::SpeedWidget ( PropertiesWidget parent)
explicit

Definition at line 58 of file speedwidget.cpp.

59  : QWidget(parent)
60 {
61  m_layout = new QVBoxLayout(this);
62  m_layout->setContentsMargins(0, 0, 0, 0);
63  m_layout->setSpacing(3);
64 
65  m_hlayout = new QHBoxLayout();
66  m_hlayout->setContentsMargins(0, 0, 0, 0);
67 
68  m_periodLabel = new QLabel("<b>" + tr("Period:") + "</b>");
69 
70  m_periodCombobox = new QComboBox();
71  m_periodCombobox->addItem(tr("1 Minute"));
72  m_periodCombobox->addItem(tr("5 Minutes"));
73  m_periodCombobox->addItem(tr("30 Minutes"));
74  m_periodCombobox->addItem(tr("3 Hours"));
75  m_periodCombobox->addItem(tr("6 Hours"));
76  m_periodCombobox->addItem(tr("12 Hours"));
77  m_periodCombobox->addItem(tr("24 Hours"));
78 
79  connect(m_periodCombobox, qOverload<int>(&QComboBox::currentIndexChanged)
81 
82  m_graphsMenu = new QMenu(this);
83  m_graphsMenu->addAction(tr("Total Upload"));
84  m_graphsMenu->addAction(tr("Total Download"));
85  m_graphsMenu->addAction(tr("Payload Upload"));
86  m_graphsMenu->addAction(tr("Payload Download"));
87  m_graphsMenu->addAction(tr("Overhead Upload"));
88  m_graphsMenu->addAction(tr("Overhead Download"));
89  m_graphsMenu->addAction(tr("DHT Upload"));
90  m_graphsMenu->addAction(tr("DHT Download"));
91  m_graphsMenu->addAction(tr("Tracker Upload"));
92  m_graphsMenu->addAction(tr("Tracker Download"));
93 
94  m_graphsMenuActions = m_graphsMenu->actions();
95 
96  for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
97  {
98  QAction *action = m_graphsMenuActions.at(id);
99  action->setCheckable(true);
100  action->setChecked(true);
101  connect(action, &QAction::changed, this, [this, id]() { onGraphChange(id); });
102  }
103 
105  m_graphsButton->addItem(tr("Select Graphs"));
106 
107  m_hlayout->addWidget(m_periodLabel);
108  m_hlayout->addWidget(m_periodCombobox);
109  m_hlayout->addStretch();
110  m_hlayout->addWidget(m_graphsButton);
111 
112  m_plot = new SpeedPlotView(this);
114 
115  m_layout->addLayout(m_hlayout);
116  m_layout->addWidget(m_plot);
117 
118  loadSettings();
119 
120  m_plot->show();
121 }
static Session * instance()
Definition: session.cpp:997
QComboBox * m_periodCombobox
Definition: speedwidget.h:75
QList< QAction * > m_graphsMenuActions
Definition: speedwidget.h:80
SpeedPlotView * m_plot
Definition: speedwidget.h:76
QHBoxLayout * m_hlayout
Definition: speedwidget.h:73
void loadSettings()
QMenu * m_graphsMenu
Definition: speedwidget.h:79
ComboBoxMenuButton * m_graphsButton
Definition: speedwidget.h:78
void onPeriodChange(int period)
QVBoxLayout * m_layout
Definition: speedwidget.h:72
QLabel * m_periodLabel
Definition: speedwidget.h:74
void onGraphChange(int id)
action
Definition: tstool.py:143

References tstool::action, BitTorrent::Session::instance(), loadSettings(), m_graphsButton, m_graphsMenu, m_graphsMenuActions, m_hlayout, m_layout, m_periodCombobox, m_periodLabel, m_plot, SpeedPlotView::NB_GRAPHS, onGraphChange(), onPeriodChange(), BitTorrent::Session::statsUpdated(), SpeedPlotView::UP, and update().

Here is the call graph for this function:

◆ ~SpeedWidget()

SpeedWidget::~SpeedWidget ( )

Definition at line 123 of file speedwidget.cpp.

124 {
125  qDebug("SpeedWidget::~SpeedWidget() ENTER");
126  saveSettings();
127  qDebug("SpeedWidget::~SpeedWidget() EXIT");
128 }
void saveSettings() const

References saveSettings().

Here is the call graph for this function:

Member Function Documentation

◆ loadSettings()

void SpeedWidget::loadSettings ( )
private

Definition at line 160 of file speedwidget.cpp.

161 {
162  Preferences *preferences = Preferences::instance();
163 
164  int periodIndex = preferences->getSpeedWidgetPeriod();
165  m_periodCombobox->setCurrentIndex(periodIndex);
166  onPeriodChange(static_cast<SpeedPlotView::TimePeriod>(periodIndex));
167 
168  for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
169  {
170  QAction *action = m_graphsMenuActions.at(id);
171  bool enable = preferences->getSpeedWidgetGraphEnable(id);
172 
173  action->setChecked(enable);
174  m_plot->setGraphEnable(static_cast<SpeedPlotView::GraphID>(id), enable);
175  }
176 }
static Preferences * instance()
bool getSpeedWidgetGraphEnable(int id) const
int getSpeedWidgetPeriod() const
void setGraphEnable(GraphID id, bool enable)

References tstool::action, Preferences::getSpeedWidgetGraphEnable(), Preferences::getSpeedWidgetPeriod(), Preferences::instance(), m_graphsMenuActions, m_periodCombobox, m_plot, SpeedPlotView::NB_GRAPHS, onPeriodChange(), SpeedPlotView::setGraphEnable(), and SpeedPlotView::UP.

Referenced by SpeedWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onGraphChange

void SpeedWidget::onGraphChange ( int  id)
privateslot

Definition at line 154 of file speedwidget.cpp.

155 {
156  QAction *action = m_graphsMenuActions.at(id);
157  m_plot->setGraphEnable(static_cast<SpeedPlotView::GraphID>(id), action->isChecked());
158 }

References tstool::action, m_graphsMenuActions, m_plot, and SpeedPlotView::setGraphEnable().

Referenced by SpeedWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onPeriodChange

void SpeedWidget::onPeriodChange ( int  period)
privateslot

Definition at line 149 of file speedwidget.cpp.

150 {
151  m_plot->setPeriod(static_cast<SpeedPlotView::TimePeriod>(period));
152 }
void setPeriod(TimePeriod period)

References m_plot, and SpeedPlotView::setPeriod().

Referenced by loadSettings(), and SpeedWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveSettings()

void SpeedWidget::saveSettings ( ) const
private

Definition at line 178 of file speedwidget.cpp.

179 {
180  Preferences *preferences = Preferences::instance();
181 
182  preferences->setSpeedWidgetPeriod(m_periodCombobox->currentIndex());
183 
184  for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
185  {
186  QAction *action = m_graphsMenuActions.at(id);
187  preferences->setSpeedWidgetGraphEnable(id, action->isChecked());
188  }
189 }
void setSpeedWidgetPeriod(int period)
void setSpeedWidgetGraphEnable(int id, bool enable)

References tstool::action, Preferences::instance(), m_graphsMenuActions, m_periodCombobox, SpeedPlotView::NB_GRAPHS, Preferences::setSpeedWidgetGraphEnable(), Preferences::setSpeedWidgetPeriod(), and SpeedPlotView::UP.

Referenced by ~SpeedWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update

void SpeedWidget::update ( )
privateslot

Definition at line 130 of file speedwidget.cpp.

131 {
133 
134  SpeedPlotView::SampleData sampleData;
135  sampleData[SpeedPlotView::UP] = btStatus.uploadRate;
136  sampleData[SpeedPlotView::DOWN] = btStatus.downloadRate;
137  sampleData[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate;
138  sampleData[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate;
139  sampleData[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate;
141  sampleData[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate;
142  sampleData[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate;
143  sampleData[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate;
144  sampleData[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate;
145 
146  m_plot->pushPoint(sampleData);
147 }
const SessionStatus & status() const
Definition: session.cpp:4301
void pushPoint(const SampleData &point)
std::array< quint64, NB_GRAPHS > SampleData
Definition: speedplotview.h:80

References SpeedPlotView::DHT_DOWN, SpeedPlotView::DHT_UP, BitTorrent::SessionStatus::dhtDownloadRate, BitTorrent::SessionStatus::dhtUploadRate, SpeedPlotView::DOWN, BitTorrent::SessionStatus::downloadRate, BitTorrent::Session::instance(), BitTorrent::SessionStatus::ipOverheadDownloadRate, BitTorrent::SessionStatus::ipOverheadUploadRate, m_plot, SpeedPlotView::OVERHEAD_DOWN, SpeedPlotView::OVERHEAD_UP, SpeedPlotView::PAYLOAD_DOWN, SpeedPlotView::PAYLOAD_UP, BitTorrent::SessionStatus::payloadDownloadRate, BitTorrent::SessionStatus::payloadUploadRate, SpeedPlotView::pushPoint(), BitTorrent::Session::status(), SpeedPlotView::TRACKER_DOWN, SpeedPlotView::TRACKER_UP, BitTorrent::SessionStatus::trackerDownloadRate, BitTorrent::SessionStatus::trackerUploadRate, SpeedPlotView::UP, and BitTorrent::SessionStatus::uploadRate.

Referenced by SpeedWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_graphsButton

ComboBoxMenuButton* SpeedWidget::m_graphsButton
private

Definition at line 78 of file speedwidget.h.

Referenced by SpeedWidget().

◆ m_graphsMenu

QMenu* SpeedWidget::m_graphsMenu
private

Definition at line 79 of file speedwidget.h.

Referenced by SpeedWidget().

◆ m_graphsMenuActions

QList<QAction *> SpeedWidget::m_graphsMenuActions
private

Definition at line 80 of file speedwidget.h.

Referenced by loadSettings(), onGraphChange(), saveSettings(), and SpeedWidget().

◆ m_hlayout

QHBoxLayout* SpeedWidget::m_hlayout
private

Definition at line 73 of file speedwidget.h.

Referenced by SpeedWidget().

◆ m_layout

QVBoxLayout* SpeedWidget::m_layout
private

Definition at line 72 of file speedwidget.h.

Referenced by SpeedWidget().

◆ m_periodCombobox

QComboBox* SpeedWidget::m_periodCombobox
private

Definition at line 75 of file speedwidget.h.

Referenced by loadSettings(), saveSettings(), and SpeedWidget().

◆ m_periodLabel

QLabel* SpeedWidget::m_periodLabel
private

Definition at line 74 of file speedwidget.h.

Referenced by SpeedWidget().

◆ m_plot

SpeedPlotView* SpeedWidget::m_plot
private

Definition at line 76 of file speedwidget.h.

Referenced by loadSettings(), onGraphChange(), onPeriodChange(), SpeedWidget(), and update().


The documentation for this class was generated from the following files: