Improved C++ NotedModel and some small visual thinks

This commit is contained in:
Scharel Clemens 2019-06-21 17:49:54 +02:00
parent 3b1e1cca8c
commit 5156f1e629
8 changed files with 112 additions and 78 deletions

View file

@ -5,8 +5,16 @@ import Nemo.Notifications 1.0
Dialog {
id: editDialog
//property int noteID
property var note
property int id
property int modified
property string title
property string category
property string content
property bool favorite
property string etag
property bool error
property string errorMessage
property string date
onAccepted: {
api.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } )

View file

@ -6,6 +6,8 @@ import "../js/showdown/dist/showdown.js" as ShowDown
Dialog {
id: noteDialog
property Note note
property int id
property int modified
property string title
@ -31,7 +33,17 @@ Dialog {
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { note: note }
acceptDestinationProperties: (
{ id: id,
modified: modified,
title: title,
category: category,
content: content,
favorite: favorite,
etag: etag,
error: error,
errorMessage: errorMessage,
date: date } )
onAccepted: {
acceptDestinationInstance.note = note
acceptDestinationInstance.reloadContent()
@ -42,6 +54,7 @@ Dialog {
}
}
Component.onCompleted: {
console.log(note.title)
parseContent()
}

View file

@ -55,7 +55,7 @@ Page {
SearchField {
id: searchField
width: parent.width
enabled: appSettings.accountIDs.length > 0
enabled: !busyIndicator.running && !noLoginPlaceholder.enabled && !errorPlaceholder.enabled && !noNotesPlaceholder.enabled
placeholderText: account.name.length > 0 ? account.name : qsTr("Nextcloud Notes")
EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false
@ -103,7 +103,8 @@ Page {
}
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"),
{ id: id,
{ note: noteListModel.get(index),
id: id,
modified: modified,
title: title,
category: category,
@ -220,6 +221,17 @@ Page {
size: BusyIndicatorSize.Large
running: notesList.count === 0 && api.busy
}
Label {
id: busyLabel
anchors.top: busyIndicator.bottom
anchors.topMargin: Theme.paddingMedium
visible: busyIndicator.running
width: parent.width
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeExtraLarge
horizontalAlignment: Qt.AlignHCenter
text: qsTr("Loading notes...")
}
ViewPlaceholder {
id: noLoginPlaceholder

View file

@ -57,6 +57,35 @@ void NotesModel::clearSearch() {
search();
}
bool NotesModel::applyJSONobject(const QJsonObject &jobj) {
if (!jobj.isEmpty()) {
Note note = Note::fromjson(jobj); // TODO connect signals
if (!note.error()) {
int position = indexOf(note.id());
Note oldNote = get(position);
if (position >= 0 && note.etag() != oldNote.etag()) {
qDebug() << "-- Existing note " << note.title() << "changed, updating the model.";
replaceNote(note);
}
else if (position < 0) {
qDebug() << "-- New note" << note.title() << ", adding it to the model.";
insertNote(note);
}
else {
qDebug() << "-- Existing note " << note.title() << "unchanged, nothing to do.";
}
}
else {
qDebug() << "Note contains an error:" << note.errorMessage();
}
}
else {
qDebug() << "Unknown JSON object. This message should never occure!";
return false;
}
return true;
}
bool NotesModel::applyJSON(const QString &json) {
qDebug() << "Applying new JSON input";// << json;
QJsonParseError error;
@ -70,55 +99,14 @@ bool NotesModel::applyJSON(const QString &json) {
QJsonValue jval = jarr.first();
if (jval.isObject()) {
//qDebug() << "It's an object, all fine...";
QJsonObject jobj = jval.toObject();
if (!jobj.isEmpty()) {
//qDebug() << "Adding it to the model...";
Note note = Note::fromjson(jobj); // TODO connect signals
if (!note.error()) {
int position = indexOf(note.id());
Note oldNote = get(position);
if (position >= 0 && note.etag() != oldNote.etag()) {
qDebug() << "-- Existing note " << note.title() << "changed, updating the model...";
replaceNote(note);
}
else if (position < 0) {
qDebug() << "-- New note" << note.title() << ", adding it to the model...";
insertNote(note);
}
//qDebug() << "Adding note"<< note.title << "on position" << position;
//beginInsertRows(QModelIndex(), position, position);
//m_notes.insert(position, note);
//endInsertRows();
}
else {
qDebug() << "Note contains an error:" << note.errorMessage();
}
}
else {
qDebug() << "Unknown JSON object. This message should never occure!";
}
applyJSONobject(jval.toObject());
}
jarr.pop_front();
}
}
else if (jdoc.isObject()) {
qDebug() << "It's a single object...";
QJsonObject jobj = jdoc.object();
if (!jobj.isEmpty() && !jobj.value(roleNames()[ErrorRole]).toBool(true)) {
Note note = Note::fromjson(jobj); // TODO connect signals
int position = indexOf(note.id());
if (position >= 0) {
m_notes[position].note = note;
}
else {
position = insertPosition(note);
ModelNote<Note, bool> noteToInsert;
noteToInsert.note = note; noteToInsert.param = true;
beginInsertRows(index(position), position, position);
m_notes.insert(position, noteToInsert);
endInsertRows();
}
}
qDebug() << "- It's a single object...";
return applyJSONobject(jdoc.object());
}
else {
qDebug() << "Unknown JSON document. This message should never occure!";
@ -127,7 +115,7 @@ bool NotesModel::applyJSON(const QString &json) {
}
else
{
qDebug() << error.errorString();
qDebug() << "Unable to parse the JSON input:" << error.errorString();
}
return error.error == QJsonParseError::NoError;
}

View file

@ -95,7 +95,7 @@ private:
void sort();
//void update();
//void insertJnote(const QJsonObject &jobj);
bool applyJSONobject(const QJsonObject &jobj);
int insertPosition(const Note &n) const;
bool noteLessThan(const Note &n1, const Note &n2) const;
/*static bool noteLessThanByDate(const Note &n1, const Note &n2);

View file

@ -313,6 +313,10 @@
<source>Deleting note</source>
<translation>Lösche Notiz</translation>
</message>
<message>
<source>Loading notes...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>

View file

@ -313,6 +313,10 @@
<source>Deleting note</source>
<translation type="unfinished">Tar bort anteckning</translation>
</message>
<message>
<source>Loading notes...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>

View file

@ -84,32 +84,32 @@
<context>
<name>EditPage</name>
<message>
<location filename="../qml/pages/EditPage.qml" line="31"/>
<location filename="../qml/pages/EditPage.qml" line="39"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="35"/>
<location filename="../qml/pages/EditPage.qml" line="43"/>
<source>Markdown syntax</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="63"/>
<location filename="../qml/pages/EditPage.qml" line="71"/>
<source>No content</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="148"/>
<location filename="../qml/pages/EditPage.qml" line="156"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="149"/>
<location filename="../qml/pages/EditPage.qml" line="157"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="164"/>
<location filename="../qml/pages/EditPage.qml" line="172"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -232,52 +232,52 @@
<context>
<name>NotePage</name>
<message>
<location filename="../qml/pages/NotePage.qml" line="102"/>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<location filename="../qml/pages/NotePage.qml" line="119"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<location filename="../qml/pages/NotePage.qml" line="119"/>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="112"/>
<location filename="../qml/pages/NotePage.qml" line="125"/>
<source>Last update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<location filename="../qml/pages/NotePage.qml" line="128"/>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="122"/>
<location filename="../qml/pages/NotePage.qml" line="135"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="123"/>
<location filename="../qml/pages/NotePage.qml" line="136"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="243"/>
<location filename="../qml/pages/NotePage.qml" line="256"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="244"/>
<location filename="../qml/pages/NotePage.qml" line="257"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="259"/>
<location filename="../qml/pages/NotePage.qml" line="272"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -328,57 +328,62 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="197"/>
<location filename="../qml/pages/NotesPage.qml" line="198"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="200"/>
<location filename="../qml/pages/NotesPage.qml" line="201"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="202"/>
<location filename="../qml/pages/NotesPage.qml" line="203"/>
<source>Deleting note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="227"/>
<location filename="../qml/pages/NotesPage.qml" line="233"/>
<source>Loading notes...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="239"/>
<source>No account yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="228"/>
<location filename="../qml/pages/NotesPage.qml" line="240"/>
<source>Got to the settings to add an account</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="234"/>
<location filename="../qml/pages/NotesPage.qml" line="246"/>
<source>No notes yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="235"/>
<location filename="../qml/pages/NotesPage.qml" line="247"/>
<source>Pull down to add a note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="241"/>
<location filename="../qml/pages/NotesPage.qml" line="253"/>
<source>No result</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="242"/>
<location filename="../qml/pages/NotesPage.qml" line="254"/>
<source>Try another query</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="248"/>
<location filename="../qml/pages/NotesPage.qml" line="260"/>
<source>An error occurred</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="259"/>
<location filename="../qml/pages/NotesPage.qml" line="271"/>
<source>Open the settings to configure your Nextcloud accounts</source>
<translation type="unfinished"></translation>
</message>