diff --git a/README.md b/README.md index 0b04384..3cde32e 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,19 @@ *** -[Download Windows Binaries (64-bits)](https://sourceforge.net/projects/wtdesigner/files/Windowsx64/v.1.0.2/) +[Download Windows Binaries (64-bits)](https://sourceforge.net/projects/wtdesigner/files/Windowsx64/v.1.0.3/) * Install "vcredist_x64.exe" before running WtDesigner for the first time. * Run WtDesigner with Administrator rights in Windows. *** -[Download Linux Binaries (64-bits)](https://sourceforge.net/projects/wtdesigner/files/Linux64/v.1.0.2/) +[Download Linux Binaries (64-bits)](https://sourceforge.net/projects/wtdesigner/files/Linux64/v.1.0.3/) * Might be necessary to: ```bash -$ chmod +x ./WtDesignerInstallerV.1.0.2.run +$ chmod +x ./WtDesignerInstallerV.1.0.3.run ``` * Tested on **CentOS7** and **Ubuntu14.04** @@ -31,6 +31,16 @@ A WYSIWYG (What You See Is What You Get) front-end editor which serves as bride *** +## Who + +List of contributors: + +* [juangburgos](https://github.com/juangburgos). + +* [cls-nebadje](https://github.com/cls-nebadje). + +*** + ## Why Although C++ doesn’t come into mind as the first language for web development, there is a specific number of scenarios in which it can be advantageous with respect to other languages: diff --git a/deploy/README.txt b/deploy/README.txt index 73dbc49..a0a1aec 100644 --- a/deploy/README.txt +++ b/deploy/README.txt @@ -22,7 +22,7 @@ All Generate installer with: -binarycreator --offline-only -c config/config.xml -p packages WtDesignerInstallerV.1.0.2.exe +binarycreator --offline-only -c config/config.xml -p packages WtDesignerInstallerV.1.0.3.exe PATH=$PATH:/home/juangburgos/Qt/QtIFW2.0.1/bin/ -binarycreator --offline-only -c config/config_nix.xml -p packages WtDesignerInstallerV.1.0.2.run +binarycreator --offline-only -c config/config_nix.xml -p packages WtDesignerInstallerV.1.0.3.run diff --git a/deploy/config/config.xml b/deploy/config/config.xml index b75933a..0e8ebad 100644 --- a/deploy/config/config.xml +++ b/deploy/config/config.xml @@ -1,7 +1,7 @@ WtDesigner - 1.0.2 + 1.0.3 WtDesigner (Windows 64-bits) Juan Gonzalez Burgos WtDesigner diff --git a/deploy/config/config_nix.xml b/deploy/config/config_nix.xml index 5852288..0d3906e 100644 --- a/deploy/config/config_nix.xml +++ b/deploy/config/config_nix.xml @@ -1,7 +1,7 @@ WtDesigner - 1.0.2 + 1.0.3 WtDesigner (Linux 64-bit) Juan Gonzalez Burgos WtDesigner diff --git a/deploy/packages/WtDesigner/meta/package.xml b/deploy/packages/WtDesigner/meta/package.xml index 3cd3ae4..8f8e642 100644 --- a/deploy/packages/WtDesigner/meta/package.xml +++ b/deploy/packages/WtDesigner/meta/package.xml @@ -2,8 +2,8 @@ WtDesigner A WYSIWYG designer for the Wt C++ library. - 1.0.2 - 2016-05-16 + 1.0.3 + 2016-06-16 true true diff --git a/src/main/dialogs/dialogabout/dialogabout.ui b/src/main/dialogs/dialogabout/dialogabout.ui index 6fe6b3d..269c820 100644 --- a/src/main/dialogs/dialogabout/dialogabout.ui +++ b/src/main/dialogs/dialogabout/dialogabout.ui @@ -75,7 +75,7 @@ 0 0 384 - 499 + 506 @@ -99,9 +99,14 @@ p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial,Helvetica,sans'; font-size:16pt; font-weight:600; color:#e1e1e1;">WtDesigner v.1.0.2</span></p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial,Helvetica,sans'; font-size:16pt; font-weight:600; color:#e1e1e1;">WtDesigner v.1.0.3</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt; color:#e1e1e1;">Copyright (c) 2016 Juan Gonzalez Burgos</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; color:#e1e1e1;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt; color:#e1e1e1;">Contributors:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; color:#e1e1e1;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt; color:#e1e1e1;">- </span><a href="https://github.com/juangburgos/"><span style=" font-size:11pt; text-decoration: underline; color:#0000ff;">juangburgos</span></a></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt; color:#e1e1e1;">- </span><a href="https://github.com/cls-nebadje"><span style=" font-size:11pt; text-decoration: underline; color:#0000ff;">cls-nebadje</span></a></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt; color:#e1e1e1;">This project could not have been possible without:</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><br /></p> diff --git a/src/main/helperfunctions.cpp b/src/main/helperfunctions.cpp index a61505d..6a9d71d 100644 --- a/src/main/helperfunctions.cpp +++ b/src/main/helperfunctions.cpp @@ -391,7 +391,7 @@ QMetaObject GetMetaObjectByClassName(QString strClassName) } else if (strClassName.compare("WCalendar") == 0) { - metaObj = WtQtWCalendar::staticMetaObject; + metaObj = WtQtCalendar::staticMetaObject; } else if (strClassName.compare("WSlider") == 0) { diff --git a/src/main/mainpage.cpp b/src/main/mainpage.cpp index fb27d62..9573626 100644 --- a/src/main/mainpage.cpp +++ b/src/main/mainpage.cpp @@ -24,24 +24,30 @@ bool MainPage::qtConnected = false; -MainPage::MainPage(const Wt::WEnvironment& env, MainWindow *mainwindow) : - Wt::WQApplication(env, true) // [IMPORTANT] : second param has to be set to TRUE +MainPage::MainPage(const Wt::WEnvironment& env, MainWindow *mainwindow) + : Wt::WQApplication(env, true) // [IMPORTANT] : second param has to be set to TRUE + , m_mainwindow(mainwindow) + , m_qtroot(nullptr) + , thisQtConnected(false) { - m_mainwindow = mainwindow; - m_qtroot = NULL; - // necessary to dynamically update webpage - enableUpdates(true); - // don't know if necessary - Wt::WString::setDefaultEncoding(Wt::UTF8); + // necessary to dynamically update webpage + enableUpdates(true); + // don't know if necessary + Wt::WString::setDefaultEncoding(Wt::UTF8); } MainPage::~MainPage() { - } void MainPage::create() { + /* prevent leakage in case of double allocation */ + if (m_qtroot) + { + qCritical() << "main page already initialized"; + return; + } QEventLoop evtblocker; m_qtroot = new SignalEmiter(NULL, this); // from mainwindow to mainpage @@ -143,20 +149,24 @@ void MainPage::create() void MainPage::destroy() { - // mark wtapp disconnected from mainwindow if connected - if (thisQtConnected) - { - // mark as not connected - thisQtConnected = false; - qtConnected = false; - } - // clear connections list - qDeleteAll(m_qtroot->m_listConnections); - m_qtroot->m_listConnections.clear(); - // delete qt object - delete m_qtroot; - + // mark wtapp disconnected from mainwindow if connected + if (thisQtConnected) + { + // mark as not connected + thisQtConnected = false; + qtConnected = false; + } + if (m_qtroot) + { + // clear connections list + qDeleteAll(m_qtroot->m_listConnections); + m_qtroot->m_listConnections.clear(); + // delete qt object + delete m_qtroot; + m_qtroot = nullptr; + } } + // TODO : FIX BY SEPARATING INTO TWO DIFFFERENT FUNCTIONS void MainPage::LoadRecursiveTree(QDomElement element, Wt::WContainerWidget *wparent/*=0*/, QObject *qparent/*=0*/, int irow/*=-1*/) { @@ -388,431 +398,111 @@ bool MainPage::PerformDisconnection(Wt_ConnectionConfig *conConfig) return true; } -QObject * MainPage::CreateWtQtInstance(QDomElement * element, int irow, Wt::WContainerWidget * wparent, QObject * qparent) +typedef QObject * (*ElementFactory) (QObject *, Wt::WContainerWidget *, int); + +template +static QObject * +WidgetFactory(QObject *qparent, + Wt::WContainerWidget *wparent, + int row) { - QObject *object = NULL; + if (row >= 0 && row < static_cast(wparent->children().size())) + { + auto *object = new WidgetT(NULL, qparent); + wparent->insertWidget(row, dynamic_cast(object)); + return object; + } + else + { + return new WidgetT(wparent, qparent); + } +} - if (!wparent) - { - wparent = GetWContainerParent(qparent); - } +template +static QObject * +InternalChildWidgetFactory(QObject *qparent, + Wt::WContainerWidget *, + int) +{ + auto *newparent = dynamic_cast(qparent); + if (newparent) + { + return new WidgetT(newparent); + } + qDebug() << "[ERROR] : Could not cast " << typeid(WidgetT).name() << " parent to " << typeid(WidgetParentT).name() << "."; + qDebug() << "[ERROR] : parent id = " << qparent->property("Wt_id").toString(); + qDebug() << "[ERROR] : parent class = " << qparent->property("Wt_className").toString(); - if (element->attribute("Wt_className").compare("WContainerWidget") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtContainerWidget(NULL, qparent); - Wt::WContainerWidget *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtContainerWidget(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WAnchor") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtAnchor(NULL, qparent); - Wt::WAnchor *wwobject = dynamic_cast(object); // [NOTE] changed casting to wanchor otherwise crash (this is because WtQtAnchor already inerits from a mixed-class) - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtAnchor(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WText") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtText(NULL, qparent); - Wt::WText *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtText(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WLineEdit") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtLineEdit(NULL, qparent); - Wt::WLineEdit *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtLineEdit(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WImage") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtImage(NULL, qparent); - Wt::WImage *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtImage(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WPushButton") == 0) // [TODO] first part was commented? - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtPushButton(NULL, qparent); - Wt::WPushButton *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtPushButton(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTemplate") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTemplate(NULL, qparent); - Wt::WTemplate *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTemplate(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WSplitButton") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtSplitButton(NULL, qparent); - Wt::WSplitButton *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtSplitButton(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WRadioButton") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtRadioButton(NULL, qparent); - Wt::WRadioButton *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtRadioButton(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WCheckBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtCheckBox(NULL, qparent); - Wt::WCheckBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtCheckBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WComboBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtComboBox(NULL, qparent); - Wt::WComboBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtComboBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WInPlaceEdit") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtInPlaceEdit(NULL, qparent); - Wt::WInPlaceEdit *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtInPlaceEdit(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTextArea") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTextArea(NULL, qparent); - Wt::WTextArea *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTextArea(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WSelectionBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtSelectionBox(NULL, qparent); - Wt::WSelectionBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtSelectionBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WSpinBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtSpinBox(NULL, qparent); - Wt::WSpinBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtSpinBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WDoubleSpinBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtDoubleSpinBox(NULL, qparent); - Wt::WDoubleSpinBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtDoubleSpinBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTimeEdit") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTimeEdit(NULL, qparent); - Wt::WTimeEdit *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTimeEdit(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WDateEdit") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtDateEdit(NULL, qparent); - Wt::WDateEdit *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtDateEdit(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WCalendar") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtWCalendar(NULL, qparent); - Wt::WCalendar *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtWCalendar(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WSlider") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtSlider(NULL, qparent); - Wt::WSlider *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtSlider(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WFileUpload") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtFileUpload(NULL, qparent); - Wt::WFileUpload *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtFileUpload(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WProgressBar") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtProgressBar(NULL, qparent); - Wt::WProgressBar *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtProgressBar(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WGroupBox") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtGroupBox(NULL, qparent); - Wt::WGroupBox *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtGroupBox(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WPanel") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtPanel(NULL, qparent); - Wt::WPanel *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtPanel(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WStackedWidget") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtStackedWidget(NULL, qparent); - Wt::WStackedWidget *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtStackedWidget(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTabWidget") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTabWidget(NULL, qparent); - Wt::WTabWidget *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTabWidget(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTabItem") == 0) - { - WtQtTabWidget *newparent = dynamic_cast(qparent); - if (newparent) - { - object = new WtQtTabItem(newparent); - } - else - { - qDebug() << "[ERROR] : Could not cast WtQtTabItem parent as WtQtWTabWidget."; - qDebug() << "[ERROR] : WtQtTabItem parent id = " << qparent->property("Wt_id").toString(); - qDebug() << "[ERROR] : WtQtTabItem parend class = " << qparent->property("Wt_className").toString(); - } - } - else if (element->attribute("Wt_className").compare("WMenu") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtMenu(NULL, qparent); - Wt::WMenu *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtMenu(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WMenuItem") == 0) - { - WtQtMenu *newparent = dynamic_cast(qparent); - if (newparent) - { - object = new WtQtMenuItem(newparent); - } - else - { - qDebug() << "[ERROR] : Could not cast WtQtMenuItem parent as WtQtMenu."; - qDebug() << "[ERROR] : WtQtMenuItem parent id = " << qparent->property("Wt_id").toString(); - qDebug() << "[ERROR] : WtQtMenuItem parend class = " << qparent->property("Wt_className").toString(); - } - } - else if (element->attribute("Wt_className").compare("WPopupMenu") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtPopupMenu(NULL, qparent); - Wt::WWidget *wwobject = dynamic_cast(object)->getInternalWWidget(); - if (wwobject) - { - wparent->insertWidget(irow, wwobject); - } - } - else - object = new WtQtPopupMenu(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WPopupItem") == 0) - { - WtQtPopupMenu *newparent = dynamic_cast(qparent); - if (newparent) - { - object = new WtQtPopupItem(newparent); - } - else - { - qDebug() << "[ERROR] : Could not cast WtQtPopupItem parent as WtQtPopupMenu."; - qDebug() << "[ERROR] : WtQtPopupItem parent id = " << qparent->property("Wt_id").toString(); - qDebug() << "[ERROR] : WtQtPopupItem parend class = " << qparent->property("Wt_className").toString(); - } - } - else if (element->attribute("Wt_className").compare("WTable") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTable(NULL, qparent); - Wt::WTable *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTable(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTree") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTree(NULL, qparent); - Wt::WTree *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTree(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WTreeTable") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtTreeTable(NULL, qparent); - Wt::WTreeTable *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtTreeTable(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WNavigationBar") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtNavigationBar(NULL, qparent); - Wt::WNavigationBar *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtNavigationBar(wparent, qparent); - } - else if (element->attribute("Wt_className").compare("WPromotedWidget") == 0) - { - if (irow >= 0 && irow < wparent->children().size()) - { - object = new WtQtPromotedWidget(NULL, qparent); - Wt::WContainerWidget *wwobject = dynamic_cast(object); - wparent->insertWidget(irow, wwobject); - } - else - object = new WtQtPromotedWidget(wparent, qparent); - } - else - { - qDebug() << "[ERROR] : Unknown Wt Element."; // TODO : do something, now it crashes - qDebug() << "[ERROR] : Unknown element className = " << element->attribute("Wt_className"); - qDebug() << "[ERROR] : Unknown element lineNumber = " << element->lineNumber(); - } + /* todo: handle this or provide a place holder widget */ + return nullptr; +} + +#define WTD_MAKE_WIDGET_LUT_ENTRY(BASENAME) \ + {"W" #BASENAME, &WidgetFactory} + +#define WTD_MAKE_WIDGET_LUT_ENTRY_INTL(BASENAME, PARENTBASENAME) \ + {"W" #BASENAME, &InternalChildWidgetFactory} - return object; +#include + +QObject * MainPage::CreateWtQtInstance(QDomElement * element, int irow, Wt::WContainerWidget * wparent, QObject * qparent) +{ + static const std::unordered_map lookup({ + WTD_MAKE_WIDGET_LUT_ENTRY(ContainerWidget), + WTD_MAKE_WIDGET_LUT_ENTRY(Anchor), + WTD_MAKE_WIDGET_LUT_ENTRY(Text), + WTD_MAKE_WIDGET_LUT_ENTRY(LineEdit), + WTD_MAKE_WIDGET_LUT_ENTRY(Image), + WTD_MAKE_WIDGET_LUT_ENTRY(PushButton), + WTD_MAKE_WIDGET_LUT_ENTRY(Template), + WTD_MAKE_WIDGET_LUT_ENTRY(SplitButton), + WTD_MAKE_WIDGET_LUT_ENTRY(RadioButton), + WTD_MAKE_WIDGET_LUT_ENTRY(CheckBox), + WTD_MAKE_WIDGET_LUT_ENTRY(ComboBox), + WTD_MAKE_WIDGET_LUT_ENTRY(InPlaceEdit), + WTD_MAKE_WIDGET_LUT_ENTRY(TextArea), + WTD_MAKE_WIDGET_LUT_ENTRY(SelectionBox), + WTD_MAKE_WIDGET_LUT_ENTRY(SpinBox), + WTD_MAKE_WIDGET_LUT_ENTRY(DoubleSpinBox), + WTD_MAKE_WIDGET_LUT_ENTRY(TimeEdit), + WTD_MAKE_WIDGET_LUT_ENTRY(DateEdit), + WTD_MAKE_WIDGET_LUT_ENTRY(Calendar), + WTD_MAKE_WIDGET_LUT_ENTRY(Slider), + WTD_MAKE_WIDGET_LUT_ENTRY(FileUpload), + WTD_MAKE_WIDGET_LUT_ENTRY(ProgressBar), + WTD_MAKE_WIDGET_LUT_ENTRY(GroupBox), + WTD_MAKE_WIDGET_LUT_ENTRY(Panel), + WTD_MAKE_WIDGET_LUT_ENTRY(StackedWidget), + WTD_MAKE_WIDGET_LUT_ENTRY(TabWidget), + WTD_MAKE_WIDGET_LUT_ENTRY_INTL(TabItem, TabWidget), + WTD_MAKE_WIDGET_LUT_ENTRY(Menu), + WTD_MAKE_WIDGET_LUT_ENTRY_INTL(MenuItem, Menu), + WTD_MAKE_WIDGET_LUT_ENTRY(PopupMenu), + WTD_MAKE_WIDGET_LUT_ENTRY_INTL(PopupItem, PopupMenu), + WTD_MAKE_WIDGET_LUT_ENTRY(Table), + WTD_MAKE_WIDGET_LUT_ENTRY(Tree), + WTD_MAKE_WIDGET_LUT_ENTRY(TreeTable), + WTD_MAKE_WIDGET_LUT_ENTRY(NavigationBar), + + /* special/irregular factory entries come here */ + {"WPromotedWidget", &WidgetFactory}, + }); + + try { + auto factory = lookup.at(element->attribute("Wt_className").toStdString()); + return factory(qparent, + wparent ? wparent : GetWContainerParent(qparent), + irow); + } catch (const std::out_of_range &) { + /* handle special cases which can not be handled by default factories here */ + + qDebug() << "[ERROR] : Unknown Wt Element."; // TODO : do something, now it crashes + qDebug() << "[ERROR] : Unknown element className = " << element->attribute("Wt_className"); + qDebug() << "[ERROR] : Unknown element lineNumber = " << element->lineNumber(); + + /* todo: instead of crashing we should return an place holder widget */ + return nullptr; + } } void MainPage::AddStyleSheetFile(QString &strPath) @@ -1103,7 +793,7 @@ void SignalEmiter::on_InsertConfig(QByteArray strConfigFraction, QString strPare void SignalEmiter::on_GenerateAutoGenCpp(QString strProjName) { - Q_EMIT SendAutoGenCpp(GetAutoGenCpp(mp_owner->m_qtroot, strProjName)); + Q_EMIT SendAutoGenCpp(GetAutoGenCpp(mp_owner->GetQtRoot(), strProjName)); } @@ -1153,7 +843,7 @@ void SignalEmiter::on_UpdateAllProperties() if (lock) { // Update all properties - HelpUpdateAllProperties(mp_owner->m_qtroot); + HelpUpdateAllProperties(mp_owner->GetQtRoot()); // Push the changes to the browser mp_owner->triggerUpdate(); } diff --git a/src/main/mainpage.h b/src/main/mainpage.h index 3e19bfb..9edb071 100644 --- a/src/main/mainpage.h +++ b/src/main/mainpage.h @@ -51,8 +51,8 @@ class MainPage : public Wt::WQApplication MainPage(const Wt::WEnvironment& env, MainWindow *mainwindow); ~MainPage(); - void create(); - void destroy(); + virtual void create(); + virtual void destroy(); void SetupUi(Wt::WContainerWidget *wtroot); @@ -68,13 +68,16 @@ class MainPage : public Wt::WQApplication bool PerformConnection(Wt_ConnectionConfig *conConfig); bool PerformDisconnection(Wt_ConnectionConfig *conConfig); - SignalEmiter * m_qtroot; + SignalEmiter * GetQtRoot() + { + return m_qtroot; + } +private: + MainWindow *m_mainwindow; + SignalEmiter * m_qtroot; - bool thisQtConnected; - static bool qtConnected; - - MainWindow *m_mainwindow; - + bool thisQtConnected; + static bool qtConnected; }; class SignalEmiter : public WtQtInteractWidget // instead of inheriting WContainerWidget, it contains a ref to one diff --git a/src/main/mainwindow.cpp b/src/main/mainwindow.cpp index 5a90ff6..cd4786d 100644 --- a/src/main/mainwindow.cpp +++ b/src/main/mainwindow.cpp @@ -19,11 +19,12 @@ #include "mainwindow.h" #include "helperfunctions.h" +#include "mainpage.h" + + MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : QMainWindow(parent) { - // create the wt server - mp_WtServerWorker = new WtServerWorker(this); // setup the main window ui ui.setupUi(this); // set all icons color @@ -32,7 +33,6 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) m_pwidgetmodel = new MyWidgetModel(g_strLocalWidgetsPath, this); // widget model should come first because it loads the icons ui.treeviewWtWidgets->setModel(m_pwidgetmodel); ui.treeviewWtWidgets->expandAll(); - m_treemodel.setMapIconsByClassName(m_pwidgetmodel->getMapIconsByClassName()); // pass icons from widget model to tree model ui.treeviewWtTree->setModel(&m_treemodel); ui.treeviewWtProperties->setModel(&m_propertymodel); ui.treeviewWtSignalsSlots->setModel(&m_sigslotmodel); @@ -127,8 +127,7 @@ MainWindow::~MainWindow() { // Stop Wt server StopWtServer(); - // Delete Wt server - delete mp_WtServerWorker; + // Delete old local /resources/ and /temp/ folders if (QDir(g_strLocalResourcesPath).exists()) { QDir(g_strLocalResourcesPath).removeRecursively(); } if (QDir(g_strLocalTempPath).exists()) { QDir(g_strLocalTempPath).removeRecursively(); } @@ -425,48 +424,77 @@ void MainWindow::LoadDefaultConfig() void MainWindow::StartWtServer() { - // (re)configure ip address for webview - m_Address = "http://127.0.0.1:" + m_vectWtParams[WT_VALHTTPPORT]; - // set settings related attrs that might have changed in settings dialog - QDomElement docElem = m_treemodel.getDocument().documentElement(); - docElem.setAttribute(g_strThemeAttr, m_strWtTheme); - docElem.setAttribute(g_strTitleAttr, m_strWtTitle); - // start Wt server - mp_WtServerWorker->ConfigureWtServer(m_vectWtParams); - mp_WtServerWorker->start(); - // load page [IMPORTANT] : DO NOT DELETE LINE BELOW OR PAGE WILL NEVER LOAD - on_LoadPage(); -} - -void MainWindow::StopWtServer() -{ - // load something else - m_WebView->load(QUrl("http://www.webtoolkit.eu/wt")); - // shutdown Wt server - if (mp_WtServerWorker->isRunning()) - { - mp_WtServerWorker->quit(); - } - // wait if necessary - int counter = 0; - while (mp_WtServerWorker->isRunning()) - { - QThread::msleep(100); - QApplication::processEvents(); - counter++; - if (counter == 15) - { - break; - } - } - if (counter == 15) - { - qDebug() << "[ERROR] Could not stop Wt Server cleanly"; - mp_WtServerWorker->quit(); - mp_WtServerWorker->terminate(); - } - // [NOTE] very important - m_WebView->settings()->clearMemoryCaches(); + if (m_server) + { + StopWtServer(); + } + + // (re)configure ip address for webview + m_Address = "http://127.0.0.1:" + m_vectWtParams[WT_VALHTTPPORT]; + + // set settings related attrs that might have changed in settings dialog + QDomElement docElem = m_treemodel.getDocument().documentElement(); + docElem.setAttribute(g_strThemeAttr, m_strWtTheme); + docElem.setAttribute(g_strTitleAttr, m_strWtTitle); + + std::vector args; + for (const auto &s : m_vectWtParams) + { + args.emplace_back(s.toStdString()); + } + std::vector argv; + for (const auto &s : args) + { + argv.emplace_back(const_cast(s.c_str())); + } + m_server = std::unique_ptr < Wt::WServer + > (new Wt::WServer(argv.size(), argv.data())); + + auto wtApplicationFactory = [&](const Wt::WEnvironment& env) + { + return new MainPage(env, this); + }; + m_server->addEntryPoint(Wt::Application, wtApplicationFactory); + + try + { + m_server->start(); + } catch (const Wt::WServer::Exception &e) + { + qCritical() << "wt server start failed with: " << e.what(); + m_server = decltype(m_server)(); + return; + } + // load page [IMPORTANT] : DO NOT DELETE LINE BELOW OR PAGE WILL NEVER LOAD + on_LoadPage(); +} + +void MainWindow::StopWtServer() +{ + if (!m_server) + { + return; + } + + // load something else + m_WebView->load(QUrl("http://www.webtoolkit.eu/wt")); + + // shutdown Wt server + if (m_server->isRunning()) + { + try + { + m_server->stop(); + } catch (const Wt::WServer::Exception &e) + { + qCritical() << "wt server stop failed with: " << e.what(); + } + } + // dispose Wt server object by resetting unique_ptr + m_server = decltype(m_server)(); + + // [NOTE] very important + m_WebView->settings()->clearMemoryCaches(); } void MainWindow::LoadFileConfig(QByteArray config) @@ -1341,8 +1369,8 @@ void MainWindow::on_actionPreferences_triggered() void MainWindow::on_ReloadWtServer() { - StopWtServer(); - StartWtServer(); + StopWtServer(); + StartWtServer(); #ifdef Q_OS_WIN // because this is called when config is changed (i.e. the lib path might have changed) m_listLibFileNames.clear(); @@ -1388,7 +1416,7 @@ void MainWindow::on_treeviewWtTree_contextMenu(const QPoint &point) QModelIndex index = ui.treeviewWtTree->indexAt(point); // for icons - QMap mapIcons = m_pwidgetmodel->getMapIconsByClassName(); + auto &mapIcons = Icons::GetCache(); if (!index.isValid()) { diff --git a/src/main/mainwindow.h b/src/main/mainwindow.h index 7dece29..5c48f05 100644 --- a/src/main/mainwindow.h +++ b/src/main/mainwindow.h @@ -18,6 +18,8 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include + #include #include #include @@ -44,7 +46,6 @@ #include "myundocommands.h" -#include "wtserverworker.h" #include "myglobals.h" #include "./dialogs/dialogconfig/dialogconfig.h" @@ -202,7 +203,7 @@ public Q_SLOTS: int m_argc; char **m_argv; QVector m_vectWtParams; - WtServerWorker *mp_WtServerWorker; + std::unique_ptr m_server; MyWebView *m_WebView; QString m_Address; diff --git a/src/main/mixedclasses.cpp b/src/main/mixedclasses.cpp index ee118f8..d922e04 100644 --- a/src/main/mixedclasses.cpp +++ b/src/main/mixedclasses.cpp @@ -2079,52 +2079,52 @@ void WtQtDateEdit::Wt_setFormat(QString format) ----------------------------------------------------------------------------------------------------------------------------------------------------------- */ -WtQtWCalendar::WtQtWCalendar(Wt::WContainerWidget *wparent /*= 0*/, QObject *qparent /*= 0*/) : Wt::WCalendar(wparent), WtQtCompositeWidget(qparent) +WtQtCalendar::WtQtCalendar(Wt::WContainerWidget *wparent /*= 0*/, QObject *qparent /*= 0*/) : Wt::WCalendar(wparent), WtQtCompositeWidget(qparent) { } -WtQtWCalendar::WtQtWCalendar(const WtQtWCalendar& other) +WtQtCalendar::WtQtCalendar(const WtQtCalendar& other) { Q_UNUSED(other) } -WtQtWCalendar::~WtQtWCalendar() +WtQtCalendar::~WtQtCalendar() { } -QString WtQtWCalendar::Wt_className() +QString WtQtCalendar::Wt_className() { return "WCalendar"; } -QString WtQtWCalendar::Wt_id() +QString WtQtCalendar::Wt_id() { return QString::fromStdString(id()); } -void WtQtWCalendar::Wt_setId(QString id) +void WtQtCalendar::Wt_setId(QString id) { setId(id.toStdString()); } -QString WtQtWCalendar::Wt_styleClass() +QString WtQtCalendar::Wt_styleClass() { return QString::fromStdString(styleClass().toUTF8()); } -void WtQtWCalendar::Wt_setStyleClass(QString styleclass) +void WtQtCalendar::Wt_setStyleClass(QString styleclass) { setStyleClass(Wt::WString::fromUTF8(styleclass.toStdString())); } -QString WtQtWCalendar::Wt_isInline() +QString WtQtCalendar::Wt_isInline() { return QString("%1").arg(isInline()); } -void WtQtWCalendar::Wt_setInline(QString isinline) +void WtQtCalendar::Wt_setInline(QString isinline) { setInline(isinline.toUInt()); } @@ -4286,7 +4286,7 @@ QString WtQtProgressBar::Cpp_value() QString WtQtGroupBox::Cpp_title() { - return Wt_id() + "->setTitle(" + Wt_title() + ");"; + return Wt_id() + "->setTitle(Wt::WString::fromUTF8(\"" + Wt_title() + "\"));"; } QString WtQtGroupBox::Cpp_htmlTagName() @@ -4297,7 +4297,7 @@ QString WtQtGroupBox::Cpp_htmlTagName() QString WtQtPanel::Cpp_title() { - return Wt_id() + "->setTitle(" + Wt_title() + ");"; + return Wt_id() + "->setTitle(Wt::WString::fromUTF8(\"" + Wt_title() + "\"));"; } QString WtQtPanel::Cpp_isCollapsible() diff --git a/src/main/mixedclasses.h b/src/main/mixedclasses.h index e742135..3b5eb74 100644 --- a/src/main/mixedclasses.h +++ b/src/main/mixedclasses.h @@ -1018,14 +1018,14 @@ class WtQtDateEdit : public WtQtLineEdit, public Wt::WDateEdit }; -class WtQtWCalendar : public WtQtCompositeWidget, public Wt::WCalendar +class WtQtCalendar : public WtQtCompositeWidget, public Wt::WCalendar { Q_OBJECT public: - WtQtWCalendar(Wt::WContainerWidget *wparent = 0, QObject *qparent = 0); - ~WtQtWCalendar(); - WtQtWCalendar(const WtQtWCalendar& other); + WtQtCalendar(Wt::WContainerWidget *wparent = 0, QObject *qparent = 0); + ~WtQtCalendar(); + WtQtCalendar(const WtQtCalendar& other); QString Wt_className(); // [NOTE] : need to add to helperfunctions::GetMetaObjectByClassName diff --git a/src/main/modelview/mytreemodel.cpp b/src/main/modelview/mytreemodel.cpp index e703f1e..12e25da 100644 --- a/src/main/modelview/mytreemodel.cpp +++ b/src/main/modelview/mytreemodel.cpp @@ -341,7 +341,7 @@ QVariant MyTreeModel::data(const QModelIndex &index, int role) const { if ( index.column() == 1 ) { - return m_mapIconByClassName.value(strClassName); + return Icons::GetCache().value(strClassName); } } @@ -880,11 +880,6 @@ void MyTreeModel::getUniqueIdList(QDomElement *elem) } } -void MyTreeModel::setMapIconsByClassName(QMap mapIcons) -{ - m_mapIconByClassName = mapIcons; -} - bool MyTreeModel::isHiddenRootElem(WDomElem * elem) { if (elem == wRootHiddenElem) diff --git a/src/main/modelview/mytreemodel.h b/src/main/modelview/mytreemodel.h index 620d264..b0a5145 100644 --- a/src/main/modelview/mytreemodel.h +++ b/src/main/modelview/mytreemodel.h @@ -93,8 +93,6 @@ class MyTreeModel : public QAbstractItemModel void replaceUniqueId(QString oldId, QString newId); - void setMapIconsByClassName(QMap mapIcons); - bool isHiddenRootElem(WDomElem * elem); QString findCloserContainer(QString &name); @@ -139,8 +137,6 @@ class MyTreeModel : public QAbstractItemModel QByteArray execXQueryOnConfig(QString strQuery); QList mstrlistAllIds; - - QMap m_mapIconByClassName; }; #endif // WQTREEMODEL_H diff --git a/src/main/modelview/mywidgetmodel.cpp b/src/main/modelview/mywidgetmodel.cpp index 8075620..5663804 100644 --- a/src/main/modelview/mywidgetmodel.cpp +++ b/src/main/modelview/mywidgetmodel.cpp @@ -18,8 +18,6 @@ #include "mywidgetmodel.h" #include "myglobals.h" -QMap WWidgetNode::m_mapIconByClassName; - WWidgetNode::WWidgetNode(WWIDGETNODETYPE intNodeType, QString &strPath, int row, WWidgetNode *parent /*= 0*/) : QObject(parent) { m_intNodeType = intNodeType; @@ -122,7 +120,7 @@ void WWidgetNode::setupNodeChildren() if (m_intNodeType == WIDGET) { - m_mapIconByClassName.insert(m_strName, m_icon); + Icons::GetCache().insert(m_strName, m_icon); } // set name for category @@ -436,11 +434,3 @@ QByteArray MyWidgetModel::findWidgetConfigRecursive(WWidgetNode * wparent, QStri } return QByteArray(); } - -QMap MyWidgetModel::getMapIconsByClassName() -{ - return wRootNode->m_mapIconByClassName; -} - - - diff --git a/src/main/modelview/mywidgetmodel.h b/src/main/modelview/mywidgetmodel.h index 6f09def..1033124 100644 --- a/src/main/modelview/mywidgetmodel.h +++ b/src/main/modelview/mywidgetmodel.h @@ -29,7 +29,6 @@ #include #include - //#include enum WWIDGETNODETYPE @@ -63,8 +62,6 @@ class WWidgetNode : public QObject void debugPrintState(QString header = ""); - static QMap m_mapIconByClassName; - private: WWIDGETNODETYPE m_intNodeType; // could be "root", "category", "widget" QString m_strPath; @@ -97,8 +94,6 @@ class MyWidgetModel : public QAbstractItemModel QByteArray getWidgetConfigByName(QString strWidgetName); - QMap getMapIconsByClassName(); - private: WWidgetNode * wRootNode; diff --git a/src/main/myglobals.cpp b/src/main/myglobals.cpp new file mode 100644 index 0000000..4721693 --- /dev/null +++ b/src/main/myglobals.cpp @@ -0,0 +1,23 @@ +/* + * icons.cpp + * + * Created on: Jun 21, 2016 + * Author: uli + */ + +#include "myglobals.h" + +#include + +QMap & +Icons::GetCache() +{ + static QMap cache; + static auto conn = QObject::connect(qApp, + &QCoreApplication::aboutToQuit, + [&]{ + cache.clear(); + }); + return cache; +} + diff --git a/src/main/myglobals.h b/src/main/myglobals.h index 73077af..0e66668 100644 --- a/src/main/myglobals.h +++ b/src/main/myglobals.h @@ -19,6 +19,7 @@ #define MY_GLOBALS_H #include +#include const QString g_strLocalRootPath = "./" ; const QString g_strLocalResourcesPath = "./resources/"; @@ -56,5 +57,14 @@ const QString g_strThemeBootstrat3 = "Boostrap 3"; const QString g_strThemeAttr = "Wt_theme"; const QString g_strTitleAttr = "Wt_title"; +/** Global icon cache. + * + * See https://bugreports.qt.io/browse/QTBUG-50829 + */ +class Icons +{ +public: + static QMap & GetCache(); +}; -#endif \ No newline at end of file +#endif diff --git a/src/main/wtdesigner.pro b/src/main/wtdesigner.pro index 10a072e..3522e11 100644 --- a/src/main/wtdesigner.pro +++ b/src/main/wtdesigner.pro @@ -33,10 +33,11 @@ TARGET = WtDesigner CONFIG -= flat CONFIG += no_batch +CONFIG += debug_and_release QT += core xml widgets gui webkitwidgets svg xmlpatterns -DEFINES += QT_DLL QT_WEBKITWIDGETS_LIB QT_WIDGETS_LIB QT_XML_LIB +DEFINES += QT_DLL QT_WEBKITWIDGETS_LIB QT_WIDGETS_LIB QT_XML_LIB DESTDIR = ../../bin/WtDesigner/ @@ -56,7 +57,6 @@ HEADERS += ./myglobals.h \ ./mixedclasses.h \ ./myundocommands.h \ ./mywebview.h \ - ./wtserverworker.h \ ./helperfunctions.h \ ./wtwithqtlib/DispatchThread.h \ ./wtwithqtlib/WQApplication.h \ @@ -80,9 +80,9 @@ SOURCES += ./main.cpp \ ./mainpage.cpp \ ./mainwindow.cpp \ ./mixedclasses.cpp \ + ./myglobals.cpp \ ./myundocommands.cpp \ - ./mywebview.cpp \ - ./wtserverworker.cpp \ + ./mywebview.cpp \ ./helperfunctions.cpp \ ./wtwithqtlib/DispatchThread.cpp \ ./wtwithqtlib/WQApplication.cpp \ diff --git a/src/main/wtserverworker.cpp b/src/main/wtserverworker.cpp deleted file mode 100644 index 1f045b1..0000000 --- a/src/main/wtserverworker.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2016 Juan Gonzalez Burgos -// -// This file is part of WtDesigner. -// -// WtDesigner is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// WtDesigner is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with WtDesigner. If not, see . - -#include -#include -#include "mainwindow.h" -#include "mainpage.h" - -QHash m_hashpages; -MainWindow *m_mainwindow; - -Wt::WApplication * createApplication(const Wt::WEnvironment& env) -{ - static int counter = 0; - MainPage * page = new MainPage(env, m_mainwindow); - //m_hashpages.insert(counter, page); - //counter++; - return page; -} - -WtServerWorker::WtServerWorker(MainWindow *mainwindow) : QThread(mainwindow) -{ - // make copy of pointer to main window to be able to pass it to Wt::WApplication (MainPage class instance) - m_mainwindow = mainwindow; -} - -WtServerWorker::~WtServerWorker() -{ - // delete allocated memory - free(m_argv); -} - -void WtServerWorker::run() -{ - // configure wt server - Wt::WServer server(m_argc, m_argv, WTHTTP_CONFIGURATION); - server.addEntryPoint(Wt::Application, createApplication); - // start wt server - try - { - server.start(); - } - catch (...) - { - qDebug() << "[ERROR] Exception occurred while starting Wt Server in WtServerWorker::run"; - } - // eter event loop and wait - exec(); - // stop wt server - try - { - server.stop(); - } - catch (...) - { - qDebug() << "[ERROR] Exception occurred while shutting down Wt Server in WtServerWorker::run"; - } -} - -void WtServerWorker::ConfigureWtServer(QVector vectargs) -{ - // make local copies in class members - m_argc = vectargs.size(); - // allocate memory for copying c strings - m_argv = (char**)malloc(m_argc*sizeof(char**)); - for (int i = 0; i < m_argc; i++) - { - m_argv[i] = (char*)calloc(vectargs[i].size(), sizeof(char)); - // copy each qstring in list as c string - strcpy(m_argv[i], vectargs[i].toStdString().c_str()); - } -} diff --git a/src/main/wtserverworker.h b/src/main/wtserverworker.h deleted file mode 100644 index 6826057..0000000 --- a/src/main/wtserverworker.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2016 Juan Gonzalez Burgos -// -// This file is part of WtDesigner. -// -// WtDesigner is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// WtDesigner is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with WtDesigner. If not, see . - -#ifndef WTSERVERWORKER_H -#define WTSERVERWORKER_H - -#include -#include -#include -#include -#include -#include -#include - -class MainWindow; - -class WtServerWorker : public QThread -{ - Q_OBJECT - -public: - WtServerWorker(MainWindow *mainwindow); - ~WtServerWorker(); - - void run(); - - Wt::WServer *m_pserver; - - void ConfigureWtServer(QVector vectargs); - -private: - int m_argc; - char **m_argv; - - -}; - -#endif // WTSERVERWORKER_H diff --git a/src/wtconfig.pri b/src/wtconfig.pri index dd2f947..5562a28 100644 --- a/src/wtconfig.pri +++ b/src/wtconfig.pri @@ -24,9 +24,7 @@ INCLUDEPATH += . \ DEPENDPATH += . LIBS += -LC:/Wt-3.3.5-msvs2013-Windows-x86-SDK/lib \ - -LC:/Wt-3.3.5-msvs2013-Windows-x86-SDK/bin \ - -LC:/Wt-3.3.5-msvs2013-Windows-x64-SDK/lib \ - -LC:/Wt-3.3.5-msvs2013-Windows-x64-SDK/bin + -LC:/Wt-3.3.5-msvs2013-Windows-x64-SDK/lib CONFIG(debug, debug|release) {