|
#include <Wt/Chart/WCartesianChart.h>
|
|
#include <Wt/WApplication.h>
|
|
#include <Wt/WEnvironment.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WStandardItem.h>
|
|
#include <Wt/WStandardItemModel.h>
|
|
#include <Wt/WText.h>
|
|
#include <Wt/WVBoxLayout.h>
|
|
|
|
using namespace Wt;
|
|
using namespace std;
|
|
|
|
class TestApp : public WApplication {
|
|
public:
|
|
TestApp(const WEnvironment& env);
|
|
void testWindow();
|
|
private:
|
|
int windowInstance_ = 0;
|
|
};
|
|
|
|
void TestApp::testWindow()
|
|
{
|
|
auto topLayout = make_unique<WVBoxLayout>();
|
|
topLayout->setPreferredImplementation(LayoutImplementation::JavaScript);
|
|
|
|
auto model = make_shared<WStandardItemModel>(10, 2);
|
|
for (int i = 0; i < model->rowCount(); ++i) {
|
|
model->setData(model->index(i, 0), i);
|
|
model->setData(model->index(i, 1), rand() % 1000);
|
|
model->setData(model->index(i, 1), "Index: " + to_string(i), ItemDataRole::ToolTip);
|
|
#if 0 // NOTE: no oscillations with deferred tooltips (or tooltips disabled...)
|
|
model->item(i, 1)->setFlags(ItemFlag::DeferredToolTip);
|
|
#endif
|
|
}
|
|
auto chart = make_unique<Chart::WCartesianChart>(Chart::ChartType::Scatter);
|
|
chart->setModel(model);
|
|
chart->setXSeriesColumn(0);
|
|
chart->addSeries(make_unique<Chart::WDataSeries>(1, Chart::SeriesType::Point));
|
|
topLayout->addWidget(move(chart), 1);
|
|
topLayout->addWidget(move(make_unique<WText>("<p>Some footer text...</p>")), 0);
|
|
root()->setLayout(move(topLayout));
|
|
}
|
|
|
|
TestApp::TestApp(const WEnvironment& env) : WApplication(env)
|
|
{
|
|
auto param = env.getParameter("p");
|
|
setTitle(string("Oscillation Test") + (param ? (" Window " + *param) : ""));
|
|
|
|
if (param)
|
|
testWindow();
|
|
else {
|
|
root()->addWidget(move(make_unique<WText>("<p>Push button to open window.</p>"
|
|
"<p>Watch for oscillations in Chrome at different zoom levels, e.g. 110%.</p>")));
|
|
auto button = root()->addWidget(make_unique<WPushButton>("Open window"));
|
|
|
|
button->clicked().connect([=] {
|
|
WString url = wApp->resolveRelativeUrl("?p=" + to_string(++windowInstance_));
|
|
button->doJavaScript("window.open(" + url.jsStringLiteral() + ", 'Test Window " +
|
|
to_string(windowInstance_) + "', 'height=389,width=400');");
|
|
});
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, [](const WEnvironment& env) {return make_unique<TestApp>(env);});
|
|
}
|