Project

General

Profile

Bug #7811 ยป main.cpp

Apivan Tuntakurn, 11/02/2020 10:02 AM

 
#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WVBoxLayout.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WText.h>
#include <Wt/WBootstrapTheme.h>
#include <boost/thread.hpp>
#include <Wt/WAbstractTableModel.h>
#include <Wt/WApplication.h>
#include <Wt/WEnvironment.h>
#include <Wt/WServer.h>

#include <Wt/WTimer.h>
#include <Wt/WImage.h>
#include <memory>


#include <Wt/WTableView.h>
#include <Wt/WStandardItemModel.h>
#include <Wt/WStandardItem.h>
#include <Wt/WItemDelegate.h>
#include <Wt/WComboBox.h>


using namespace Wt;

class MyTableBenchmarkingAppApplication : public WApplication
{
public:
MyTableBenchmarkingAppApplication(const WEnvironment& env);

};


MyTableBenchmarkingAppApplication::MyTableBenchmarkingAppApplication(const WEnvironment& env)
: WApplication(env)
{


this->enableUpdates(true);
auto theme = std::make_shared<Wt::WBootstrapTheme>();
theme->setVersion(Wt::BootstrapVersion::v3);
setTheme(theme);


setTitle("TableBenchmarkingApp");

class TestWidget : public Wt::WContainerWidget
{
public:
TestWidget() :
m_testSignal(this, "test")
{
m_testSignal.connect([]() {Wt::log("error") << " 1 called"; });

this->setLayoutSizeAware(true);

}

void layoutSizeChanged(int, int) override
{}

void render(Wt::WFlags<Wt::RenderFlag>) override
{
this->doJavaScript(Wt::WString(R"(
function isPrime(num) {
for ( var i = 2; i < num; i++ ) {
if ( num % i === 0 ) {
return false;
}
}
return true;
}

function display(n) {
var arr = [2];
for ( var i = 3; i < n; i+=2 ) {
if ( isPrime(i) ) {
arr.push(i);
}
}
{2}.innerText = arr;
}

{1};
display(200000);





)").arg(m_testSignal.createCall({}))
.arg(this->jsRef()).toUTF8());
}

Wt::JSignal<> m_testSignal;

};




auto rootx = root()->addWidget(std::make_unique<Wt::WContainerWidget>());
auto layout = rootx->setLayout(std::make_unique<Wt::WVBoxLayout>());
layout->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);



auto server = Wt::WApplication::instance()->environment().server();
server->schedule(std::chrono::seconds(2), Wt::WApplication::instance()->sessionId()
, [=]() {

auto text = layout->addWidget(std::make_unique<Wt::WText>("hello"));
layout->addWidget(std::make_unique<TestWidget>());


Wt::WApplication::instance()->triggerUpdate();
});


}



std::unique_ptr<WApplication> createApplication(const WEnvironment& env)
{
return std::make_unique<MyTableBenchmarkingAppApplication>(env);
}

int main(int argc, char** argv)
{


return WRun(argc, argv, &createApplication);
}
    (1-1/1)