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
FlashCardEditor Class Reference
Collaboration diagram for FlashCardEditor:
Collaboration graph

Public Member Functions

 FlashCardEditor (TemplateCore *core, QWidget *parent=0)
 
bool canGenerateApplications ()
 Specifies if template can generate applications or not. More...
 
QString generateBundleData ()
 Generates RAW data which represent data of this template. More...
 
bool loadBundleData (const QString &bundle_data)
 Loads editor state from XML bundle. More...
 
QList< FlashCardQuestionactiveQuestions () const
 
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 FlashCardSimulator
 
class FlashCardCore
 

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

Definition at line 44 of file flashcardeditor.h.

Member Function Documentation

QString FlashCardEditor::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 249 of file flashcardeditor.cpp.

249  {
250  return m_ui->m_txtAuthor->lineEdit()->text();
251 }
bool FlashCardEditor::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 136 of file flashcardeditor.cpp.

136  {
137  return
138  !m_ui->m_txtName->lineEdit()->text().simplified().isEmpty() &&
139  !m_ui->m_txtAuthor->lineEdit()->text().simplified().isEmpty() &&
140  !activeQuestions().isEmpty();
141 }
QString FlashCardEditor::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 143 of file flashcardeditor.cpp.

143  {
144  /*if (!canGenerateApplications()) {
145  return QString();
146  }*/
147 
148  QDomDocument source_document = qApp->templateManager()->generateBundleHeader(core()->entryPoint()->typeIndentifier(),
149  m_ui->m_txtAuthor->lineEdit()->text(),
150  QString(),
151  m_ui->m_txtName->lineEdit()->text(),
152  QString(),
153  "1");
154  FIND_DATA_ELEMENT(data_element, source_document);
155 
156  foreach (const FlashCardQuestion &question, activeQuestions()) {
157  QDomElement item_element = source_document.createElement("item");
158 
159  // Fill in details about question.
160  QDomElement question_element = source_document.createElement("question");
161  QDomElement answer_element = source_document.createElement("answer");
162  QDomElement hint_element = source_document.createElement("hint");
163  QDomElement image_element = source_document.createElement("image");
164 
165  question_element.appendChild(source_document.createTextNode(question.question()));
166  answer_element.appendChild(source_document.createTextNode(question.answer()));
167  hint_element.appendChild(source_document.createTextNode(question.hint()));
168 
169  // Read file with image, convert it to base64 and insert into XML bundle.
170  QByteArray picture_encoded = IOFactory::fileToBase64(question.picturePath());
171 
172  if (picture_encoded.isEmpty() || picture_encoded.isNull()) {
173  return QString();
174  }
175 
176  image_element.appendChild(source_document.createTextNode(QString::fromUtf8(picture_encoded)));
177  item_element.appendChild(question_element);
178  item_element.appendChild(answer_element);
179  item_element.appendChild(hint_element);
180  item_element.appendChild(image_element);
181 
182  data_element.appendChild(item_element);
183  }
184 
185  return source_document.toString(XML_BUNDLE_INDENTATION);
186 }
TemplateCore * core() const
Access to associated template core.
static QByteArray fileToBase64(const QString &file_name)
Takes input file and reads it into base64 byte array.
Definition: iofactory.cpp:111

Here is the call graph for this function:

bool FlashCardEditor::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 188 of file flashcardeditor.cpp.

188  {
189  QDomDocument bundle_document;
190  bundle_document.setContent(bundle_data);
191 
192  QDomNodeList items = bundle_document.documentElement().elementsByTagName("item");
193 
194  for (int i = 0; i < items.size(); i++) {
195  QDomNode item = items.at(i);
196 
197  if (item.isElement()) {
198  QString question = item.namedItem("question").toElement().text();
199  QString answer = item.namedItem("answer").toElement().text();
200  QString hint = item.namedItem("hint").toElement().text();
201  QString image_data = item.namedItem("image").toElement().text();
202 
203  if (question.isEmpty() || answer.isEmpty() || image_data.isEmpty()) {
204  // TODO: error
205  continue;
206  }
207  else {
208  // TODO: POKRACOVAT TADY, prevadeni z base64 do souboru blbne.
209  // https://www.google.cz/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=qt%20base64%20to%20file
210  QString output_directory = qApp->templateManager()->tempDirectory();
211  QString target_image_file = output_directory +
212  QString("/image_%1.png").arg(i);
213 
214  if (IOFactory::base64ToFile(image_data, target_image_file)) {
215  // Picture from the item was saved to disk.
216  addQuestion(question, answer, hint, target_image_file);
217  }
218  else {
219  // TODO: errro
220  }
221  }
222  }
223  else {
224  continue;
225  }
226  }
227 
228  // Load author & name.
229  m_ui->m_txtAuthor->lineEdit()->setText(bundle_document.documentElement().namedItem("author").namedItem("name").toElement().text());
230  m_ui->m_txtName->lineEdit()->setText(bundle_document.documentElement().namedItem("title").toElement().text());
231 
232  return true;
233 }
static bool base64ToFile(const QString &source_data, const QString &target_file)
Takes base64 byte array and saves it into file.
Definition: iofactory.cpp:125

Here is the call graph for this function:

QString FlashCardEditor::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 245 of file flashcardeditor.cpp.

245  {
246  return m_ui->m_txtName->lineEdit()->text();
247 }

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