Further Changed on the QML side to adopt the previous changes on the C++ side

This commit is contained in:
Scharel Clemens 2020-05-03 18:30:39 +02:00
parent 842ea9f699
commit fe31598042
8 changed files with 108 additions and 113 deletions

View file

@ -6,6 +6,18 @@ Dialog {
id: editDialog
property int id
property var note
onIdChanged: note = notesModel.getNoteById(id)
onNoteChanged: {
dialogHeader.title = note["title"]
contentArea.text = note["content"]
favoriteButton.selected = note["favorite"]
categoryField.text = note["category"]
modifiedDetail.modified = note["modified"]
//parseContent()
}
property int modified
property string title
property string category
@ -19,16 +31,6 @@ Dialog {
notesApi.updateNote(id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected, 'modified': new Date().valueOf() / 1000 } )
}
function reloadContent() {
//notesApi.getNoteFromApi(id)
/*note = notesApi.getNote(id)
dialogHeader.title = title
contentArea.text = content
favoriteButton.selected = favorite
categoryField.text = category
modifiedDetail.modified = modified*/
}
SilicaFlickable {
anchors.fill: parent
contentHeight: mainColumn.height + Theme.paddingLarge
@ -169,8 +171,8 @@ Dialog {
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
property int modified//: modified
value: new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
property int modified
onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
}

View file

@ -1,4 +1,4 @@
import QtQuick 2.5
import QtQuick 2.2
import Sailfish.Silica 1.0
import Nemo.Configuration 1.0

View file

@ -1,4 +1,4 @@
import QtQuick 2.5
import QtQuick 2.2
import Sailfish.Silica 1.0
import "../js/showdown/dist/showdown.js" as ShowDown
@ -6,8 +6,22 @@ Dialog {
id: noteDialog
property int id
//property var note: notesProxyModel.getNote(notesProxyModel.index(index, 0))
property var note: notesModel.getNoteById(id)
property var note
onIdChanged: note = notesModel.getNoteById(id)
onNoteChanged: {
if (note["content"].split('\n')[0].indexOf(note["title"]) > 0) {
dialogHeader.title = ""
}
else {
dialogHeader.title = note["title"]
}
favoriteButton.selected = note["favorite"]
categoryField.text = note["category"]
modifiedDetail.modified = note["modified"]
parseContent()
}
Connections {
target: notesModel
onNoteUpdated: {
@ -17,6 +31,18 @@ Dialog {
}
}
acceptDestination: Qt.resolvedUrl("EditPage.qml")
onAcceptPendingChanged: {
if (acceptPending)
acceptDestinationInstance.id = id
}
onStatusChanged: {
if (status === PageStatus.Activating) {
notesModel.getNote(id)
}
}
property var showdown: ShowDown.showdown
property var converter: new showdown.Converter(
{ simplifiedAutoLink: true,
@ -29,57 +55,7 @@ Dialog {
simpleLineBreaks: true,
emoji: true } )
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: (
{ id: id,
modified: modified,
title: title,
category: category,
content: content,
favorite: favorite,
etag: etag,
error: error,
errorMessage: errorMessage
} )
onAccepted: {
//acceptDestinationInstance.note = note
acceptDestinationInstance.reloadContent()
}
onStatusChanged: {
if (status === DialogStatus.Opened) {
//notesApi.getNoteFromApi(id)
}
}
Component.onCompleted: {
parseContent()
}
Connections {
target: notesProxyModel
onDataChanged: {
console.log(topLeft, bottomRight, index)
if (notesProxyModel.index(topLeft, bottomRight) === index) {
console.log("This note changed")
}
else {
console.log("Another note changed")
}
}
}
function reloadContent() {
//notesApi.getNoteFromApi(id)
/*note = notesApi.getNote(id)
dialogHeader.title = title
favoriteButton.selected = favorite
categoryField.text = category
modifiedDetail.modified = modified
parseContent()*/
}
function parseContent() {
//note = notesApi.getNoteFromApi(id, false)
var convertedText = converter.makeHtml(note["content"])
var occurence = -1
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi,
@ -130,6 +106,11 @@ Dialog {
enabled: !notesApi.busy
onClicked: notesApi.getNote(note["id"])
}
/*MenuItem {
text: qsTr("Edit")
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } )
}*/
MenuLabel {
visible: appSettings.currentAccount.length >= 0
text: qsTr("Last update") + ": " + (
@ -141,7 +122,6 @@ Dialog {
DialogHeader {
id: dialogHeader
//title: noteDialog.title
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
}
@ -157,12 +137,6 @@ Dialog {
width: parent.width
spacing: Theme.paddingLarge
/*Separator {
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
}*/
LinkedLabel {
id: contentLabel
x: Theme.horizontalPageMargin
@ -251,7 +225,7 @@ Dialog {
width: parent.width - x
IconButton {
id: favoriteButton
property bool selected: note["favorite"]
property bool selected: false
width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
@ -262,7 +236,6 @@ Dialog {
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note["category"]
placeholderText: qsTr("No category")
label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
@ -270,7 +243,7 @@ Dialog {
categoryField.focus = false
}
onFocusChanged: {
if (focus === false && text !== category) {
if (focus === false && text !== note["category"]) {
notesApi.updateNote(id, {'content': content, 'category': text, 'modified': new Date().valueOf() / 1000}) // This does not seem to work without adding the content
}
}
@ -280,7 +253,8 @@ Dialog {
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
value: new Date(note["modified"] * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
property int modified
onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
}

View file

@ -106,7 +106,7 @@ Page {
id: remorse
}
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } )
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { id: id } )
onPressAndHold: menu.open(note)
Separator {

View file

@ -130,8 +130,8 @@ void NotesModel::setAccount(const QString &account) {
mp_notesStore->setAccount(account);
}
const QJsonObject NotesModel::getNoteById(const int id) const {
return m_notes[id];
const QVariantMap NotesModel::getNoteById(const int id) const {
return m_notes[id].toVariantMap();
}
bool NotesModel::getAllNotes(const QStringList &exclude) {
@ -197,6 +197,12 @@ void NotesModel::insert(const int id, const QJsonObject& note) {
//emit noteInserted(id, note);
qDebug() << "Note inserted";
}
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
}
void NotesModel::update(const int id, const QJsonObject &note) {
@ -216,6 +222,12 @@ void NotesModel::update(const int id, const QJsonObject &note) {
qDebug() << "Note changed";
}
}
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
}
void NotesModel::remove(const int id) {
@ -230,6 +242,12 @@ void NotesModel::remove(const int id) {
}
endRemoveRows();
}
if (sender() == mp_notesApi) {
// TODO
}
if (sender() == mp_notesStore) {
// TODO
}
}
void NotesModel::clear() {

View file

@ -72,7 +72,7 @@ public:
QString account() const;
void setAccount(const QString& account);
const QJsonObject getNoteById(const int id) const;
Q_INVOKABLE const QVariantMap getNoteById(const int id) const;
public slots:
Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList());

View file

@ -191,7 +191,8 @@ bool NotesStore::getNote(const int id, const QStringList& exclude) {
}
bool NotesStore::createNote(const QJsonObject& note) {
/* qDebug() << "Creating note: " << id;
int id = note.value("id").toInt(-1);
qDebug() << "Creating note: " << id;
if (id < 0) {
// TODO probably crate files with an '.json.<NUMBER>.new' extension
qDebug() << "Creating notes without the server API is not supported yet!";
@ -204,7 +205,7 @@ bool NotesStore::createNote(const QJsonObject& note) {
}
else {
qDebug() << "Note already exists";
}*/
}
return false;
}

View file

@ -84,32 +84,32 @@
<context>
<name>EditPage</name>
<message>
<location filename="../qml/pages/EditPage.qml" line="38"/>
<location filename="../qml/pages/EditPage.qml" line="40"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="42"/>
<location filename="../qml/pages/EditPage.qml" line="44"/>
<source>Markdown syntax</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="70"/>
<location filename="../qml/pages/EditPage.qml" line="72"/>
<source>No content</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="155"/>
<location filename="../qml/pages/EditPage.qml" line="157"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="156"/>
<location filename="../qml/pages/EditPage.qml" line="158"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="171"/>
<location filename="../qml/pages/EditPage.qml" line="173"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -143,17 +143,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="239"/>
<location filename="../qml/pages/LoginPage.qml" line="240"/>
<source>Username</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="250"/>
<location filename="../qml/pages/LoginPage.qml" line="251"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="225"/>
<location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Abort</source>
<translation type="unfinished"></translation>
</message>
@ -179,57 +179,57 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="207"/>
<location filename="../qml/pages/LoginPage.qml" line="208"/>
<source>Enforce legacy login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="225"/>
<location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="225"/>
<location filename="../qml/pages/LoginPage.qml" line="226"/>
<source>Re-Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="259"/>
<location filename="../qml/pages/LoginPage.qml" line="260"/>
<source>Test Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="265"/>
<location filename="../qml/pages/LoginPage.qml" line="266"/>
<source>Note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="273"/>
<location filename="../qml/pages/LoginPage.qml" line="274"/>
<source>The &lt;a href=&quot;https://apps.nextcloud.com/apps/notes&quot;&gt;Notes&lt;/a&gt; app needs to be installed on the Nextcloud server for this app to work.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="277"/>
<location filename="../qml/pages/LoginPage.qml" line="278"/>
<source>Security</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="284"/>
<location filename="../qml/pages/LoginPage.qml" line="285"/>
<source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="288"/>
<location filename="../qml/pages/LoginPage.qml" line="289"/>
<source>Do not check certificates</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="289"/>
<location filename="../qml/pages/LoginPage.qml" line="290"/>
<source>Enable this option to allow selfsigned certificates</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="298"/>
<location filename="../qml/pages/LoginPage.qml" line="299"/>
<source>Allow unencrypted connections</source>
<translation type="unfinished"></translation>
</message>
@ -263,52 +263,52 @@
<context>
<name>NotePage</name>
<message>
<location filename="../qml/pages/NotePage.qml" line="125"/>
<location filename="../qml/pages/NotePage.qml" line="96"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="129"/>
<location filename="../qml/pages/NotePage.qml" line="100"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="129"/>
<location filename="../qml/pages/NotePage.qml" line="100"/>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="135"/>
<location filename="../qml/pages/NotePage.qml" line="111"/>
<source>Last update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="138"/>
<location filename="../qml/pages/NotePage.qml" line="114"/>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="145"/>
<location filename="../qml/pages/NotePage.qml" line="120"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="146"/>
<location filename="../qml/pages/NotePage.qml" line="121"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="266"/>
<location filename="../qml/pages/NotePage.qml" line="234"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="267"/>
<location filename="../qml/pages/NotePage.qml" line="235"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="282"/>
<location filename="../qml/pages/NotePage.qml" line="250"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>