Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics dialog improvements and bug fixes #702

Merged
merged 7 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plotjuggler_app/plot_docker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ DockWidget::DockWidget(PlotDataMapRef& datamap, QWidget* parent)

connect(_plot_widget, &PlotWidget::splitVertical, this, &DockWidget::splitVertical);

connect(_toolbar, &DockToolbar::titleChanged,_plot_widget,[=](QString title){_plot_widget->setStatisticsTitle(title);});

auto FullscreenAction = [=]() {
PlotDocker* parent_docker = static_cast<PlotDocker*>(dockManager());
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_app/plot_docker_toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ bool DockToolbar::eventFilter(QObject* object, QEvent* event)
if (ok)
{
ui->label->setText(newName);
emit titleChanged(newName);
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_app/plot_docker_toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public slots:

signals:
void backgroundColorRequest(QString name);
void titleChanged(QString title);
private slots:
void on_buttonBackground_clicked();
};
Expand Down
33 changes: 27 additions & 6 deletions plotjuggler_app/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ void PlotWidget::setZoomRectangle(QRectF rect, bool emit_signal)
emit rectChanged(this, rect);
}
}
updateStatistics();
}

void PlotWidget::reloadPlotData()
Expand Down Expand Up @@ -1121,11 +1122,18 @@ void PlotWidget::updateCurves(bool reset_older_data)
}
updateMaximumZoomArea();

if(_statistics_dialog)
{
auto rect = canvasBoundingRect();
_statistics_dialog->update( {rect.left(), rect.right()} );
}
updateStatistics(true);
}

void PlotWidget::updateStatistics(bool forceUpdate){
if(_statistics_dialog)
{
if(_statistics_dialog->calcVisibleRange() || forceUpdate){
auto rect = canvasBoundingRect();
_statistics_dialog->update( {rect.left(), rect.right()} );
}
}

}

void PlotWidget::on_changeCurveColor(const QString& curve_name, QColor new_color)
Expand Down Expand Up @@ -1218,12 +1226,23 @@ void PlotWidget::onBackgroundColorRequest(QString name)
}
}

void PlotWidget::setStatisticsTitle(QString title){
_statistics_window_title = title;

if(_statistics_dialog)
{
_statistics_dialog->setTitle(_statistics_window_title);
}
}

