Skip to content

Commit a2089ca

Browse files
committed
[tqweb] add canvas update demo
With extra check box one can enable regular fill and update histogram
1 parent 4ebb879 commit a2089ca

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

tutorials/visualisation/webgui/qtweb/ExampleWidget.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ExampleWidget::ExampleWidget(QWidget *parent, const char *name) : QWidget(parent
3939
QObject::connect(GeoCanvasBtn, &QPushButton::clicked, this, &ExampleWidget::GeoCanvasButton_clicked);
4040
QObject::connect(StandaloneBtn, &QPushButton::clicked, this, &ExampleWidget::StandaloneBtn_clicked);
4141
QObject::connect(ExitBtn, &QPushButton::clicked, this, &ExampleWidget::ExitButton_clicked);
42+
QObject::connect(fxUpdateChk, &QCheckBox::toggled, this, &ExampleWidget::UpdateChk_toggled);
4243

4344
setAttribute(Qt::WA_DeleteOnClose);
4445

@@ -51,7 +52,7 @@ ExampleWidget::ExampleWidget(QWidget *parent, const char *name) : QWidget(parent
5152
fHisto->SetDirectory(nullptr);
5253

5354
gPad = fxTCanvasWidget->getCanvas();
54-
fHisto->Draw();
55+
fHisto->Draw("hist");
5556

5657
static constexpr int nth2points = 40;
5758
fHisto2 = std::make_shared<TH2I>("gaus2", "Example of TH2 drawing in RCanvas", nth2points, -5, 5, nth2points, -5, 5);
@@ -71,6 +72,23 @@ ExampleWidget::ExampleWidget(QWidget *parent, const char *name) : QWidget(parent
7172

7273
ExampleWidget::~ExampleWidget() {}
7374

75+
void ExampleWidget::UpdateChk_toggled(bool on)
76+
{
77+
if (on) {
78+
// enable modify of canvas every 100 ms
79+
QObject::connect(&fTimer, &QTimer::timeout, [&]() {
80+
fHisto->FillRandom("gaus", 1000);
81+
fxTCanvasWidget->getCanvas()->Modified();
82+
fxTCanvasWidget->getCanvas()->Update();
83+
});
84+
fTimer.setSingleShot(false);
85+
fTimer.start(100);
86+
} else {
87+
fTimer.stop();
88+
}
89+
}
90+
91+
7492
void ExampleWidget::CreateDummyGeometry()
7593
{
7694
auto viewer = fxGeomViewerWidget->getGeomViewer();

tutorials/visualisation/webgui/qtweb/ExampleWidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define ExampleWidget_h
1313

1414
#include <QWidget>
15+
#include <QTimer>
1516
#include "ui_ExampleWidget.h"
1617

1718
#include <memory>
@@ -25,6 +26,7 @@ class ExampleWidget : public QWidget, public Ui::ExampleWidget {
2526
protected:
2627
TH1F *fHisto{nullptr}; ///< histogram for display in TCanvas
2728
std::shared_ptr<TH2I> fHisto2; ///< histogram for display in RCanvas
29+
QTimer fTimer;
2830

2931
void ImportCmsGeometry();
3032

@@ -44,6 +46,7 @@ public slots:
4446
void GeoCanvasButton_clicked();
4547
void StandaloneBtn_clicked();
4648
void ExitButton_clicked();
49+
void UpdateChk_toggled(bool);
4750
};
4851

4952
#endif

tutorials/visualisation/webgui/qtweb/ExampleWidget.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@
142142
<number>2</number>
143143
</property>
144144
<item row="0" column="0" >
145+
<widget class="QCheckBox" name="fxUpdateChk" >
146+
<property name="text" >
147+
<string>update canvas</string>
148+
</property>
149+
</widget>
150+
</item>
151+
<item row="1" column="0" >
145152
<widget class="TCanvasWidget" name="fxTCanvasWidget" >
146153
<property name="sizePolicy" >
147154
<sizepolicy>

0 commit comments

Comments
 (0)