Skip to content

Commit e7b3bbd

Browse files
author
Flaviu Toader
committed
Updated code. TODO: change the property convertors to one central implementation in ModelToXmlConvertor.
1 parent 94c00c3 commit e7b3bbd

12 files changed

+114
-31
lines changed

src/CMakeLists.txt

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,31 @@ set(wt_project_source
2525
main.cpp
2626
)
2727

28+
set(vanetxml_source
29+
xml/property/abstractpropertyconvertor.cpp
30+
xml/property/areapropertyconvertor.cpp
31+
xml/property/gmsoutpropertyconvertor.cpp
32+
xml/modeltoxmlconverter.cpp
33+
)
34+
include_directories(${cmake_source_dir})
2835
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
2936
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
3037

3138
configure_file(${cmake_source_dir}/general.xml ${EXECUTABLE_OUTPUT_PATH}/general.xml COPYONLY)
32-
33-
add_executable(${wt_project_target} ${wt_project_source})
34-
target_link_libraries(${wt_project_target} wthttp wt boost_signals)
35-
include_directories(${cmake_source_dir})
36-
3739
# create the logs directory
3840
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/logs)
3941
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
4042
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin/resources)
4143
# copy themes to resources directory
4244
file(COPY ../themes/ DESTINATION ${PROJECT_BINARY_DIR}/bin/resources/themes/)
4345

46+
add_library(vanetXml ${vanetxml_source})
47+
target_link_libraries(vanetXml pugixml wt)
48+
49+
add_executable(${wt_project_target} ${wt_project_source})
50+
target_link_libraries(${wt_project_target} wthttp wt boost_signals vanetXml)
51+
52+
4453
add_subdirectory(client)
4554
add_subdirectory(xml)
4655
add_subdirectory(model)

src/client/widgets/dialogs/vanetareapropertyform.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ void VanetAreaPropertyForm::setPreselectedValues(const std::map< std::string, bo
5656

5757
WStandardItem *VanetAreaPropertyForm::treeNode()
5858
{
59-
WStandardItem *result = new WStandardItem();
59+
WStandardItem *result = new WStandardItem(tr("mappropertyeditor.group.general"));
6060
result->setData(VanetArea);
61-
result->setText(tr("mappropertyeditor.group.general").toUTF8());
6261

6362
result->appendRow(propertyRow(std::string("dimx"), tr("mappropertyeditor.group.general.dimx").toUTF8(), boost::lexical_cast<std::string>(dimx_->value())));
6463
result->appendRow(propertyRow(std::string("dimy"), tr("mappropertyeditor.group.general.dimy").toUTF8(), boost::lexical_cast<std::string>(dimy_->value())));

src/client/widgets/mappropertyeditor.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "client/mapmakerpage.h"
2727
#include "client/widgets/dialogs/propertydialog.h"
2828
#include "client/widgets/dialogs/abstractpropertyform.h"
29+
#include "xml/modeltoxmlconverter.h"
2930

3031
using namespace Wt;
3132

@@ -81,6 +82,7 @@ MapPropertyEditor::MapPropertyEditor(MapMakerPage* mapmaker, WStandardItemModel
8182

8283
validate_ = new WPushButton(tr("mappropertyeditor.button.validate"), buttonTable->elementAt(0, 2));
8384
validate_->resize(120, 30);
85+
validate_->clicked().connect(this, &MapPropertyEditor::validateClicked);
8486

8587
save_ = new WPushButton(tr("button.save"), buttonTable->elementAt(0, 3));
8688
save_->resize(120, 30);
@@ -140,3 +142,9 @@ void MapPropertyEditor::itemClicked(const WModelIndex& clickedItem)
140142
removeProperty_->setDisabled(true);
141143
}
142144
}
145+
146+
void MapPropertyEditor::validateClicked()
147+
{
148+
ModelToXmlConverter modelToXml(model_);
149+
modelToXml.validate();
150+
}

src/client/widgets/mappropertyeditor.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class MapPropertyEditor : public Wt::WContainerWidget
6969
void itemDoubleClicked(const Wt::WModelIndex &clickedItem);
7070
void itemClicked(const Wt::WModelIndex &clickedItem);
7171
void removeSelectedProperty();
72+
void validateClicked();
7273

7374
Wt::WPushButton* addProperty_, * removeProperty_, * validate_, * save_;
7475
Wt::WStandardItemModel* model_;

src/xml/CMakeLists.txt

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
set(vanetxml_source
2-
property/areapropertyconvertor.cpp
3-
modeltoxmlconverter.cpp
4-
)
51

6-
add_library(vanetXml ${vanetxml_source})
7-
target_link_libraries(vanetXml pugixml wt)
82
add_subdirectory(property)

src/xml/modeltoxmlconverter.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <string>
2+
#include <boost/any.hpp>
23
#include <pugixml/pugixml.hpp>
34

45
#include <Wt/WStandardItemModel>
@@ -25,14 +26,27 @@ void ModelToXmlConverter::convertXml()
2526
for (int i = 0; i < model_->rowCount(); i++)
2627
{
2728
WStandardItem* currentItem = model_->item(i);
28-
int itemType = boost::any_cast<int>(currentItem->data());
29-
AbstractPropertyConvertor* convertor;
30-
switch(itemType)
29+
try
3130
{
32-
case VanetArea:
33-
convertor = new AreaPropertyConvertor;
34-
break;
31+
int itemType = boost::any_cast<VanetProperty>(currentItem->data());
32+
AbstractPropertyConvertor* convertor;
33+
switch(itemType)
34+
{
35+
case 1:
36+
convertor = new AreaPropertyConvertor;
37+
break;
38+
}
39+
convertor->appendXml(root_, currentItem);
40+
}
41+
catch(boost::bad_any_cast e)
42+
{
43+
Logger::entry("error") << "Bad any cast when getting data from item " << currentItem->text().toUTF8() << ". Exception message: " << e.what();
3544
}
36-
convertor->appendXml(root_, currentItem);
3745
}
3846
}
47+
48+
void ModelToXmlConverter::validate()
49+
{
50+
doc_.save_file("test.xml");
51+
}
52+

