BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
QuizEditor Class Reference

Editor for Quiz. More...

#include <quizeditor.h>

Collaboration diagram for QuizEditor:
Collaboration graph

Public Member Functions

 QuizEditor (TemplateCore *core, QWidget *parent=0)
 
QString generateBundleData ()
 Generates RAW data which represent data of this template. More...
 
bool canGenerateApplications ()
 Specifies if template can generate applications or not. More...
 
bool loadBundleData (const QString &bundle_data)
 Loads editor state from XML bundle. More...
 
QList< QuizQuestionactiveQuestions () const
 Access to list of added questions. More...
 
QString projectName ()
 Access to project name of current editor. More...
 
QString authorName ()
 Access to author name of current editor. More...
 
- Public Member Functions inherited from TemplateEditor
 TemplateEditor (TemplateCore *core, QWidget *parent=0)
 
virtual QString generationStatusDescription ()
 Access to description of current state. More...
 
virtual void launch ()
 Executed when given template with this editor is launched. More...
 
TemplateCorecore () const
 Access to associated template core. More...
 
bool isDirty () const
 Check if editor contains unsaved contents. More...
 
void setIsDirty (bool is_dirty)
 Sets new dirtiness status. More...
 

Friends

class QuizSimulator
 
class QuizCore
 

Additional Inherited Members

- Public Slots inherited from TemplateEditor
void dirtify ()
 Dirtifies (sets m_isDirty to true) the editor.
 
- Signals inherited from TemplateEditor
void changed ()
 Emitted everytime any child widget of editor changes its contents. More...
 
void canGenerateChanged (bool can_generate, const QString &message=QString())
 Emitted if status, which specifies if mobile application can be generated from the template, changes. More...
 
- Protected Member Functions inherited from TemplateEditor
void issueNewGenereationStatus (bool can_generate, const QString &message=QString())
 Emits new signal notifying other components about state of creating of APK application. More...
 
- Protected Attributes inherited from TemplateEditor
bool m_canGenerate
 
QString m_generateMessage
 
bool m_isDirty
 
TemplateCorem_core
 

Detailed Description

Editor for Quiz.

Definition at line 51 of file quizeditor.h.

Member Function Documentation

QList< QuizQuestion > QuizEditor::activeQuestions ( ) const

Access to list of added questions.

Returns
Returns list of added questions.

Definition at line 141 of file quizeditor.cpp.

141  {
142  QList<QuizQuestion> questions;
143 
144  for (int i = 0; i < m_ui->m_listQuestions->count(); i++) {
145  questions.append(m_ui->m_listQuestions->item(i)->data(Qt::UserRole).value<QuizQuestion>());
146  }
147 
148  return questions;
149 }
Container for one question.
Definition: quizquestion.h:41

Here is the caller graph for this function:

QString QuizEditor::authorName ( )
virtual

Access to author name of current editor.

Returns
Returns string of author name. This is usually text in some text box in the editor.

Implements TemplateEditor.

Definition at line 155 of file quizeditor.cpp.

155  {
156  return m_ui->m_txtAuthor->lineEdit()->text();
157 }
bool QuizEditor::canGenerateApplications ( )
virtual

Specifies if template can generate applications or not.

Returns
Returns true if editor contains enough data for generating of applications.
Warning
This is used in cooperation with canGenerateStatusChanged(bool can_generate).

Reimplemented from TemplateEditor.

Definition at line 416 of file quizeditor.cpp.

416  {
417  return
418  !m_ui->m_txtName->lineEdit()->text().simplified().isEmpty() &&
419  !m_ui->m_txtAuthor->lineEdit()->text().simplified().isEmpty() &&
420  !activeQuestions().isEmpty();
421 }
QList< QuizQuestion > activeQuestions() const
Access to list of added questions.
Definition: quizeditor.cpp:141

Here is the call graph for this function:

QString QuizEditor::generateBundleData ( )
virtual

Generates RAW data which represent data of this template.

Remarks
Generated data are stored in XML bundle file.
Warning
Generated data of this method must be compatible with custom implementation of TemplateEntryPoint::loadCoreFromBundleData(const QString &raw_data) method!!!
Returns
Returns string with generated data.

Implements TemplateEditor.

Definition at line 462 of file quizeditor.cpp.

