I have been removing a lot of old JSON stuff which is now replaced with Wt::Dbo. So far, using Wt::Dbo has offered so much of convenience when adding, modifying or querying database objects, as long as you create the Wt::Dbo::Session using your database file.

insertWidget at specified positions

So I have taken the advice from Dr. Shawn to make some improvements on my project. When adding new files into the application, the newest file should appear at the first position. I fumbled around the WContainerWidget member functions and tried insertBefore(). However, this required the WWidget* which is followed after it. I tried to apply some code logic to find the WWidget* but it became so messy. Instead, I found out about insertWidget(), which actually allows you to insert the Widget at given positions(index). There is probably an automatic indexing built in when user adds a Widget into a Container. insertWidget() actually allows the Widget to be placed at the specified index while pushing all the previous Widgets backwards.

There is also another method of sorting the project files, which is through sql commands. Since I am querying the Dbo to list out the projects in a certain order, I can just add a simple line in the query.

Projects projects_ = sessiontest->find("where user_id = ? order by last_modified desc").bind(user.id());

Then in the iteration, it will give me the pointer to the latest project file which I modified. Of course, this requires the last_modified column to be constantly updated and the format to be correct. Wt::WDateTime can be used as a data type which mapping its value. However, I had problem using WLocalDateTime for it. As I preferred using a localTime anyway, I made some adjustments.

Wt::WDateTime dateTime = Wt::WDateTime::currentDateTime();
int offset = Wt::WApplication::instance()->environment().timeZoneOffset()*60;
std::string name = "MyProject-"+dateTime.addSecs(offset).toString().toUTF8();

This was how I changed the WDateTime to WLocalDateTime because somehow the WDateTime.toCurrentDateTime() did not work out for me.

Working with JSlot

So I was facing this Popup Blocked prompt from Chrome whenever I try to open a new window in my Application. The problem would be easily mitigated if I used a Wt::WAnchor instead. However, I needed the window to open when I double-clicked on it while WAnchor would only work for single clicks.

What was causing the popup block was actually the way the window.open was triggered. I attached a onDoubleClicked event on the Widget where in the event handler was a doJavaScript() function. This somehow cause the window.open not to be directly triggered by the user click, thus prompting the user.

That’s when I found out about JSlot. After playing around with it, I finally worked something which did the job.
Wt::JSlot myJSFunc2;
std::string js;
js = "function(){window.open('http://www.google.com','_blank')};";
myJSFunc2 = new Wt::JSlot(js);

And voila, praise the Wt authors.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.