1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00
Files
joplin/QtClient/JoplinQtClient/models/item.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

2016-12-10 22:39:53 +00:00
#include "models/item.h"
2017-02-08 21:43:35 +00:00
#include "constants.h"
2016-12-10 22:39:53 +00:00
2017-02-08 21:43:35 +00:00
namespace jop {
2016-12-10 22:39:53 +00:00
Item::Item() {}
2017-02-08 21:43:35 +00:00
QString Item::toFriendlyString() const {
QStringList shownKeys;
shownKeys << "author" << "longitude" << "latitude" << "is_todo" << "todo_due" << "todo_completed";
QStringList output;
output << value("title").toString();
output << "";
output << value("body").toString();
output << "================================================================================";
QHash<QString, Value> values = this->values();
for (int i = 0; i < shownKeys.size(); i++) {
QString key = shownKeys[i];
if (!values.contains(key)) continue;
output << QString("%1: %2").arg(key).arg(values[key].toString());
}
return output.join(NEW_LINE);
}
void Item::patchFriendlyString(const QString& patch) {
QStringList lines = patch.split(jop::NEW_LINE);
QString title("");
if (lines.size() >= 1) {
title = lines[0];
}
bool foundDelimiter = false;
2017-02-09 20:14:36 +00:00
QString body("");
for (int i = 1; i < lines.size(); i++) {
2017-02-08 21:43:35 +00:00
QString line = lines[i];
2017-02-09 20:14:36 +00:00
if (line.indexOf("================================================================================") == 0) {
2017-02-08 21:43:35 +00:00
foundDelimiter = true;
continue;
}
2017-02-09 20:14:36 +00:00
if (!foundDelimiter && line.trimmed() == "" && i == 1) continue; // Skip the first \n
2017-02-08 21:43:35 +00:00
if (!foundDelimiter) {
2017-02-09 20:14:36 +00:00
if (!body.isEmpty()) body += "\n";
body += line;
2017-02-08 21:43:35 +00:00
} else {
int colonIndex = line.indexOf(':');
QString propName = line.left(colonIndex).trimmed();
QString propValue = line.right(line.length() - colonIndex - 1).trimmed();
setValue(propName, propValue);
2017-02-08 21:43:35 +00:00
}
}
2017-02-09 20:14:36 +00:00
setValue("title", title);
setValue("body", body);
2017-02-08 21:43:35 +00:00
}
}