462  {
463  /*if (!canGenerateApplications()) {
464  return QString();
465  }*/
466 
467  QDomDocument source_document = qApp->templateManager()->generateBundleHeader(core()->entryPoint()->typeIndentifier(),
468  m_ui->m_txtAuthor->lineEdit()->text(),
469  QString(),
470  m_ui->m_txtName->lineEdit()->text(),
471  QString(),
472  "1");
473  FIND_DATA_ELEMENT(data_element, source_document);
474 
475  foreach (const QuizQuestion &question, activeQuestions()) {
476  QDomElement item_element = source_document.createElement("item");
477 
478  // Fill in details about question.
479  QDomElement question_element = source_document.createElement("question");
480  QDomElement answer_one_element = source_document.createElement("option");
481  QDomElement answer_two_element = source_document.createElement("option");
482  QDomElement answer_three_element = source_document.createElement("option");
483  QDomElement answer_four_element = source_document.createElement("option");
484  QDomElement answer_number_element = source_document.createElement("answer");
485 
486  question_element.appendChild(source_document.createTextNode(question.question()));
487  answer_one_element.appendChild(source_document.createTextNode(question.answerOne()));
488  answer_two_element.appendChild(source_document.createTextNode(question.answerTwo()));
489  answer_three_element.appendChild(source_document.createTextNode(question.answerThree()));
490  answer_four_element.appendChild(source_document.createTextNode(question.answerFour()));
491  answer_number_element.appendChild(source_document.createTextNode(QString::number(question.correctAnswer())));
492 
493  item_element.appendChild(question_element);
494  item_element.appendChild(answer_one_element);
495  item_element.appendChild(answer_two_element);
496  item_element.appendChild(answer_three_element);
497  item_element.appendChild(answer_four_element);
498  item_element.appendChild(answer_number_element);
499 
500  data_element.appendChild(item_element);
501  }
502 
503  return source_document.toString(XML_BUNDLE_INDENTATION);
504 }
TemplateCore * core() const
Access to associated template core.
QList< QuizQuestion > activeQuestions() const
Access to list of added questions.
Definition: quizeditor.cpp:141
int correctAnswer() const
Access to inde of correct answer.
Container for one question.
Definition: quizquestion.h:41

Here is the call graph for this function:

bool QuizEditor::loadBundleData ( const QString &  bundle_data)
virtual

Loads editor state from XML bundle.

Parameters
bundle_dataRaw XML bundle data.
Returns
Returns true if editor loaded bundle data, otherwise returns false.

Implements TemplateEditor.

Definition at line 423 of file quizeditor.cpp.

423  {
424  QDomDocument bundle_document;
425  bundle_document.setContent(bundle_data);
426 
427  QDomNodeList items = bundle_document.documentElement().elementsByTagName("item");
428 
429  for (int i = 0; i < items.size(); i++) {
430  QDomNode item = items.at(i);
431 
432  if (item.isElement()) {
433  QString question = item.namedItem("question").toElement().text();
434  int correct_answer = item.namedItem("answer").toElement().text().toInt();
435  QDomNodeList answer_items = item.toElement().elementsByTagName("option");
436  QList<QString> answers;
437 
438  for (int j = 0; j < answer_items.size(); j++) {
439  answers.append(answer_items.at(j).toElement().text());
440  }
441 
442  if (question.isEmpty() || answers.size() < 2 || answers.size() > 4) {
443  // TODO: error
444  continue;
445  }
446  else {
447  addQuestion(question, answers, correct_answer);
448  }
449  }
450  else {
451  continue;
452  }
453  }
454 
455  // Load author & name.
456  m_ui->m_txtAuthor->lineEdit()->setText(bundle_document.documentElement().namedItem("author").namedItem("name").toElement().text());
457  m_ui->m_txtName->lineEdit()->setText(bundle_document.documentElement().namedItem("title").toElement().text());
458 
459  return true;
460 }
QString QuizEditor::projectName ( )
virtual

Access to project name of current editor.

Returns
Returns string of project name of current editor. This is usually text in some text box in the editor.

Implements TemplateEditor.

Definition at line 151 of file quizeditor.cpp.

151  {
152  return m_ui->m_txtName->lineEdit()->text();
153 }

The documentation for this class was generated from the following files: