Skip to content

Commit

Permalink
changed WTreeTable in WTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu authored and Mathieu committed Jan 15, 2014
1 parent b4e86a0 commit 4eb6b81
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 62 deletions.
6 changes: 2 additions & 4 deletions src/BoolQuestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ std::ostream& operator<<(std::ostream& out, const BoolQuestion& question) {
return out << question.print();
}

Wt::WTreeTableNode* BoolQuestion::widget() {
Wt::WTreeTableNode* node = Question::widget();
Wt::WContainerWidget* BoolQuestion::widget() {

Wt::WContainerWidget* container = new Wt::WContainerWidget();
Wt::WButtonGroup* group = new Wt::WButtonGroup(container);
Expand All @@ -97,6 +96,5 @@ Wt::WTreeTableNode* BoolQuestion::widget() {
yes->checked().connect(boost::bind(&BoolQuestion::setAnswer, this, true));
no->checked().connect(boost::bind(&BoolQuestion::setAnswer, this, false));

node->setColumnWidget(1, container);
return node;
return container;
}
2 changes: 1 addition & 1 deletion src/BoolQuestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BoolQuestion : public AnswerQuestion<bool> {
virtual void ask();
virtual std::ostream& save(std::ostream& out);

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget();

friend std::ostream& operator<<(std::ostream& out, const BoolQuestion& question);

Expand Down
6 changes: 2 additions & 4 deletions src/ChoiceQuestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ std::ostream& operator<<(std::ostream& out, const ChoiceQuestion& choiceQuestion
return out << choiceQuestion.print() << choiceQuestion.printChoices();
}

Wt::WTreeTableNode* ChoiceQuestion::widget() {
Wt::WTreeTableNode* node = Question::widget();
Wt::WContainerWidget* ChoiceQuestion::widget() {

Wt::WContainerWidget* container = new Wt::WContainerWidget();
Wt::WComboBox* comboBox = new Wt::WComboBox(container);
Expand All @@ -154,6 +153,5 @@ Wt::WTreeTableNode* ChoiceQuestion::widget() {
}
comboBox->changed().connect(boost::bind(&ChoiceQuestion::setAnswer, this, comboBox->currentIndex()+1));

node->setColumnWidget(1, container);
return node;
return container;
}
2 changes: 1 addition & 1 deletion src/ChoiceQuestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChoiceQuestion: public AnswerQuestion<int> {
virtual void ask();
virtual std::ostream& save(std::ostream& out);

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget();

friend std::ostream& operator<<(std::ostream& out, const ChoiceQuestion& choiceQuestion);

Expand Down
9 changes: 2 additions & 7 deletions src/GroupQuestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ void GroupQuestion::insert(Question* q, Iterator previous) {
}
}

Wt::WTreeTableNode* GroupQuestion::widget() {
Wt::WTreeTableNode* node = Question::widget();
for(Iterator it = begin(); it != end(); it.levelForward()) {
Wt::WTreeTableNode* child = (*it)->widget();
node->addChildNode(child);
}
Wt::WContainerWidget* GroupQuestion::widget() {

return node;
return new Wt::WContainerWidget();
}
4 changes: 2 additions & 2 deletions src/GroupQuestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef GROUPQUESTION_H_
#define GROUPQUESTION_H_

#include"Wt/WTreeTableNode"
#include"Wt/WContainerWidget"
#include "Question.h"
#include "QuestionList.h"
#include<string>
Expand All @@ -24,7 +24,7 @@ class GroupQuestion : public QuestionList, public Question{

virtual std::string print() const;

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget();

friend std::ostream& operator<<(std::ostream& out, const GroupQuestion& question) {
return out << question.print();
Expand Down
6 changes: 2 additions & 4 deletions src/OpenQuestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ std::ostream& operator<<(std::ostream& out, const OpenQuestion& openQuestion) {
return out << openQuestion.print();
}

Wt::WTreeTableNode* OpenQuestion::widget() {
Wt::WTreeTableNode* node = Question::widget();
Wt::WContainerWidget* OpenQuestion::widget() {

Wt::WContainerWidget* container = new Wt::WContainerWidget();
Wt::WLineEdit* text = new Wt::WLineEdit(container);
text->changed().connect(boost::bind(&OpenQuestion::setAnswer, this, text->text().toUTF8()));

node->setColumnWidget(1, container);
return node;
return container;
}

4 changes: 2 additions & 2 deletions src/OpenQuestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef OPENQUESTION_H_
#define OPENQUESTION_H_

#include "Wt/WTreeTableNode"
#include "Wt/WContainerWidget"
#include "AnswerQuestion.h"
#include<string>

Expand All @@ -22,7 +22,7 @@ class OpenQuestion: public AnswerQuestion<std::string> {
virtual void ask();
virtual std::ostream& save(std::ostream& out);

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget();

friend std::ostream& operator<<(std::ostream& out, const OpenQuestion& openQuestion);

Expand Down
10 changes: 0 additions & 10 deletions src/Question.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,3 @@ std::ostream& operator<<(std::ostream& out, const Question& question) {
return out << question.print();
}

Wt::WTreeTableNode* Question::widget() {
Wt::WCssDecorationStyle style;
style.setForegroundColor(Wt::WColor(0,255,0));

Wt::WTreeTableNode* node = new Wt::WTreeTableNode(getQuestion(), 0);
if(isOptional()) node->setDecorationStyle(style);

return node;
}

4 changes: 2 additions & 2 deletions src/Question.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef QUESTION_H_
#define QUESTION_H_

#include"Wt/WTreeTableNode"
#include"Wt/WContainerWidget"
#include <string>

class Question {
Expand All @@ -25,7 +25,7 @@ class Question {

virtual Question* copy() = 0;

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget() = 0;

friend std::ostream& operator<<(std::ostream& out, const Question& question);

Expand Down
6 changes: 2 additions & 4 deletions src/ScaleQuestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ std::ostream& operator<<(std::ostream& out, const ScaleQuestion& question) {
return out << question.print();
}

Wt::WTreeTableNode* ScaleQuestion::widget() {
Wt::WTreeTableNode* node = Question::widget();
Wt::WContainerWidget* ScaleQuestion::widget() {

Wt::WContainerWidget* container = new Wt::WContainerWidget();
Wt::WSlider* slider = new Wt::WSlider(container);
Expand All @@ -128,7 +127,6 @@ Wt::WTreeTableNode* ScaleQuestion::widget() {

slider->valueChanged().connect(boost::bind(&ScaleQuestion::setAnswer, this, slider->value()));

node->setColumnWidget(1, container);
return node;
return container;
}

2 changes: 1 addition & 1 deletion src/ScaleQuestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ScaleQuestion : public AnswerQuestion<int> {
virtual void ask();
virtual std::ostream& save(std::ostream& out);

virtual Wt::WTreeTableNode* widget();
virtual Wt::WContainerWidget* widget();

friend std::ostream& operator<<(std::ostream& out, const ScaleQuestion& question);

Expand Down
40 changes: 23 additions & 17 deletions src/SurveyFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
#include "Wt/WLink"
#include "Wt/WSignal"
#include "Wt/WText"
#include "Wt/WTree"
#include "Wt/WTreeTableNode"
#include "Wt/WCssDecorationStyle"
#include "Wt/WColor"
#include "Wt/WLineEdit"

#include "Question.h"

#include <boost/bind.hpp>


SurveyFiller::SurveyFiller(std::string title, std::string username) : title_(title),user_(username) {
std::string filename("./");
Expand All @@ -31,8 +34,8 @@ SurveyFiller::SurveyFiller(std::string title, std::string username) : title_(tit
//Title
new Wt::WText(title_, this);
//Tree
questionTree_ = new Wt::WTreeTable(this);
fillQuestionTree();
questionTable = new Wt::WTable(this);
fillQuestionTable();
//Buttons
save_ = new Wt::WPushButton("Save", this);
save_->clicked().connect(this, &SurveyFiller::save);
Expand All @@ -57,23 +60,26 @@ void SurveyFiller::save() {
//}
}

void SurveyFiller::fillQuestionTree() {
//one column for answers
questionTree_->tree()->setSelectionMode(Wt::ExtendedSelection);
questionTree_->addColumn("Answers", 120);
void SurveyFiller::fillQuestionTable() {
//default columns
questionTable->elementAt(0, 0)->addWidget(new Wt::WText("Path"));
questionTable->elementAt(0, 1)->addWidget(new Wt::WText("Question"));
questionTable->elementAt(0, 2)->addWidget(new Wt::WText("Answer"));

//rootnode
Wt::WTreeTableNode* root = new Wt::WTreeTableNode("Survey");
questionTree_->setTreeRoot(root, "Questions");
int i(1);
//add questions
for(Questionary::Iterator it = questionary_->begin(); it != questionary_->end(); it.levelForward()) {
root->addChildNode((*it)->widget());
}
root->expand();

//add optional to answered
for(Questionary::Iterator it = questionary_->begin(); it != questionary_->end(); ++it) {
questionTable->elementAt(i, 0)->addWidget(new Wt::WText(it.getPath().print()));
Wt::WCssDecorationStyle style;
style.setForegroundColor(Wt::WColor(0,255,0));
Wt::WText* question = new Wt::WText((*it)->getQuestion());
if((*it)->isOptional()) question->setDecorationStyle(style);
questionTable->elementAt(i, 1)->addWidget(question);
questionTable->elementAt(i, 2)->addWidget((*it)->widget());

//optional?
if((*it)->isOptional()) answered_.insert(*it);
++i;
}
updateAnswered();
}
Expand Down
6 changes: 3 additions & 3 deletions src/SurveyFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include"Questionary.h"
#include "QuestionList.h"
#include<Wt/WGroupBox>
#include<Wt/WTreeTable>
#include<Wt/WTable>
#include<Wt/WPushButton>
#include<string>
#include<list>
Expand All @@ -22,7 +22,7 @@ class SurveyFiller : public Wt::WGroupBox {
virtual ~SurveyFiller();

private:
void fillQuestionTree();
void fillQuestionTable();
void save();

bool isCompleted(QuestionList& ql);
Expand All @@ -32,7 +32,7 @@ class SurveyFiller : public Wt::WGroupBox {
std::string user_;
std::set<Question*> answered_;
Questionary *questionary_;
Wt::WTreeTable* questionTree_;
Wt::WTable* questionTable;
Wt::WPushButton* save_;
Wt::WPushButton* back_;
};
Expand Down

0 comments on commit 4eb6b81

Please sign in to comment.