void PlotWidget::onShowDataStatistics()
{
if (!_statistics_dialog) {
_statistics_dialog = new StatisticsDialog(this);
}

setStatisticsTitle(_statistics_window_title);

auto rect = canvasBoundingRect();
_statistics_dialog->update( {rect.left(), rect.right()} );
_statistics_dialog->show();
Expand All @@ -1239,7 +1258,7 @@ void PlotWidget::onShowDataStatistics()
connect(this, &PlotWidget::rectChanged, _statistics_dialog,
[=](PlotWidget*, QRectF rect)
{
_statistics_dialog->update( {rect.left(), rect.right()} );
_statistics_dialog->update( {rect.left(), rect.right()} );
});

connect(_statistics_dialog, &QDialog::rejected,
Expand Down Expand Up @@ -1271,6 +1290,8 @@ void PlotWidget::zoomOut(bool emit_signal)
updateMaximumZoomArea();
setZoomRectangle(maxZoomRect(), emit_signal);
replot();

updateStatistics();
}

void PlotWidget::on_zoomOutHorizontal_triggered(bool emit_signal)
Expand Down
6 changes: 6 additions & 0 deletions plotjuggler_app/plotwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class PlotWidget : public PlotWidgetBase

bool isZoomLinkEnabled() const;

void setStatisticsTitle(QString title);

void updateStatistics(bool forceUpdate = false);

protected:
PlotDataMapRef& _mapped_data;

Expand Down Expand Up @@ -180,6 +184,8 @@ private slots:
CurveTracker* _tracker;
QwtPlotGrid* _grid;

QString _statistics_window_title = "";

std::unique_ptr<BackgroundColorItem> _background_item;

bool _use_date_time_scale;
Expand Down
23 changes: 23 additions & 0 deletions plotjuggler_app/resources/stylesheet_dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,29 @@ QHeaderView::section {
border: 1px solid #6c6c6c;
}

QHeaderView::text{
padding-left: 4px;
padding-right: 4px;
}

QHeaderView::up-arrow {
subcontrol-position: center right;
image: url(":/style_${theme}/arrow_up.png");
height: 12px;
width: 12px;
padding-left: 4px;
padding-right: 4px;
}

QHeaderView::down-arrow {
subcontrol-position: center right;
image: url(":/style_${theme}/arrow_down.png");
height: 12px;
width: 12px;
padding-left: 4px;
padding-right: 4px;
}

QTreeView:branch {
background-color: transparent;
}
Expand Down
23 changes: 23 additions & 0 deletions plotjuggler_app/resources/stylesheet_light.qss
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,29 @@ QHeaderView::section {
border: 1px solid #6c6c6c;
}

QHeaderView::text{
padding-left: 4px;
padding-right: 4px;
}

QHeaderView::up-arrow {
subcontrol-position: center right;
image: url(":/style_${theme}/arrow_up.png");
height: 12px;
width: 12px;
padding-left: 4px;
padding-right: 4px;
}

QHeaderView::down-arrow {
subcontrol-position: center right;
image: url(":/style_${theme}/arrow_down.png");
height: 12px;
width: 12px;
padding-left: 4px;
padding-right: 4px;
}

QTreeView:branch {
background-color: transparent;
}
Expand Down
37 changes: 28 additions & 9 deletions plotjuggler_app/statistics_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ StatisticsDialog::StatisticsDialog(PlotWidget *parent) :
{
ui->setupUi(this);

setWindowTitle(QString("Statistics: %1").arg(_parent->windowTitle()));
setWindowFlag(Qt::WindowStaysOnTopHint);
setWindowTitle(QString("Statistics | %1").arg(_parent->windowTitle()));
setWindowFlag(Qt::Tool);

ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

connect(ui->rangeComboBox,qOverload<int>(&QComboBox::currentIndexChanged),this,[this](){
auto rect = _parent->canvasBoundingRect();
update({rect.left(), rect.right()});
});

}

StatisticsDialog::~StatisticsDialog()
{
delete ui;
}

bool StatisticsDialog::calcVisibleRange(){
return (ui->rangeComboBox->currentIndex() == 0);
}

void StatisticsDialog::update(PJ::Range range)
{
std::map<QString, Statistics> statistics;
Expand All @@ -41,13 +51,15 @@ void StatisticsDialog::update(PJ::Range range)
for( size_t i=0; i<ts->size(); i++)
{
const auto p = ts->sample(i);
if( p.x() < range.min )
{
continue;
}
if( p.x() > range.max )
{
break;
if(calcVisibleRange()){
if( p.x() < range.min )
{
continue;
}
if( p.x() > range.max )
{
break;
}
}
stat.count++;
if( first )
Expand Down Expand Up @@ -93,6 +105,13 @@ void StatisticsDialog::update(PJ::Range range)
}
}

void StatisticsDialog::setTitle(QString title){
if(title == "..."){
title = "";
}
setWindowTitle(QString("Statistics | %1").arg(title));
}

void StatisticsDialog::closeEvent(QCloseEvent *event)
{
QWidget::closeEvent(event);
Expand Down
4 changes: 4 additions & 0 deletions plotjuggler_app/statistics_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class StatisticsDialog : public QDialog

void closeEvent(QCloseEvent *event);

void setTitle(QString title);

bool calcVisibleRange();

private:
Ui::statistics_dialog *ui;

Expand Down
74 changes: 66 additions & 8 deletions plotjuggler_app/statistics_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
Expand Down Expand Up @@ -50,14 +53,69 @@
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<family>Segoe UI</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>Calculate statistics from: </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="rangeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>125</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>Segoe UI</family>
<pointsize>9</pointsize>
</font>
</property>
<item>
<property name="text">
<string>Visible Range</string>
</property>
</item>
<item>
<property name="text">
<string>Full Range</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="font">
<font>
<family>Segoe UI</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down