fixed bw graph window to display both up+dn

This commit is contained in:
csoler 2021-01-31 23:28:15 +01:00
parent 60893e2344
commit f61b37e10b
5 changed files with 78 additions and 106 deletions

View File

@ -819,8 +819,7 @@ bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t
bool ftServer::ExtraFileRemove(const RsFileHash& hash)
{ return mFileDatabase->removeExtraFile(hash); }
bool ftServer::ExtraFileHash(
std::string localpath, rstime_t period, TransferRequestFlags flags )
bool ftServer::ExtraFileHash( std::string localpath, rstime_t period, TransferRequestFlags flags )
{
constexpr rstime_t uintmax = std::numeric_limits<uint32_t>::max();
if(period > uintmax)

View File

@ -80,14 +80,26 @@ void BWGraphSource::update()
std::cerr << " visible service: " << std::dec << mVisibleServices.size() << std::endl;
#endif
// now, convert data to current curve points.
// Now, convert latest data measurement into points. convertTrafficToValues() returns
// a map of values corresponding to the latest point in time, doing all the requested calculations
// (sum over friends, sum over services, etc).
//
std::map<std::string,float> vals ;
if(_current_direction == BWGraphSource::DIRECTION_UP)
convertTrafficClueToValues(thc.out_rstcl,vals) ;
if(_current_direction == (DIRECTION_UP | DIRECTION_DOWN))
{
std::map<std::string,float> vals1,vals2 ;
convertTrafficClueToValues(thc.out_rstcl,vals1) ;
convertTrafficClueToValues(thc.in_rstcl,vals2) ;
for(auto it:vals1) vals[it.first + " (sent)"] = it.second;
for(auto it:vals2) vals[it.first + " (received)"] = it.second;
}
else if(_current_direction & DIRECTION_UP)
convertTrafficClueToValues(thc.out_rstcl,vals) ;
else
convertTrafficClueToValues(thc.in_rstcl,vals) ;
convertTrafficClueToValues(thc.in_rstcl,vals) ;
qint64 ms = getTime() ;
@ -217,8 +229,6 @@ std::string BWGraphSource::makeSubItemName(uint16_t service_id,uint8_t sub_item_
void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& lst,std::map<std::string,float>& vals) const
{
vals.clear() ;
switch(_friend_graph_type)
{
case GRAPH_TYPE_SINGLE:
@ -555,9 +565,18 @@ void BWGraphSource::recomputeCurrentCurves()
std::set<std::string> unused_values = used_values_ref ;
if(_current_direction==DIRECTION_UP)
convertTrafficClueToValues((*it).out_rstcl,vals) ;
else
if(_current_direction == (DIRECTION_UP | DIRECTION_DOWN))
{
std::map<std::string,float> vals1,vals2 ;
convertTrafficClueToValues((*it).out_rstcl,vals1) ;
convertTrafficClueToValues((*it).in_rstcl,vals2) ;
for(auto it:vals1) vals[it.first + " (sent)"] = it.second;
for(auto it:vals2) vals[it.first + " (received)"] = it.second;
}
else if(_current_direction & DIRECTION_UP)
convertTrafficClueToValues((*it).out_rstcl,vals) ;
else
convertTrafficClueToValues((*it).in_rstcl,vals) ;
for(std::map<std::string,float>::iterator it2=vals.begin();it2!=vals.end();++it2)

View File

@ -48,7 +48,7 @@ public:
enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
enum { UNIT_KILOBYTES=0x00, UNIT_COUNT=0x01 };
enum { DIRECTION_UP=0x02, DIRECTION_DOWN=0x01 };
enum { DIRECTION_DOWN=0x01,DIRECTION_UP=0x02 }; // can be combined using binary ops
// re-derived from RSGraphSource
@ -113,6 +113,8 @@ class BWGraph: public RSGraphWidget
void setDirection(int dir) { _local_source->setDirection(dir); }
void setUnit(int unit) { _local_source->setUnit(unit) ;}
int direction() const { return _local_source->direction(); }
const std::map<RsPeerId,std::string>& visibleFriends() const { return _local_source->visibleFriends(); }
const std::set<uint16_t>& visibleServices() const { return _local_source->visibleServices(); }
protected:

View File

@ -105,7 +105,11 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
ui.chkReceiveRate->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_RECEIVE));
ui.chkReceiveRate->setText("");
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_LIGHT));
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.frmGraph->setToolTip("Use Ctrl+mouse wheel to change line width, Shift+wheel to time-filter the curve.");
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP | BWGraphSource::DIRECTION_DOWN);
loadSettings();
@ -119,21 +123,13 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
void BandwidthGraph::toggleSendRate(bool b)
{
whileBlocking(ui.chkReceiveRate)->setChecked(!b);
if(b)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
else
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
ui.frmGraph->setShowEntry(0,b);
saveSettings();
}
void BandwidthGraph::toggleReceiveRate(bool b)
{
whileBlocking(ui.chkSendRate)->setChecked(!b);
if(b)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
else
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
ui.frmGraph->setShowEntry(1,b);
saveSettings();
}
@ -149,6 +145,8 @@ void BandwidthGraph::switchGraphColor()
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_DARK));
}
saveSettings();
}
/** Loads the saved Bandwidth Graph settings. */
@ -159,60 +157,29 @@ BandwidthGraph::loadSettings()
ui.sldrOpacity->setValue(getSetting(SETTING_OPACITY, DEFAULT_OPACITY).toInt());
setOpacity(ui.sldrOpacity->value());
/* Set the line filter checkboxes accordingly */
uint filter = getSetting(SETTING_FILTER, DEFAULT_FILTER).toUInt();
ui.chkReceiveRate->setChecked(filter & BWGRAPH_LINE_RECV);
ui.chkSendRate->setChecked(filter & BWGRAPH_LINE_SEND);
/* Set whether we are plotting bandwidth as area graphs or not */
int graphStyle = getSetting(SETTING_STYLE, DEFAULT_STYLE).toInt();
// if (graphStyle < 0 || graphStyle >= ui.cmbGraphStyle->count()) {
// graphStyle = DEFAULT_STYLE;
// }
// ui.cmbGraphStyle->setCurrentIndex(graphStyle);
if(graphStyle==0)
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
else
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
/* Set whether we are plotting bandwidth as area graphs or not */
int graphColor = getSetting(SETTING_GRAPHCOLOR, DEFAULT_GRAPHCOLOR).toInt();
if(graphColor>0)
{
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_DARK));
}
else
{
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_LIGHT));
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
}
/* Download & Upload */
int defaultdirection = getSetting(SETTING_DIRECTION, DEFAULT_DIRECTION).toInt();
// if (defaultdirection < 0 || defaultdirection >= ui.cmbDownUp->count()) {
// defaultdirection = DEFAULT_DIRECTION;
// }
// ui.cmbDownUp->setCurrentIndex(graphColor);
if(defaultdirection>0)
{
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
whileBlocking(ui.chkSendRate)->setChecked(false);
whileBlocking(ui.chkReceiveRate)->setChecked(true);
}
else
{
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
whileBlocking(ui.chkSendRate)->setChecked(true);
whileBlocking(ui.chkReceiveRate)->setChecked(false);
}
whileBlocking(ui.chkSendRate )->setChecked(bool(defaultdirection & BWGraphSource::DIRECTION_UP ));
whileBlocking(ui.chkReceiveRate)->setChecked(bool(defaultdirection & BWGraphSource::DIRECTION_DOWN));
/* Default Settings for the Graph */
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP | BWGraphSource::DIRECTION_DOWN);
ui.frmGraph->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SUM) ;
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LOG_SCALE_Y) ;
@ -230,56 +197,41 @@ void BandwidthGraph::reset()
ui.frmGraph->resetGraph();
}
/** Saves the Bandwidth Graph settings and adjusts the graph if necessary. */
void BandwidthGraph::saveChanges()
BandwidthGraph::~BandwidthGraph()
{
/* Hide the settings frame and reset toggle button */
showSettingsFrame(false);
/* Save the opacity and graph style */
saveSetting(SETTING_OPACITY, ui.sldrOpacity->value());
// saveSetting(SETTING_STYLE, ui.cmbGraphStyle->currentIndex());
saveSetting(SETTING_GRAPHCOLOR, ui.btnGraphColor->isChecked());
saveSettings();
}
/** Saves the Bandwidth Graph settings and adjusts the graph if necessary. */
void BandwidthGraph::saveSettings()
{
/* Save the opacity and graph style */
saveSetting(SETTING_OPACITY, ui.sldrOpacity->value());
saveSetting(SETTING_GRAPHCOLOR, ui.btnGraphColor->isChecked());
/* Save the Always On Top setting */
saveSetting(SETTING_ALWAYS_ON_TOP, ui.chkAlwaysOnTop->isChecked());
if (ui.chkAlwaysOnTop->isChecked()) {
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
} else {
setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
}
setOpacity(ui.sldrOpacity->value());
/* Save the Always On Top setting */
saveSetting(SETTING_ALWAYS_ON_TOP, ui.chkAlwaysOnTop->isChecked());
/* Save the line filter values */
uint filter = 0;
ADD_TO_FILTER(filter, BWGRAPH_LINE_RECV, ui.chkReceiveRate->isChecked());
ADD_TO_FILTER(filter, BWGRAPH_LINE_SEND, ui.chkSendRate->isChecked());
saveSetting(SETTING_FILTER, filter);
/* Save the line filter values */
saveSetting(SETTING_DIRECTION, ui.frmGraph->direction());
/* Update the graph frame settings */
// ui.frmGraph->setShowEntry(0,ui.chkReceiveRate->isChecked()) ;
// ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
// ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
/* Update the graph frame settings */
ui.frmGraph->setShowEntry(0,ui.chkReceiveRate->isChecked()) ;
ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
// if(ui.btnGraphColor->isChecked()==0)
// ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
// else
// ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
// if(ui.cmbGraphStyle->currentIndex()==0)
// ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
// else
// ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
// if(ui.cmbDownUp->currentIndex()==0)
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
// else
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
if(ui.btnGraphColor->isChecked()==0)
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
else
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
// if(ui.cmbDownUp->currentIndex()==0)
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
// else
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
/* A change in window flags causes the window to disappear, so make sure
/* A change in window flags causes the window to disappear, so make sure
* it's still visible. */
showNormal();
showNormal();
}
/** Simply restores the previously saved settings. */

View File

@ -45,6 +45,7 @@ public:
/** Default constructor */
BandwidthGraph(QWidget *parent = 0, Qt::WindowFlags flags = 0);
virtual ~BandwidthGraph();
public slots:
/** Overloaded QWidget.show */
@ -59,8 +60,6 @@ private slots:
void showSettingsFrame(bool show);
/** Called when the settings button is toggled */
void setOpacity(int value);
/** Called when the user saves settings */
void saveChanges();
/** Called when the user cancels changes settings */
void cancelChanges();
/** Called when the reset button is pressed */
@ -71,6 +70,7 @@ private:
void createActions();
/** Loads the saved Bandwidth Graph settings */
void loadSettings();
void saveSettings();
/** Qt Designer generated object */
Ui::BandwidthGraph ui;