Notes App#
Example's page
This page describes an example listed in app category.
Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.
The functionality includes loading, saving, creating and deleting notes, as well as marking the UI state as dirty when changes are made.
Models#
Note
struct describes a note:
@dontinclude examples/app/notes/src/main.cpp @skip struct Note @until };
The JSON representation is described as follows:
@line AJSON
MainWindow class#
The MainWindow
class is responsible for managing the overall view and logic related to notes.
Fields#
mNotes
: a member that holds a list of notes.mCurrentNote
: a property holding a pointer to the currently selected note.mDirty
: a boolean property indicating whether there are unsaved changes in the application.
Methods#
load()
: loads notes from a JSON file.
|
save()
: saves the current list of notes to a JSON file. Also resets the dirty state.
|
newNote()
: creates a new note with a default title and adds it to the list of notes. Sets this note as the currently selected note.
deleteCurrentNote()
: deletes the current note, if one is selected. Prompts the user for confirmation before proceeding with deletion.
|
markDirty()
: marks the application state as dirty when changes made that require saving. Such a simple operation is extracted to a dedicated method, so the signals can be easily connected to. @skip markDirty() @until }
UI Components and Layout#
@dontinclude examples/app/notes/src/main.cpp
- TitleTextArea
: derivative of ATextArea
that focuses next text area when Enter
is pressed.
@skip TitleTextArea
@until };
- 'New note' button: creates a new note using newNote()
.
- 'Save' button: saves application data via save()
method. It's enabled
state is controlled by mDirty
property.
- 'Delete' button: deletes current note via deleteCurrentNote()
method. It's enabled
state is controlled by
mCurrentNote
property.
- Previews: contains dynamically generated previews of all notes, allowing users to select the one they want to view
or edit.
|
notePreview()
function generates a single preview for a note.
|
- Main area of the application is occupied by note editor generated by
noteEditor()
function.noteEditor()
consists of 2 text areas - one for title, one for contents.
|
Source Code#
CMakeLists.txt#
|
src/main.cpp#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|