src/xml/modeltoxmlconverter.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#ifndef MODELTOXMLCONVERTER_H
22
#define MODELTOXMLCONVERTER_H
33

4+
#include <pugixml/pugixml.hpp>
5+
46
namespace Wt
57
{
68
class WStandardItemModel;
79
}
810

9-
namespace pugi
10-
{
11-
class xml_document;
12-
class xml_node;
13-
}
11+
// namespace pugi
12+
// {
13+
// class xml_document;
14+
// class xml_node;
15+
// }
1416

1517
class ModelToXmlConverter
1618
{

src/xml/property/abstractpropertyconvertor.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <string>
22
#include <vector>
33
#include <Wt/WStandardItem>
4+
#include <Wt/WString>
45

56
#include "abstractpropertyconvertor.h"
67

@@ -13,15 +14,15 @@ std::vector< WStandardItem* > AbstractPropertyConvertor::propertyRow(const strin
1314
WStandardItem *item;
1415

1516
// tree column 0: property name
16-
item = new WStandardItem(propertyName);
17+
item = new WStandardItem(WString::fromUTF8(propertyName));
1718
propertyItems.push_back(item);
1819

1920
// tree column 1: property value
20-
item = new WStandardItem(propertyValue);
21+
item = new WStandardItem(WString::fromUTF8(propertyValue));
2122
propertyItems.push_back(item);
2223

2324
// tree column 2: property id (hidden column)
24-
item = new WStandardItem(propertyId);
25+
item = new WStandardItem(WString::fromUTF8(propertyId));
2526
propertyItems.push_back(item);
2627

2728
return propertyItems;

src/xml/property/areapropertyconvertor.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <vector>
21
#include <string>
32
#include <pugixml/pugixml.hpp>
43

54
#include <Wt/WStandardItem>
65
#include <Wt/WString>
6+
#include <boost/concept_check.hpp>
77

88
#include "areapropertyconvertor.h"
99
#include "abstractpropertyconvertor.h"
@@ -41,10 +41,16 @@ WStandardItem* AreaPropertyConvertor::treeNode(const pugi::xml_node& root)
4141
for(pugi::xml_node_iterator it = root.begin(); it != root.end(); ++it)
4242
{
4343
pugi::xml_node currentNode = *it;
44-
if (currentNode.name() == "dimx")
44+
if (currentNode.name() == "dimx")
45+
{
4546
dimxval = string(currentNode.value());
47+
continue;
48+
}
4649
if (currentNode.name() == "dimy")
50+
{
4751
dimyval = string(currentNode.value());
52+
continue;
53+
}
4854
if (!dimxval.empty() && !dimyval.empty())
4955
break;
5056
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <string>
2+
#include <map>
3+
#include <pugixml/pugixml.hpp>
4+
5+
#include <Wt/WStandardItem>
6+
#include <Wt/WString>
7+
8+
#include "gmsoutpropertyconvertor.h"
9+
#include "abstractpropertyconvertor.h"
10+
#include "logger.h"
11+
#include "client/widgets/dialogs/abstractpropertyform.h"
12+
13+
using namespace Wt;
14+
using namespace std;
15+
16+
const char* const GmsOutPropertyConvertor::TREENODE_NAME = "mappropertyeditor.group.gmsout";
17+
18+
Wt::WStandardItem* GmsOutPropertyConvertor::treeNode(const pugi::xml_node& root)
19+
{
20+
WStandardItem* result = new WStandardItem(WString::tr(TREENODE_NAME));
21+
map< string, string > values;
22+
for(pugi::xml_node_iterator it = root.begin(); it != root.end(); ++it)
23+
{
24+
string currentName = it->name();
25+
26+
}
27+
}
28+
29+
void GmsOutPropertyConvertor::appendXml(pugi::xml_node& root, Wt::WStandardItem* treeNode)
30+
{
31+
32+
}
33+
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef GMSOUTPROPERTYCONVERTOR_H
2+
#define GMSOUTPROPERTYCONVERTOR_H
3+
4+
#include <../../home/flaviu/projects/vanetizer-c--/src/xml/property/abstractpropertyconvertor.h>
5+
6+
7+
class GmsOutPropertyConvertor : public AbstractPropertyConvertor
8+
{
9+
10+
public:
11+
static const char* const TREENODE_NAME;
12+
virtual Wt::WStandardItem* treeNode(const pugi::xml_node& root);
13+
virtual void appendXml(pugi::xml_node& root, Wt::WStandardItem* treeNode);
14+
};
15+
16+
#endif // GMSOUTPROPERTYCONVERTOR_H

vanetizer.kdev4

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[Project]
2-
Name=vanetizer
32
Manager=KDevCMakeManager
3+
Name=vanetizer-c--
44
VersionControl=kdevgit

0 commit comments

Comments
 (0)