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) bool ftServer::ExtraFileRemove(const RsFileHash& hash)
{ return mFileDatabase->removeExtraFile(hash); } { return mFileDatabase->removeExtraFile(hash); }
bool ftServer::ExtraFileHash( bool ftServer::ExtraFileHash( std::string localpath, rstime_t period, TransferRequestFlags flags )
std::string localpath, rstime_t period, TransferRequestFlags flags )
{ {
constexpr rstime_t uintmax = std::numeric_limits<uint32_t>::max(); constexpr rstime_t uintmax = std::numeric_limits<uint32_t>::max();
if(period > uintmax) if(period > uintmax)

View file

@ -80,14 +80,26 @@ void BWGraphSource::update()
std::cerr << " visible service: " << std::dec << mVisibleServices.size() << std::endl; std::cerr << " visible service: " << std::dec << mVisibleServices.size() << std::endl;
#endif #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 ; std::map<std::string,float> vals ;
if(_current_direction == BWGraphSource::DIRECTION_UP) if(_current_direction == (DIRECTION_UP | DIRECTION_DOWN))
convertTrafficClueToValues(thc.out_rstcl,vals) ; {
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 else
convertTrafficClueToValues(thc.in_rstcl,vals) ; convertTrafficClueToValues(thc.in_rstcl,vals) ;
qint64 ms = getTime() ; 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 void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& lst,std::map<std::string,float>& vals) const
{ {
vals.clear() ;
switch(_friend_graph_type) switch(_friend_graph_type)
{ {
case GRAPH_TYPE_SINGLE: case GRAPH_TYPE_SINGLE:
@ -555,9 +565,18 @@ void BWGraphSource::recomputeCurrentCurves()
std::set<std::string> unused_values = used_values_ref ; std::set<std::string> unused_values = used_values_ref ;
if(_current_direction==DIRECTION_UP) if(_current_direction == (DIRECTION_UP | DIRECTION_DOWN))
convertTrafficClueToValues((*it).out_rstcl,vals) ; {
else 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) ; convertTrafficClueToValues((*it).in_rstcl,vals) ;
for(std::map<std::string,float>::iterator it2=vals.begin();it2!=vals.end();++it2) 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 { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 }; enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
enum { UNIT_KILOBYTES=0x00, UNIT_COUNT=0x01 }; 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 // re-derived from RSGraphSource
@ -113,6 +113,8 @@ class BWGraph: public RSGraphWidget
void setDirection(int dir) { _local_source->setDirection(dir); } void setDirection(int dir) { _local_source->setDirection(dir); }
void setUnit(int unit) { _local_source->setUnit(unit) ;} 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::map<RsPeerId,std::string>& visibleFriends() const { return _local_source->visibleFriends(); }
const std::set<uint16_t>& visibleServices() const { return _local_source->visibleServices(); } const std::set<uint16_t>& visibleServices() const { return _local_source->visibleServices(); }
protected: protected:

View file

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

View file

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