Format all c++ files

This commit is contained in:
Vyn 2024-04-13 11:52:42 +02:00
parent 081e107b9b
commit f8f49233dc
21 changed files with 683 additions and 599 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ todo.md
.qmlls.ini
.clangd
.cache
.nvimrc

View file

@ -8,30 +8,34 @@
#define CPP_UTILS_VECTOR_H
#include <algorithm>
#include <functional>
#include <optional>
#include <vector>
#include <concepts>
namespace cpputils::vector {
namespace cpputils::vector
{
template <typename C, typename T>
concept AnyIterable =
std::same_as<typename C::value_type, T> &&
requires (C c) {
{ c.begin() } -> std::forward_iterator;
{ c.end() } -> std::forward_iterator;
{ const_cast<const C&>(c).begin() } -> std::forward_iterator;
{ const_cast<const C&>(c).end() } -> std::forward_iterator;
concept AnyIterable = std::same_as<typename C::value_type, T> && requires(C c) {
{
c.begin()
} -> std::forward_iterator;
{
c.end()
} -> std::forward_iterator;
{
const_cast<const C &>(c).begin()
} -> std::forward_iterator;
{
const_cast<const C &>(c).end()
} -> std::forward_iterator;
};
template<typename T>
bool contains(const std::vector<T>& vec, const T& value) {
template <typename T> bool contains(const std::vector<T> &vec, const T &value)
{
return std::ranges::find(vec, value) != vec.end();
}
template<typename T>
bool containsAll(const std::vector<T>& vec, const AnyIterable<T> auto vec2) {
template <typename T> bool containsAll(const std::vector<T> &vec, const AnyIterable<T> auto vec2)
{
for (auto &elem : vec) {
if (!contains(vec2, elem)) {
return false;
@ -39,6 +43,6 @@ namespace cpputils::vector {
}
return true;
}
}
} // namespace cpputils::vector
#endif

View file

@ -6,8 +6,10 @@
#include "Backend.h"
#include "core/TodoMd.h"
#include <ostream>
Backend::Backend() {
Backend::Backend()
{
std::cout << "Backend created" << std::endl;
QDir().mkdir(QDir::homePath() + "/.config/mirai");
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
@ -37,47 +39,55 @@ Backend::Backend() {
rebuildQMLTasksList();
}
void Backend::addTodo(QString newTodo, QString date) {
void Backend::addTodo(QString newTodo, QString date)
{
mirai.addTask(newTodo.toStdString(), date.toStdString());
mirai.save();
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::addTodoFromRawFormat(QString text, QString date) {
void Backend::addTodoFromRawFormat(QString text, QString date)
{
mirai.addTask(mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString()));
mirai.save();
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::addTagFilter(QString tag) {
void Backend::addTagFilter(QString tag)
{
view.lock()->addTagFilter(tag.toStdString());
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::removeTagFilter(QString tag) {
void Backend::removeTagFilter(QString tag)
{
view.lock()->removeTagFilter(tag.toStdString());
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::removeFilters() {
void Backend::removeFilters()
{
view.lock()->removeFilters();
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date) {
void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date)
{
QMLTaskItem &taskItem = QMLTasks[todoIndex];
*(taskItem.taskItem) = mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
*(taskItem.taskItem) =
mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
mirai.save();
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::updateTodo(int todoIndex, QString state, QString text, QString date) {
void Backend::updateTodo(int todoIndex, QString state, QString text, QString date)
{
QMLTaskItem &taskItem = QMLTasks[todoIndex];
taskItem.taskItem->state = state == "TODO" ? mirai::TODO : mirai::DONE;
if (state == "DONE") {
@ -92,7 +102,8 @@ void Backend::updateTodo(int todoIndex, QString state, QString text, QString dat
emit tasksChanged();
}
void Backend::removeTodo(int todoIndex) {
void Backend::removeTodo(int todoIndex)
{
QMLTaskItem &taskItem = QMLTasks[todoIndex];
mirai.removeTask(taskItem.taskItem);
mirai.save();
@ -100,13 +111,15 @@ void Backend::removeTodo(int todoIndex) {
emit tasksChanged();
}
void Backend::hideCompletedTasks(bool shouldHide) {
void Backend::hideCompletedTasks(bool shouldHide)
{
shouldHideCompletedTasks_ = shouldHide;
rebuildQMLTasksList();
emit tasksChanged();
}
void Backend::rebuildQMLTasksList() {
void Backend::rebuildQMLTasksList()
{
QMLTasks.clear();
std::string lastDate = "";
std::time_t t = std::time(nullptr);
@ -115,7 +128,8 @@ void Backend::rebuildQMLTasksList() {
currentDate << std::put_time(&tm, "%Y-%m-%d");
for (int i = 0; i < view.lock()->count(); ++i) {
mirai::TaskItem &task = (*view.lock())[i];
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() && task.getDate() < currentDate.str()) {
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() &&
task.getDate() < currentDate.str()) {
continue;
}
bool shouldShowDate = false;
@ -127,14 +141,10 @@ void Backend::rebuildQMLTasksList() {
for (auto &tag : task.getTags()) {
qStringTags.push_back(QString::fromStdString(tag));
}
QMLTasks.push_back({
.taskItem = &task,
.shouldShowDate = shouldShowDate,
.tags = qStringTags
});
QMLTasks.push_back(
{.taskItem = &task, .shouldShowDate = shouldShowDate, .tags = qStringTags});
}
QMLTags.clear();
for (auto &tag : mirai.getTags()) {
QMLTags.push_back(QString::fromStdString(tag));
@ -146,18 +156,22 @@ void Backend::rebuildQMLTasksList() {
}
}
QVariant Backend::getTasks() {
QVariant Backend::getTasks()
{
return QVariant::fromValue(QMLTasks);
}
QVariant Backend::getTags() {
QVariant Backend::getTags()
{
return QVariant::fromValue(QMLTags);
}
QVariant Backend::getActiveTagsFilter() {
QVariant Backend::getActiveTagsFilter()
{
return QVariant::fromValue(QMLActiveTagsFilter);
}
bool Backend::shouldHideCompletedTasks() {
bool Backend::shouldHideCompletedTasks()
{
return shouldHideCompletedTasks_;
}

View file

@ -10,21 +10,18 @@
#include "QtCore/qcontainerfwd.h"
#include "QtCore/qtmetamacros.h"
#include "QtCore/qvariant.h"
#include <QtQml/qqmlregistration.h>
#include <QtCore/QObject>
#include <QtCore/QDateTime>
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QDir>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonArray>
#include <iostream>
#include <memory>
#include "core/TaskItem.h"
#include "core/TasksView.h"
#include "core/TodoMd.h"
#include "core/Mirai.h"
#include "core/TasksView.h"
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtQml/qqmlregistration.h>
#include <memory>
#include "TaskItem.h"
@ -35,10 +32,10 @@ class Backend : public QObject
Q_PROPERTY(QVariant tasks READ getTasks NOTIFY tasksChanged)
Q_PROPERTY(QVariant tags READ getTags NOTIFY tasksChanged)
Q_PROPERTY(QVariant activeTagsFilter READ getActiveTagsFilter NOTIFY tasksChanged)
Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks NOTIFY tasksChanged)
Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks
NOTIFY tasksChanged)
public:
Backend();
Q_INVOKABLE void addTodo(QString newTodo, QString date);
@ -52,7 +49,6 @@ public:
Q_INVOKABLE void hideCompletedTasks(bool shouldHide);
private:
void rebuildQMLTasksList();
QVariant getTasks();

View file

@ -7,33 +7,40 @@
#include "TaskItem.h"
#include "core/TodoMd.h"
QString QMLTaskItem::getRawFormat() {
QString QMLTaskItem::getRawFormat()
{
return QString::fromStdString(mirai::TodoMdFormat::TaskToString(*taskItem));
}
QString QMLTaskItem::getText() {
QString QMLTaskItem::getText()
{
return QString::fromStdString(taskItem->getText());
}
QString QMLTaskItem::getState() {
QString QMLTaskItem::getState()
{
return QString::fromStdString(taskItem->getState() == mirai::TODO ? "TODO" : "DONE");
}
QString QMLTaskItem::getDate() {
QString QMLTaskItem::getDate()
{
return QString::fromStdString(taskItem->getDate());
}
QString QMLTaskItem::getTime() {
QString QMLTaskItem::getTime()
{
if (taskItem->getStartTime() != "" && taskItem->getEndTime() != "") {
return QString::fromStdString(taskItem->getStartTime() + "-" + taskItem->getEndTime());
}
return "";
}
QList<QString> QMLTaskItem::getTags() {
QList<QString> QMLTaskItem::getTags()
{
return tags;
}
bool QMLTaskItem::getShouldShowDate() {
bool QMLTaskItem::getShouldShowDate()
{
return shouldShowDate;
}

View file

@ -8,8 +8,8 @@
#define QML_TASKITEM_H
#include "QtCore/qvariant.h"
#include <QtQml/qqmlregistration.h>
#include <QtCore/QString>
#include <QtQml/qqmlregistration.h>
#include <memory>
#include "core/TaskItem.h"
@ -27,7 +27,6 @@ struct QMLTaskItem {
QML_VALUE_TYPE(taskItem)
public:
QString getText();
QString getRawFormat();
QString getState();

View file

@ -8,35 +8,40 @@
#include "TaskItem.h"
#include "cpp-utils/vector.h"
namespace mirai {
namespace mirai
{
void Mirai::loadFile(const std::string& path) {
void Mirai::loadFile(const std::string &path)
{
auto tasksFile = TodoMdFormat::readFile(path);
files->push_back(std::move(tasksFile));
tags.clear();
for (auto &task : (*files)[0].getTasks()) {
for (auto &tag : task->getTags()) {
if (vectorUtils::contains(tags, tag)) {
if (!vectorUtils::contains(tags, tag)) {
tags.push_back(tag);
}
}
}
}
void Mirai::save() {
void Mirai::save()
{
for (auto &file : *files) {
TodoMdFormat::writeFile(file);
}
}
void Mirai::addTask(TaskItem taskItem) {
void Mirai::addTask(TaskItem taskItem)
{
(*files)[0].addTask(taskItem);
for (auto &view : views) {
view->update();
}
}
void Mirai::addTask(std::string text, std::string date) {
void Mirai::addTask(std::string text, std::string date)
{
/*std::time_t t = std::time(nullptr);*/
/*std::tm tm = *std::localtime(&t);*/
/*std::stringstream ssCreationDate;*/
@ -47,20 +52,23 @@ namespace mirai {
}
}
void Mirai::removeTask(const TaskItem* taskItem) {
void Mirai::removeTask(const TaskItem *taskItem)
{
(*files)[0].removeTask(taskItem);
for (auto &view : views) {
view->update();
}
}
std::weak_ptr<TasksView> Mirai::getTasks() {
std::weak_ptr<TasksView> Mirai::getTasks()
{
auto view = std::make_shared<TasksView>(files);
views.push_back(view);
return view;
}
const std::vector<std::string>& Mirai::getTags() {
const std::vector<std::string> &Mirai::getTags()
{
return tags;
}
}
} // namespace mirai

View file

@ -14,12 +14,13 @@
#include <algorithm>
#include <memory>
namespace mirai {
namespace mirai
{
class Mirai {
class Mirai
{
public:
void loadFile(const std::string &path);
void save();
void addTask(TaskItem taskItem);
@ -30,7 +31,6 @@ namespace mirai {
const std::vector<std::string> &getTags();
private:
// The `TasksFile`s are shared to the views, their lifetime can outlive
// this (Mirai) object
// because we can't control if the caller will keep the main object alive.
@ -42,5 +42,5 @@ namespace mirai {
std::vector<std::shared_ptr<TasksView>> views;
std::vector<std::string> tags;
};
}
} // namespace mirai
#endif

View file

@ -4,38 +4,69 @@
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include "TaskItem.h"
#include "cpp-utils/vector.h"
namespace mirai {
namespace mirai
{
void TaskItem::markAsDone() {
void TaskItem::markAsDone()
{
state = DONE;
}
void TaskItem::markAsUndone() {
void TaskItem::markAsUndone()
{
state = TODO;
}
void TaskItem::setDate(const std::string& date) {
void TaskItem::setDate(const std::string &date)
{
this->date = date;
}
void TaskItem::setText(const std::string& text) {
void TaskItem::setText(const std::string &text)
{
this->text = text;
}
const std::string& TaskItem::getText() const { return text; }
const TaskItemState& TaskItem::getState() const { return state; }
const std::string& TaskItem::getDate() const { return date; }
const std::string& TaskItem::getStartTime() const { return startTime; }
const std::string& TaskItem::getEndTime() const { return endTime; }
const Tags& TaskItem::getTags() const { return tags; }
bool TaskItem::hasDate() const { return isDate(date); }
const std::string &TaskItem::getText() const
{
return text;
}
const TaskItemState &TaskItem::getState() const
{
return state;
}
bool TaskItem::hasTag(const std::string& tag) const {
const std::string &TaskItem::getDate() const
{
return date;
}
const std::string &TaskItem::getStartTime() const
{
return startTime;
}
const std::string &TaskItem::getEndTime() const
{
return endTime;
}
const Tags &TaskItem::getTags() const
{
return tags;
}
bool TaskItem::hasDate() const
{
return isDate(date);
}
bool TaskItem::hasTag(const std::string &tag) const
{
return vectorUtils::contains(tags, tag);
}
}
} // namespace mirai

View file

@ -20,15 +20,12 @@
#include <string>
#include <vector>
namespace mirai {
enum TaskItemState {
TODO,
DONE
};
namespace mirai
{
enum TaskItemState { TODO, DONE };
struct TaskItem {
public:
void markAsDone();
void markAsUndone();
@ -53,6 +50,6 @@ namespace mirai {
std::string endTime;
Tags tags;
};
}
} // namespace mirai
#endif

View file

@ -8,42 +8,58 @@
#include "TaskItem.h"
#include <memory>
namespace mirai {
namespace mirai
{
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path) {
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path)
{
for (const auto &task : params.tasks) {
tasks.push_back(std::make_unique<TaskItem>(task));
}
sortByDate();
}
const std::string& TasksFile::getName() const { return name; }
const std::string& TasksFile::getPath() const { return path; }
TasksPtrs& TasksFile::getTasks() { return tasks; }
const std::string &TasksFile::getName() const
{
return name;
}
void TasksFile::addTask(TaskItem taskItem) {
const std::string &TasksFile::getPath() const
{
return path;
}
TasksPtrs &TasksFile::getTasks()
{
return tasks;
}
void TasksFile::addTask(TaskItem taskItem)
{
tasks.push_back(std::make_unique<TaskItem>(taskItem));
sortByDate();
}
void TasksFile::addTask(std::string text, std::string date) {
auto newTask = std::make_unique<TaskItem>(TaskItem{
.text = text,
.state = TODO,
.date = date == "" ? "No date" : date
});
void TasksFile::addTask(std::string text, std::string date)
{
auto newTask = std::make_unique<TaskItem>(
TaskItem{.text = text, .state = TODO, .date = date == "" ? "No date" : date});
tasks.push_back(std::move(newTask));
sortByDate();
}
void TasksFile::removeTask(const TaskItem* taskToRemove) {
tasks.erase(std::remove_if(tasks.begin(), tasks.end(), [&] (const std::unique_ptr<TaskItem>& taskInFilter){
void TasksFile::removeTask(const TaskItem *taskToRemove)
{
tasks.erase(std::remove_if(tasks.begin(), tasks.end(),
[&](const std::unique_ptr<TaskItem> &taskInFilter) {
return taskInFilter.get() == taskToRemove;
}));
}
void TasksFile::sortByDate() {
std::sort(tasks.begin(), tasks.end(), [] (const std::unique_ptr<TaskItem>& t1, const std::unique_ptr<TaskItem>& t2) {
void TasksFile::sortByDate()
{
std::sort(tasks.begin(), tasks.end(),
[](const std::unique_ptr<TaskItem> &t1, const std::unique_ptr<TaskItem> &t2) {
if (t1->hasDate() && !t2->hasDate()) {
return true;
} else if (!t1->hasDate() && t2->hasDate()) {
@ -52,4 +68,4 @@ namespace mirai {
return t1->date < t2->date;
});
}
}
} // namespace mirai

View file

@ -7,6 +7,9 @@
#ifndef MIRAI_TASKSFILE_H
#define MIRAI_TASKSFILE_H
#include "TaskItem.h"
#include "using.h"
#include "utils.h"
#include <algorithm>
#include <ctime>
#include <fstream>
@ -19,12 +22,9 @@
#include <stdexcept>
#include <string>
#include <vector>
#include "TaskItem.h"
#include "using.h"
#include "utils.h"
namespace mirai {
namespace mirai
{
using TasksPtrs = std::vector<std::unique_ptr<TaskItem>>;
@ -34,10 +34,10 @@ namespace mirai {
std::vector<TaskItem> tasks;
};
class TasksFile {
class TasksFile
{
public:
TasksFile(TasksFileConstructor params);
void addTask(std::string text, std::string date);
@ -54,6 +54,6 @@ namespace mirai {
std::string path;
TasksPtrs tasks;
};
}
} // namespace mirai
#endif

View file

@ -7,53 +7,63 @@
#include "TasksView.h"
#include "cpp-utils/vector.h"
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <ostream>
#include <string>
namespace mirai {
namespace mirai
{
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files) {
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files)
{
update();
}
TaskItem& TasksView::operator[](int index) {
TaskItem &TasksView::operator[](int index)
{
return *(tasksToShow.at(index));
}
int TasksView::count() const { return tasksToShow.size(); }
size_t TasksView::count() const
{
return tasksToShow.size();
}
void TasksView::update() {
void TasksView::update()
{
tasksToShow.clear();
for (auto &file : *files) {
for (auto &task : file.getTasks()) {
std::function<bool(const std::string&)> f = [&](const std::string& tag) {
return task->hasTag(tag);
};
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags()))
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) {
continue;
}
tasksToShow.push_back(task.get());
}
}
}
void TasksView::addTagFilter(const std::string& tag) {
void TasksView::addTagFilter(const std::string &tag)
{
tagsFilter.push_back(tag);
update();
}
void TasksView::removeTagFilter(const std::string& tag) {
tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(), [&] (const auto& tagInFilter){
return tag == tagInFilter;
}));
void TasksView::removeTagFilter(const std::string &tag)
{
tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(),
[&](const auto &tagInFilter) { return tag == tagInFilter; }));
update();
}
void TasksView::removeFilters() {
void TasksView::removeFilters()
{
tagsFilter.clear();
update();
}
const std::vector<std::string>& TasksView::getActiveTagsFilter() {
const std::vector<std::string> &TasksView::getActiveTagsFilter()
{
return tagsFilter;
}
}
} // namespace mirai

View file

@ -8,23 +8,22 @@
#define MIRAI_TASKSVIEW_H
#include "TasksFile.h"
#include "using.h"
#include <algorithm>
#include <iostream>
#include <cstddef>
#include <memory>
#include <ostream>
#include <string>
namespace mirai {
namespace mirai
{
class TasksView {
class TasksView
{
public:
TasksView(std::shared_ptr<std::vector<TasksFile>> files);
TaskItem &operator[](int index);
int count() const;
size_t count() const;
void update();
void addTagFilter(const std::string &tag);
void removeTagFilter(const std::string &tag);
@ -32,10 +31,9 @@ namespace mirai {
const Tags &getActiveTagsFilter();
private:
std::shared_ptr<std::vector<TasksFile>> files;
std::vector<TaskItem *> tasksToShow;
Tags tagsFilter;
};
}
} // namespace mirai
#endif

View file

@ -8,9 +8,11 @@
#include "TaskItem.h"
#include "cpp-utils/vector.h"
namespace mirai {
namespace mirai
{
TasksFile TodoMdFormat::readFile(const std::string& path) {
TasksFile TodoMdFormat::readFile(const std::string &path)
{
std::ifstream file(path);
if (!file.is_open()) {
throw std::runtime_error("todo.txt file not found");
@ -35,22 +37,18 @@ namespace mirai {
}
}
file.close();
TasksFile tasks({
.name = name,
.path = path,
.tasks = taskItems
});
TasksFile tasks({.name = name, .path = path, .tasks = taskItems});
return tasks;
}
Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) {
Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata)
{
Tags tags;
std::regex regex("(#[a-zA-Z0-1]+)");
std::smatch matches;
while (std::regex_search(metadata, matches, regex))
{
while (std::regex_search(metadata, matches, regex)) {
if (!vectorUtils::contains(tags, matches[0].str())) {
tags.push_back(matches[0]);
}
@ -59,7 +57,8 @@ namespace mirai {
return tags;
}
void TodoMdFormat::writeFile(TasksFile& tasks) {
void TodoMdFormat::writeFile(TasksFile &tasks)
{
std::ofstream file(tasks.getPath());
if (!file.is_open()) {
throw std::runtime_error("can't create todo.txt");
@ -77,15 +76,18 @@ namespace mirai {
file.close();
}
std::string TodoMdFormat::fieldWithSpace(const std::string& field) {
std::string TodoMdFormat::fieldWithSpace(const std::string &field)
{
if (field.length() == 0)
return "";
return (field + " ");
}
TaskItem TodoMdFormat::StringToTask(const std::string& str, const std::string& date) {
TaskItem TodoMdFormat::StringToTask(const std::string &str, const std::string &date)
{
std::smatch matches;
std::regex regex("- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?");
std::regex regex(
"- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?");
std::regex_match(str, matches, regex);
/*std::cout << "line " << str << std::endl;*/
@ -100,18 +102,17 @@ namespace mirai {
std::string text = stringUtils::trim(matches[5]);
TaskItem taskItem = {
.text = text,
TaskItem taskItem = {.text = text,
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
.date = date,
.startTime = matches[3],
.endTime = matches[4],
.tags = extractTagsFromMetadata(matches[7])
};
.tags = extractTagsFromMetadata(matches[7])};
return taskItem;
}
std::string TodoMdFormat::TaskToString(const TaskItem& task) {
std::string TodoMdFormat::TaskToString(const TaskItem &task)
{
std::string str = task.getText();
if (task.getTags().size() > 0) {
str += " --";
@ -125,5 +126,4 @@ namespace mirai {
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
return str;
}
}
} // namespace mirai

View file

@ -20,11 +20,12 @@
#include <string>
#include <vector>
namespace mirai {
namespace mirai
{
class TodoMdFormat {
class TodoMdFormat
{
public:
static TasksFile readFile(const std::string &path);
static void writeFile(TasksFile &tasks);
@ -32,11 +33,10 @@ namespace mirai {
static TaskItem StringToTask(const std::string &str, const std::string &date);
private:
static std::string fieldWithSpace(const std::string &field);
static TaskItem parseLine(const std::string &line);
static Tags extractTagsFromMetadata(std::string metadata);
};
}
} // namespace mirai
#endif

View file

@ -65,7 +65,8 @@
/*static TaskItem parseLine(const std::string& line) {*/
/*std::smatch matches;*/
/*std::regex regex("(^x )?(\\([A-Z]\\) )?([0-9]{4}-[0-9]{2}-[0-9]{2} )?([0-9]{4}-[0-9]{2}-[0-9]{2} )?(.*)");*/
/*std::regex regex("(^x )?(\\([A-Z]\\) )?([0-9]{4}-[0-9]{2}-[0-9]{2} )?([0-9]{4}-[0-9]{2}-[0-9]{2}
* )?(.*)");*/
/*std::regex_match(line, matches, regex);*/
/*for (size_t i = 0; i < matches.size(); ++i) {*/
@ -81,8 +82,6 @@
/*const std::string date = taskState == DONE ? firstDate : "";*/
/*return {*/
/*.text = text,*/
/*.state = taskState,*/

View file

@ -11,7 +11,8 @@
#include <string>
#include <vector>
namespace mirai {
namespace mirai
{
using Tags = std::vector<std::string>;
}

View file

@ -6,9 +6,11 @@
#include "utils.h"
namespace mirai {
bool isDate(const std::string& dateStr) {
namespace mirai
{
bool isDate(const std::string &dateStr)
{
std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");
return std::regex_match(dateStr, regex);
}
}
} // namespace mirai

View file

@ -9,17 +9,17 @@
#include <algorithm>
#include <cctype>
#include <locale>
#include <regex>
#include <cpp-utils/string.h>
#include <cpp-utils/vector.h>
#include <locale>
#include <regex>
namespace mirai {
namespace mirai
{
namespace stringUtils = cpputils::string;
namespace vectorUtils = cpputils::vector;
bool isDate(const std::string &dateStr);
}
} // namespace mirai
#endif

View file

@ -4,9 +4,9 @@
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include <QtGui/QGuiApplication>
#include <QtGui/QFont>
#include <QtCore/QRect>
#include <QtGui/QFont>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <QtQml/QQmlApplicationEngine>
#include <exception>
@ -26,16 +26,17 @@ int main(int argc, char *argv[])
qreal width = qMin(rect.width(), rect.height());
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
// auto m_ratio = qMin(height/refHeight, width/refWidth);
auto m_ratioFont = qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth));
auto m_ratioFont =
qMin(height * refDpi / (dpi * refHeight), width * refDpi / (dpi * refWidth));
QFont font("Helvetica", m_ratioFont);
app.setFont(font);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/qt/qml/Mirai/src/qml/Main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
[]() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
engine.load(url);
return app.exec();