Fixed sorting by date

This commit is contained in:
Scharel Clemens 2019-04-07 12:28:38 +02:00
parent c4268f6212
commit 159ef73315
10 changed files with 143 additions and 115 deletions

View file

@ -37,17 +37,6 @@ Dialog {
noteID = note.id
parseContent()
}
Connections {
target: api
onNoteChanged: {
console.log("Some note changed")
if (id === noteID) {
console.log("This note changed")
reloadContent()
}
else console.log("Other note changed")
}
}
function reloadContent() {
api.getNoteFromApi(note.id)

View file

@ -70,7 +70,7 @@ Page {
anchors.bottomMargin: Theme.paddingMedium
color: Theme.secondaryHighlightColor
font.pixelSize: Theme.fontSizeSmall
text: account.username + "@" + account.server
text: account.username + "@" + account.server.toString().split("://")[1]
}
BusyIndicator {
anchors.verticalCenter: searchField.verticalCenter

View file

@ -123,6 +123,7 @@ Page {
onCurrentIndexChanged: {
appSettings.autoSyncInterval = autoSyncIntervalRepeater.model[currentIndex]
if (autoSyncIntervalRepeater.model[currentIndex] === 42 && theAnswer.enabled) {
console.log(theAnswer.body)
theAnswer.publish()
}
}

View file

@ -4,32 +4,40 @@ Note::Note(QObject *parent) : QObject(parent) {
m_id = -1;
m_modified = 0;
m_error = true;
connect(this, SIGNAL(idChanged(int)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(modifiedChanged(uint)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(categoryChanged(QString)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(contentChanged(QString)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(favoriteChanged(bool)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(etagChanged(QString)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(errorChanged(bool)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(errorMessageChanged(QString)), this, SIGNAL(noteChanged()));
connect(this, SIGNAL(dateStringChanged(QString)), this, SIGNAL(noteChanged()));
}
Note::Note(const Note& note, QObject *parent) : QObject(parent) {
m_id = note.id();
m_modified = note.modified();
m_title = note.title();
m_category = note.category();
m_content = note.content();
m_favorite = note.favorite();
m_etag = note.etag();
m_error = note.error();
m_errorMessage = note.errorMessage();
m_date = note.date();
setId(note.id());
setModified(note.modified());
setTitle(note.title());
setCategory(note.category());
setContent(note.content());
setFavorite(note.favorite());
setEtag(note.etag());
setError(note.error());
setErrorMessage(note.errorMessage());
}
Note& Note::operator=(const Note& note) {
m_id = note.id();
m_modified = note.modified();
m_title = note.title();
m_category = note.category();
m_content = note.content();
m_favorite = note.favorite();
m_etag = note.etag();
m_error = note.error();
m_errorMessage = note.errorMessage();
m_date = note.date();
setId(note.id());
setModified(note.modified());
setTitle(note.title());
setCategory(note.category());
setContent(note.content());
setFavorite(note.favorite());
setEtag(note.etag());
setError(note.error());
setErrorMessage(note.errorMessage());
return *this;
}

View file

@ -18,7 +18,7 @@ class Note : public QObject {
Q_PROPERTY(QString etag READ etag WRITE setEtag NOTIFY etagChanged)
Q_PROPERTY(bool error READ error WRITE setError NOTIFY errorChanged)
Q_PROPERTY(QString errorMessage READ errorMessage WRITE setErrorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(QString date READ date NOTIFY dateChanged)
Q_PROPERTY(QString dateString READ dateString NOTIFY dateStringChanged)
public:
Note(QObject *parent = NULL);
@ -33,30 +33,26 @@ public:
QString etag() const { return m_etag; }
bool error() const { return m_error; }
QString errorMessage() const { return m_errorMessage; }
QString date() const { return m_date; }
QString dateString() const {
QDateTime date;
QString dateString;
date.setTime_t(m_modified);
qint64 diff = date.daysTo(QDateTime::currentDateTime());
if (diff == 0)
dateString = tr("Today");
else if (diff == 1)
dateString = tr("Yesterday");
else if (diff < 7)
dateString = date.toLocalTime().toString("dddd");
else if (date.toLocalTime().toString("yyyy") == QDateTime::currentDateTime().toString("yyyy"))
dateString = date.toLocalTime().toString("MMMM");
else
dateString = date.toLocalTime().toString("MMMM yyyy");
return dateString;
}
void setId(int id) { if (id != m_id) { m_id = id; emit idChanged(id); } }
void setModified(uint modified) {
if (modified != m_modified) {
m_modified = modified;
QDateTime date;
QString newDate;
date.setTime_t(modified);
qint64 diff = date.daysTo(QDateTime::currentDateTime());
if (diff == 0)
newDate = "Today";
else if (diff == 1)
newDate = "Yesterday";
else if (diff < 7)
newDate = date.toLocalTime().toString("dddd");
else if (date.toLocalTime().toString("yyyy") == QDateTime::currentDateTime().toString("yyyy"))
newDate = date.toLocalTime().toString("MMMM");
else
newDate = date.toLocalTime().toString("MMMM yyyy");
if (newDate != m_date) { m_date = newDate; emit dateChanged(newDate); }
emit modifiedChanged(modified);
}
}
void setModified(uint modified) { if (modified != m_modified) { m_modified = modified; emit modifiedChanged(modified); emit dateStringChanged(dateString()); } }
void setTitle(QString title) { if (title != m_title) { m_title = title; emit titleChanged(title); } }
void setCategory(QString category) { if (category != m_category) { m_category = category; emit categoryChanged(category); } }
void setContent(QString content) { if (content != m_content) { m_content = content; emit contentChanged(content); } }
@ -64,7 +60,6 @@ public:
void setEtag(QString etag) { if (etag != m_etag) { m_etag = etag; emit etagChanged(etag); } }
void setError(bool error) { if (error != m_error) { m_error = error; emit errorChanged(error); } }
void setErrorMessage(QString errorMessage) { if (errorMessage != m_errorMessage) { m_errorMessage = errorMessage; emit errorMessageChanged(errorMessage); } }
void setDate(QString date) { if (date != m_date) { m_date = date; emit dateChanged(date); } }
Note& operator=(const Note& note);
bool operator==(const Note& note) const {
@ -116,7 +111,8 @@ signals:
void etagChanged(QString etag);
void errorChanged(bool error);
void errorMessageChanged(QString errorMessage);
void dateChanged(QString date);
void dateStringChanged(QString date);
void noteChanged();
private:
int m_id;
@ -128,7 +124,6 @@ private:
QString m_etag;
bool m_error;
QString m_errorMessage;
QString m_date;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Note::SearchAttributes)

View file

@ -214,7 +214,7 @@ QHash<int, QByteArray> NotesModel::roleNames() const {
{NotesModel::EtagRole, "etag"},
{NotesModel::ErrorRole, "error"},
{NotesModel::ErrorMessageRole, "errorMessage"},
{NotesModel::DateRole, "date"}
{NotesModel::DateStringRole, "date"}
};
}
@ -265,7 +265,7 @@ QVariant NotesModel::data(const QModelIndex &index, int role) const {
else if (role == EtagRole) return m_notes[index.row()].note->etag();
else if (role == ErrorRole) return m_notes[index.row()].note->error();
else if (role == ErrorMessageRole) return m_notes[index.row()].note->errorMessage();
else if (role == DateRole) return m_notes[index.row()].note->date();
else if (role == DateStringRole) return m_notes[index.row()].note->dateString();
return QVariant();
}
@ -285,7 +285,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
else if (role == ModifiedRole && m_notes[index.row()].note->modified() != value.toUInt()) {
m_notes[index.row()].note->setModified(value.toInt());
emit dataChanged(this->index(index.row()), this->index(index.row()), QVector<int> { 1, role } ); // TODO remove when signals from Note are connected
emit dataChanged(this->index(index.row()), this->index(index.row()), QVector<int> { 1, DateRole} ); // TODO remove when signals from Note are connected
emit dataChanged(this->index(index.row()), this->index(index.row()), QVector<int> { 1, DateStringRole} ); // TODO remove when signals from Note are connected
sort();
return true;
}
@ -331,9 +331,9 @@ void NotesModel::sort() {
emit layoutAboutToBeChanged(QList<QPersistentModelIndex> (), VerticalSortHint);
for (int i = 0; i < m_notes.size(); i++) {
if (m_favoritesOnTop && m_notes[i].note->favorite())
favorites.insert(QString::number(m_notes[i].note->modified()), m_notes[i]);
favorites.insert(QString::number(std::numeric_limits<uint>::max() - m_notes[i].note->modified()), m_notes[i]);
else
map.insert(QString::number(m_notes[i].note->modified()), m_notes[i]);
map.insert(QString::number(std::numeric_limits<uint>::max() - m_notes[i].note->modified()), m_notes[i]);
}
notes = favorites.values();
notes.append(map.values());

View file

@ -50,7 +50,7 @@ public:
EtagRole = Qt::UserRole + 7,
ErrorRole = Qt::UserRole + 8,
ErrorMessageRole = Qt::UserRole + 9,
DateRole = Qt::UserRole + 10
DateStringRole = Qt::UserRole + 10
};
QHash<int, QByteArray> roleNames() const;

View file

@ -163,19 +163,30 @@
<translation>MIT Lizenz</translation>
</message>
</context>
<context>
<name>Note</name>
<message>
<source>Today</source>
<translation>Heute</translation>
</message>
<message>
<source>Yesterday</source>
<translation>Gestern</translation>
</message>
</context>
<context>
<name>NoteDelegateModel</name>
<message>
<source>Modified</source>
<translation type="unfinished">Geändert</translation>
<translation>Geändert</translation>
</message>
<message>
<source>Delete</source>
<translation type="unfinished">Löschen</translation>
<translation>Löschen</translation>
</message>
<message>
<source>Deleting note</source>
<translation type="unfinished"></translation>
<translation>Lösche Notiz</translation>
</message>
</context>
<context>
@ -232,75 +243,75 @@
<name>NotesPage</name>
<message>
<source>Settings</source>
<translation type="unfinished">Einstellungen</translation>
<translation>Einstellungen</translation>
</message>
<message>
<source>Add note</source>
<translation type="unfinished"></translation>
<translation>Notiz hinzufügen</translation>
</message>
<message>
<source>Reload</source>
<translation type="unfinished">Neu laden</translation>
<translation>Neu laden</translation>
</message>
<message>
<source>Updating...</source>
<translation type="unfinished">Aktualisiere...</translation>
<translation>Aktualisiere...</translation>
</message>
<message>
<source>Last update</source>
<translation type="unfinished">Zuletzt aktualisiert</translation>
<translation>Zuletzt aktualisiert</translation>
</message>
<message>
<source>never</source>
<translation type="unfinished">noch nie</translation>
<translation>noch nie</translation>
</message>
<message>
<source>No account yet</source>
<translation type="unfinished"></translation>
<translation>Noch kein Konto eingerichtet</translation>
</message>
<message>
<source>Got to the settings to add an account</source>
<translation type="unfinished"></translation>
<translation>Gehe in die Einstellungen um ein Konto hinzuzufügen</translation>
</message>
<message>
<source>No notes yet</source>
<translation type="unfinished"></translation>
<translation>Keine Notizen vorhanden</translation>
</message>
<message>
<source>Pull down to add a note</source>
<translation type="unfinished"></translation>
<translation>Ziehe nach unten um eine Notiz zu erstellen</translation>
</message>
<message>
<source>No result</source>
<translation type="unfinished"></translation>
<translation>Nichts gefunden</translation>
</message>
<message>
<source>Try another query</source>
<translation type="unfinished"></translation>
<translation>Probiere eine andere Suche</translation>
</message>
<message>
<source>An error occurred</source>
<translation type="unfinished"></translation>
<translation>Ein Fehler ist aufgetreten</translation>
</message>
<message>
<source>Open the settings to configure your Nextcloud accounts</source>
<translation type="unfinished"></translation>
<translation>Gehe in die Einstellungen um deine Nextcloud Konten zu verwalten</translation>
</message>
<message>
<source>Nextcloud Notes</source>
<translation type="unfinished">Nextcloud Notizen</translation>
<translation>Nextcloud Notizen</translation>
</message>
<message>
<source>Modified</source>
<translation type="unfinished">Geändert</translation>
<translation>Geändert</translation>
</message>
<message>
<source>Delete</source>
<translation type="unfinished">Löschen</translation>
<translation>Löschen</translation>
</message>
<message>
<source>Deleting note</source>
<translation type="unfinished"></translation>
<translation>Lösche Notiz</translation>
</message>
</context>
<context>

View file

@ -163,6 +163,17 @@
<translation>MIT License</translation>
</message>
</context>
<context>
<name>Note</name>
<message>
<source>Today</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Yesterday</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NoteDelegateModel</name>
<message>

View file

@ -198,6 +198,19 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Note</name>
<message>
<location filename="../src/note.h" line="42"/>
<source>Today</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/note.h" line="44"/>
<source>Yesterday</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NoteDelegateModel</name>
<message>
@ -219,52 +232,52 @@
<context>
<name>NotePage</name>
<message>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<location filename="../qml/pages/NotePage.qml" line="95"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="110"/>
<location filename="../qml/pages/NotePage.qml" line="99"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="110"/>
<location filename="../qml/pages/NotePage.qml" line="99"/>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="116"/>
<location filename="../qml/pages/NotePage.qml" line="105"/>
<source>Last update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="119"/>
<location filename="../qml/pages/NotePage.qml" line="108"/>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="126"/>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="127"/>
<location filename="../qml/pages/NotePage.qml" line="116"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="247"/>
<location filename="../qml/pages/NotePage.qml" line="236"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="248"/>
<location filename="../qml/pages/NotePage.qml" line="237"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="263"/>
<location filename="../qml/pages/NotePage.qml" line="252"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -458,102 +471,102 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="133"/>
<location filename="../qml/pages/SettingsPage.qml" line="134"/>
<source>The Answer is 42</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="134"/>
<location filename="../qml/pages/SettingsPage.qml" line="135"/>
<source>Congratulation you found the Answer to the Ultimate Question of Life, The Universe, and Everything!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="142"/>
<location filename="../qml/pages/SettingsPage.qml" line="143"/>
<source>Appearance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="149"/>
<location filename="../qml/pages/SettingsPage.qml" line="150"/>
<source>No sorting</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="172"/>
<location filename="../qml/pages/SettingsPage.qml" line="173"/>
<source>Favorites on top</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="173"/>
<location filename="../qml/pages/SettingsPage.qml" line="174"/>
<source>Show notes marked as favorite above the others</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="146"/>
<location filename="../qml/pages/SettingsPage.qml" line="147"/>
<source>Last edited</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="147"/>
<location filename="../qml/pages/SettingsPage.qml" line="148"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="148"/>
<location filename="../qml/pages/SettingsPage.qml" line="149"/>
<source>Title alphabetically</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="150"/>
<location filename="../qml/pages/SettingsPage.qml" line="151"/>
<source>Sort notes by</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="151"/>
<location filename="../qml/pages/SettingsPage.qml" line="152"/>
<source>This will also change how the notes are grouped</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="178"/>
<location filename="../qml/pages/SettingsPage.qml" line="179"/>
<source>Show separator</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="179"/>
<location filename="../qml/pages/SettingsPage.qml" line="180"/>
<source>Show a separator line between the notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="189"/>
<location filename="../qml/pages/SettingsPage.qml" line="190"/>
<source>lines</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="190"/>
<location filename="../qml/pages/SettingsPage.qml" line="191"/>
<source>Number of lines in the preview</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="195"/>
<location filename="../qml/pages/SettingsPage.qml" line="196"/>
<source>Editing</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="198"/>
<location filename="../qml/pages/SettingsPage.qml" line="199"/>
<source>Monospaced font</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="199"/>
<location filename="../qml/pages/SettingsPage.qml" line="200"/>
<source>Use a monospeced font to edit a note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="204"/>
<location filename="../qml/pages/SettingsPage.qml" line="205"/>
<source>Capital &apos;X&apos; in checkboxes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/SettingsPage.qml" line="205"/>
<location filename="../qml/pages/SettingsPage.qml" line="206"/>
<source>For interoperability with other apps such as Joplin</source>
<translation type="unfinished"></translation>
</message>