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
templateeditor.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef TEMPLATEEDITOR_H
32 #define TEMPLATEEDITOR_H
33 
34 #include <QWidget>
35 
36 #include <QDomDocument>
37 
38 
39 class TemplateCore;
40 
41 /// \brief Represents the editor of the template.
42 ///
43 /// Editor is the place where user can edit contents of the template,
44 /// for example questions for Quiz template.
45 /// \ingroup template-interfaces
46 class TemplateEditor : public QWidget {
47  Q_OBJECT
48 
49  public:
50  // Constructors and destructors.
51  explicit TemplateEditor(TemplateCore *core, QWidget *parent = 0);
52  virtual ~TemplateEditor();
53 
54  /// \brief Specifies if template can generate applications
55  /// or not.
56  /// \return Returns true if editor contains enough data
57  /// for generating of applications.
58  /// \warning This is used in cooperation with canGenerateStatusChanged(bool can_generate).
59  virtual bool canGenerateApplications() {
60  return m_canGenerate;
61  }
62 
63  /// \brief Access to description of current state.
64  /// \return Returns active description of generating state.
65  virtual QString generationStatusDescription() {
66  return m_generateMessage;
67  }
68 
69  /// \brief Generates RAW data which represent data of this template.
70  /// \remarks Generated data are stored in XML bundle file.
71  /// \warning Generated data of this method must be compatible
72  /// with custom implementation of TemplateEntryPoint::loadCoreFromBundleData(const QString &raw_data)
73  /// method!!!
74  /// \return Returns string with generated data.
75  virtual QString generateBundleData() = 0;
76 
77  /// \brief Loads editor state from XML bundle.
78  /// \param bundle_data Raw XML bundle data.
79  /// \return Returns true if editor loaded bundle data, otherwise
80  /// returns false.
81  virtual bool loadBundleData(const QString &bundle_data) = 0;
82 
83  /// \brief Executed when given template with this editor is launched.
84  /// \note Editor is "launched" when its core is newly created or loaded
85  /// from XML bundle file. Durin "launch" usually only check if data contained
86  /// in editor is done.
87  virtual void launch();
88 
89  /// \brief Access to associated template core.
90  /// \return Returns associated template core.
91  /// \see TemplateCore
92  TemplateCore *core() const;
93 
94  /// \brief Check if editor contains unsaved contents.
95  /// \return Returns true, if editor contains unsaved contents, otherwise
96  /// returns false.
97  bool isDirty() const;
98 
99  /// \brief Sets new dirtiness status.
100  /// \param is_dirty New dirtiness status.
101  void setIsDirty(bool is_dirty);
102 
103  /// \brief Access to project name of current editor.
104  /// \return Returns string of project name of current editor.
105  /// This is usually text in some text box in the editor.
106  virtual QString projectName() = 0;
107 
108  /// \brief Access to author name of current editor.
109  /// \return Returns string of author name. This is usually text in some text box in the editor.
110  virtual QString authorName() = 0;
111 
112  public slots:
113  /// \brief Dirtifies (sets m_isDirty to true) the editor.
114  void dirtify() {
115  setIsDirty(true);
116  }
117 
118  protected:
119  /// \brief Emits new signal notifying other components about state
120  /// of creating of APK application.
121  /// \param can_generate True if editor contains enough data
122  /// to generate APK application or not.
123  /// \param message New message to be delivered to application
124  /// about current status of creating of APK application.
125  void issueNewGenereationStatus(bool can_generate, const QString &message = QString());
126 
127  signals:
128  /// \brief Emitted everytime any child widget of editor
129  /// changes its contents.
130  /// \remarks This signal is used to check if contents of
131  /// editor are saved or not. If editor notifies that its contents
132  /// are changed, then it is marked by toolkit as "unsaved".
133  void changed();
134 
135  /// \brief Emitted if status, which specifies if mobile application
136  /// can be generated from the template, changes.
137  /// \warning This signal also specifies if new simulation can be started.
138  /// \param can_generate True if editor contains enough
139  /// data so that mobile application can be generated, false
140  /// otherwise.
141  /// \remarks This is for example emitted if user ads first
142  /// question item to Quiz template editor.
143  void canGenerateChanged(bool can_generate, const QString &message = QString());
144 
145  protected:
146  bool m_canGenerate;
147  QString m_generateMessage;
148  bool m_isDirty;
149  TemplateCore *m_core;
150 };
151 
152 #endif // TEMPLATEEDITOR_H
virtual QString projectName()=0
Access to project name of current editor.
void canGenerateChanged(bool can_generate, const QString &message=QString())
Emitted if status, which specifies if mobile application can be generated from the template...
void dirtify()
Dirtifies (sets m_isDirty to true) the editor.
bool isDirty() const
Check if editor contains unsaved contents.
virtual QString generationStatusDescription()
Access to description of current state.
TemplateCore * core() const
Access to associated template core.
void changed()
Emitted everytime any child widget of editor changes its contents.
virtual QString authorName()=0
Access to author name of current editor.
Represents the editor of the template.
virtual bool canGenerateApplications()
Specifies if template can generate applications or not.
void issueNewGenereationStatus(bool can_generate, const QString &message=QString())
Emits new signal notifying other components about state of creating of APK application.
void setIsDirty(bool is_dirty)
Sets new dirtiness status.
The core class container for single template.
Definition: templatecore.h:43
virtual bool loadBundleData(const QString &bundle_data)=0
Loads editor state from XML bundle.
virtual QString generateBundleData()=0
Generates RAW data which represent data of this template.
virtual void launch()
Executed when given template with this editor is launched.