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

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -8,37 +8,41 @@
#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;
};
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;
};
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) {
for (auto& elem : vec) {
if (!contains(vec2, elem)) {
return false;
}
}
return true;
}
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)
{
for (auto &elem : vec) {
if (!contains(vec2, elem)) {
return false;
}
}
return true;
}
} // namespace cpputils::vector
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -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");
@ -16,7 +18,7 @@ Backend::Backend() {
qWarning() << "Couldn't find existing config file";
exit(1);
}
QByteArray loadData = loadFile.readAll();
QJsonDocument json = QJsonDocument::fromJson(loadData);
loadFile.close();
@ -25,7 +27,7 @@ Backend::Backend() {
exit(1);
}
QJsonObject jsonRootObject = json.object();
auto jsonFilesPath = json["files"];
if (!jsonFilesPath.isArray()) {
qWarning() << "config.json should contains a 'files' string array";
@ -37,48 +39,56 @@ 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) {
QMLTaskItem& taskItem = QMLTasks[todoIndex];
*(taskItem.taskItem) = mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date)
{
QMLTaskItem &taskItem = QMLTasks[todoIndex];
*(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) {
QMLTaskItem& taskItem = QMLTasks[todoIndex];
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") {
taskItem.taskItem->markAsDone();
@ -92,21 +102,24 @@ void Backend::updateTodo(int todoIndex, QString state, QString text, QString dat
emit tasksChanged();
}
void Backend::removeTodo(int todoIndex) {
QMLTaskItem& taskItem = QMLTasks[todoIndex];
void Backend::removeTodo(int todoIndex)
{
QMLTaskItem &taskItem = QMLTasks[todoIndex];
mirai.removeTask(taskItem.taskItem);
mirai.save();
rebuildQMLTasksList();
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);
@ -114,8 +127,9 @@ void Backend::rebuildQMLTasksList() {
std::stringstream currentDate;
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()) {
mirai::TaskItem &task = (*view.lock())[i];
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() &&
task.getDate() < currentDate.str()) {
continue;
}
bool shouldShowDate = false;
@ -124,40 +138,40 @@ void Backend::rebuildQMLTasksList() {
shouldShowDate = true;
}
QList<QString> qStringTags;
for (auto& tag : task.getTags()) {
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()) {
for (auto &tag : mirai.getTags()) {
QMLTags.push_back(QString::fromStdString(tag));
}
QMLActiveTagsFilter.clear();
for (auto& activeTagFilter: view.lock()->getActiveTagsFilter()) {
for (auto &activeTagFilter : view.lock()->getActiveTagsFilter()) {
QMLActiveTagsFilter.push_back(QString::fromStdString(activeTagFilter));
}
}
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

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -10,35 +10,32 @@
#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"
class Backend : public QObject
{
Q_OBJECT
QML_ELEMENT
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)
public:
Q_OBJECT
QML_ELEMENT
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)
public:
Backend();
Q_INVOKABLE void addTodo(QString newTodo, QString date);
@ -51,8 +48,7 @@ public:
Q_INVOKABLE void removeTodo(int todoIndex);
Q_INVOKABLE void hideCompletedTasks(bool shouldHide);
private:
private:
void rebuildQMLTasksList();
QVariant getTasks();
@ -69,7 +65,7 @@ private:
bool shouldHideCompletedTasks_ = true;
signals:
signals:
void tasksChanged();
};

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -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

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -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"
@ -17,26 +17,25 @@
struct QMLTaskItem {
Q_GADGET
Q_PROPERTY(QString rawFormat READ getRawFormat)
Q_PROPERTY(QString text READ getText)
Q_PROPERTY(QString state READ getState)
Q_PROPERTY(QString date READ getDate)
Q_PROPERTY(QList<QString> tags READ getTags)
Q_PROPERTY(bool shouldShowDate READ getShouldShowDate)
Q_PROPERTY(QString time READ getTime)
Q_PROPERTY(QString rawFormat READ getRawFormat)
Q_PROPERTY(QString text READ getText)
Q_PROPERTY(QString state READ getState)
Q_PROPERTY(QString date READ getDate)
Q_PROPERTY(QList<QString> tags READ getTags)
Q_PROPERTY(bool shouldShowDate READ getShouldShowDate)
Q_PROPERTY(QString time READ getTime)
QML_VALUE_TYPE(taskItem)
public:
public:
QString getText();
QString getRawFormat();
QString getState();
QString getDate();
QString getTime();
QList<QString> getTags();
bool getShouldShowDate();
bool getShouldShowDate();
mirai::TaskItem* taskItem;
mirai::TaskItem *taskItem;
bool shouldShowDate = false;
QList<QString> tags;
};

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -8,59 +8,67 @@
#include "TaskItem.h"
#include "cpp-utils/vector.h"
namespace mirai {
namespace mirai
{
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)) {
tags.push_back(tag);
}
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)) {
tags.push_back(tag);
}
}
}
}
void Mirai::save() {
for (auto& file : *files) {
TodoMdFormat::writeFile(file);
}
}
void Mirai::addTask(TaskItem taskItem) {
(*files)[0].addTask(taskItem);
for (auto& view : views) {
view->update();
}
}
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;*/
/*ssCreationDate << std::put_time(&tm, "%Y-%m-%d");*/
(*files)[0].addTask(text, date);
for (auto& view : views) {
view->update();
}
}
void Mirai::removeTask(const TaskItem* taskItem) {
(*files)[0].removeTask(taskItem);
for (auto& view : views) {
view->update();
}
}
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() {
return tags;
void Mirai::save()
{
for (auto &file : *files) {
TodoMdFormat::writeFile(file);
}
}
void Mirai::addTask(TaskItem taskItem)
{
(*files)[0].addTask(taskItem);
for (auto &view : views) {
view->update();
}
}
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;*/
/*ssCreationDate << std::put_time(&tm, "%Y-%m-%d");*/
(*files)[0].addTask(text, date);
for (auto &view : views) {
view->update();
}
}
void Mirai::removeTask(const TaskItem *taskItem)
{
(*files)[0].removeTask(taskItem);
for (auto &view : views) {
view->update();
}
}
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()
{
return tags;
}
} // namespace mirai

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -14,33 +14,33 @@
#include <algorithm>
#include <memory>
namespace mirai {
namespace mirai
{
class Mirai {
class Mirai
{
public:
public:
void loadFile(const std::string &path);
void save();
void addTask(TaskItem taskItem);
void addTask(std::string text, std::string date);
void removeTask(const TaskItem *taskItem);
void loadFile(const std::string& path);
void save();
void addTask(TaskItem taskItem);
void addTask(std::string text, std::string date);
void removeTask(const TaskItem* taskItem);
std::weak_ptr<TasksView> getTasks();
const std::vector<std::string> &getTags();
std::weak_ptr<TasksView> getTasks();
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.
std::shared_ptr<std::vector<TasksFile>> files = std::make_shared<std::vector<TasksFile>>();
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.
std::shared_ptr<std::vector<TasksFile>> files = std::make_shared<std::vector<TasksFile>>();
// We keep a vector of shared_ptr because we need the ref counting mechanism to know
// if we have to remove the view (not used) or tell the view to update() on
// some changes.
std::vector<std::shared_ptr<TasksView>> views;
std::vector<std::string> tags;
};
}
// We keep a vector of shared_ptr because we need the ref counting mechanism to know
// if we have to remove the view (not used) or tell the view to update() on
// some changes.
std::vector<std::shared_ptr<TasksView>> views;
std::vector<std::string> tags;
};
} // namespace mirai
#endif

View file

@ -1,41 +1,72 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* 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() {
state = DONE;
}
void TaskItem::markAsUndone() {
state = TODO;
}
void TaskItem::setDate(const std::string& date) {
this->date = date;
}
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); }
bool TaskItem::hasTag(const std::string& tag) const {
return vectorUtils::contains(tags, tag);
}
void TaskItem::markAsDone()
{
state = DONE;
}
void TaskItem::markAsUndone()
{
state = TODO;
}
void TaskItem::setDate(const std::string &date)
{
this->date = date;
}
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);
}
bool TaskItem::hasTag(const std::string &tag) const
{
return vectorUtils::contains(tags, tag);
}
} // namespace mirai

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -20,39 +20,36 @@
#include <string>
#include <vector>
namespace mirai {
enum TaskItemState {
TODO,
DONE
};
namespace mirai
{
enum TaskItemState { TODO, DONE };
struct TaskItem {
public:
struct TaskItem {
public:
void markAsDone();
void markAsDone();
void markAsUndone();
void setDate(const std::string &date);
void markAsUndone();
void setDate(const std::string& date);
void setText(const std::string &text);
void setText(const std::string& text);
const std::string &getLine() const;
const std::string &getText() const;
const TaskItemState &getState() const;
const std::string &getDate() const;
const std::string &getStartTime() const;
const std::string &getEndTime() const;
const Tags &getTags() const;
bool hasTag(const std::string &tag) const;
bool hasDate() const;
const std::string& getLine() const;
const std::string& getText() const;
const TaskItemState& getState() const;
const std::string& getDate() const;
const std::string& getStartTime() const;
const std::string& getEndTime() const;
const Tags& getTags() const;
bool hasTag(const std::string& tag) const;
bool hasDate() const;
std::string text;
TaskItemState state;
std::string date;
std::string startTime;
std::string endTime;
Tags tags;
};
}
std::string text;
TaskItemState state;
std::string date;
std::string startTime;
std::string endTime;
Tags tags;
};
} // namespace mirai
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -8,48 +8,64 @@
#include "TaskItem.h"
#include <memory>
namespace mirai {
namespace mirai
{
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; }
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
});
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){
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) {
if (t1->hasDate() && !t2->hasDate()) {
return true;
} else if (!t1->hasDate() && t2->hasDate()) {
return false;
}
return t1->date < t2->date;
});
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;
}
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});
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) {
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) {
if (t1->hasDate() && !t2->hasDate()) {
return true;
} else if (!t1->hasDate() && t2->hasDate()) {
return false;
}
return t1->date < t2->date;
});
}
} // namespace mirai

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -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,41 +22,38 @@
#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>>;
using TasksPtrs = std::vector<std::unique_ptr<TaskItem>>;
struct TasksFileConstructor {
const std::string &name;
const std::string &path;
std::vector<TaskItem> tasks;
};
struct TasksFileConstructor {
const std::string& name;
const std::string& path;
std::vector<TaskItem> tasks;
};
class TasksFile
{
class TasksFile {
public:
TasksFile(TasksFileConstructor params);
public:
void addTask(std::string text, std::string date);
void addTask(TaskItem TaskItem);
void removeTask(const TaskItem *taskToRemove);
void sortByDate();
TasksFile(TasksFileConstructor params);
const std::string &getName() const;
const std::string &getPath() const;
TasksPtrs &getTasks();
void addTask(std::string text, std::string date);
void addTask(TaskItem TaskItem);
void removeTask(const TaskItem* taskToRemove);
void sortByDate();
const std::string& getName() const;
const std::string& getPath() const;
TasksPtrs& getTasks();
private:
std::string name;
std::string path;
TasksPtrs tasks;
};
}
private:
std::string name;
std::string path;
TasksPtrs tasks;
};
} // namespace mirai
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -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)
{
update();
}
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files) {
update();
}
TaskItem &TasksView::operator[](int index)
{
return *(tasksToShow.at(index));
}
TaskItem& TasksView::operator[](int index) {
return *(tasksToShow.at(index));
}
size_t TasksView::count() const
{
return tasksToShow.size();
}
int TasksView::count() const { return tasksToShow.size(); }
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()))
continue;
tasksToShow.push_back(task.get());
void TasksView::update()
{
tasksToShow.clear();
for (auto &file : *files) {
for (auto &task : file.getTasks()) {
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) {
continue;
}
tasksToShow.push_back(task.get());
}
}
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;
}));
update();
}
void TasksView::removeFilters() {
tagsFilter.clear();
update();
}
const std::vector<std::string>& TasksView::getActiveTagsFilter() {
return tagsFilter;
}
}
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; }));
update();
}
void TasksView::removeFilters()
{
tagsFilter.clear();
update();
}
const std::vector<std::string> &TasksView::getActiveTagsFilter()
{
return tagsFilter;
}
} // namespace mirai

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -8,34 +8,32 @@
#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:
public:
TasksView(std::shared_ptr<std::vector<TasksFile>> files);
TasksView(std::shared_ptr<std::vector<TasksFile>> files);
TaskItem &operator[](int index);
TaskItem& operator[](int index);
size_t count() const;
void update();
void addTagFilter(const std::string &tag);
void removeTagFilter(const std::string &tag);
void removeFilters();
const Tags &getActiveTagsFilter();
int count() const;
void update();
void addTagFilter(const std::string& tag);
void removeTagFilter(const std::string& tag);
void removeFilters();
const Tags& getActiveTagsFilter();
private:
std::shared_ptr<std::vector<TasksFile>> files;
std::vector<TaskItem*> tasksToShow;
Tags tagsFilter;
};
}
private:
std::shared_ptr<std::vector<TasksFile>> files;
std::vector<TaskItem *> tasksToShow;
Tags tagsFilter;
};
} // namespace mirai
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -8,122 +8,122 @@
#include "TaskItem.h"
#include "cpp-utils/vector.h"
namespace mirai {
namespace mirai
{
TasksFile TodoMdFormat::readFile(const std::string& path) {
std::ifstream file(path);
if (!file.is_open()) {
throw std::runtime_error("todo.txt file not found");
}
std::vector<TaskItem> taskItems;
std::string line;
TasksFile TodoMdFormat::readFile(const std::string &path)
{
std::ifstream file(path);
if (!file.is_open()) {
throw std::runtime_error("todo.txt file not found");
}
std::vector<TaskItem> taskItems;
std::string line;
if (!std::getline(file, line) || line.substr(0, 2) != "# ") {
std::cerr << "Couldn't find the task list name" << std::endl;
}
std::string name = line.substr(2);
std::string currentDate = "";
while (std::getline(file, line)) {
if (line.substr(0, 3) == "## ") {
currentDate = line.substr(3);
} else if (line.substr(0, 5) == "- [ ]" || line.substr(0, 5) == "- [X]") {
TaskItem taskItem = StringToTask(line, currentDate);
taskItem.setDate(currentDate);
taskItems.push_back(taskItem);
}
}
file.close();
TasksFile tasks({
.name = name,
.path = path,
.tasks = taskItems
});
return tasks;
if (!std::getline(file, line) || line.substr(0, 2) != "# ") {
std::cerr << "Couldn't find the task list name" << std::endl;
}
Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) {
Tags tags;
std::string name = line.substr(2);
std::string currentDate = "";
std::regex regex("(#[a-zA-Z0-1]+)");
std::smatch matches;
while (std::regex_search(metadata, matches, regex))
{
if (!vectorUtils::contains(tags, matches[0].str())) {
tags.push_back(matches[0]);
}
metadata = matches.suffix();
while (std::getline(file, line)) {
if (line.substr(0, 3) == "## ") {
currentDate = line.substr(3);
} else if (line.substr(0, 5) == "- [ ]" || line.substr(0, 5) == "- [X]") {
TaskItem taskItem = StringToTask(line, currentDate);
taskItem.setDate(currentDate);
taskItems.push_back(taskItem);
}
return tags;
}
void TodoMdFormat::writeFile(TasksFile& tasks) {
std::ofstream file(tasks.getPath());
if (!file.is_open()) {
throw std::runtime_error("can't create todo.txt");
}
std::string currentDate = "";
file << "# " << tasks.getName() << "\n";
for (const auto& task : tasks.getTasks()) {
if (currentDate != task->date) {
currentDate = task->date;
file << "\n## " << (task->date != "" ? task->date : "No date") << "\n\n";
}
file << TaskToString(*task) << '\n';
}
file.close();
}
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) {
std::smatch matches;
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;*/
/*std::cout << "M 0 " << matches[0] << std::endl;*/
/*std::cout << "M 1 " << matches[1] << std::endl;*/
/*std::cout << "M 2 " << matches[2] << std::endl;*/
/*std::cout << "M 3 " << matches[3] << std::endl;*/
/*std::cout << "M 4 " << matches[4] << std::endl;*/
/*std::cout << "M 5 " << matches[5] << std::endl;*/
/*std::cout << "M 6 " << matches[6] << std::endl;*/
/*std::cout << "M 7 " << matches[7] << std::endl;*/
std::string text = stringUtils::trim(matches[5]);
TaskItem taskItem = {
.text = text,
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
.date = date,
.startTime = matches[3],
.endTime = matches[4],
.tags = extractTagsFromMetadata(matches[7])
};
return taskItem;
}
std::string TodoMdFormat::TaskToString(const TaskItem& task) {
std::string str = task.getText();
if (task.getTags().size() > 0) {
str += " --";
for (const std::string& tag : task.getTags()) {
str += " " + tag;
}
}
if (task.getStartTime() != "" && task.getEndTime() != "") {
str = task.getStartTime() + "-" + task.getEndTime() + " > " + str;
}
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
return str;
}
file.close();
TasksFile tasks({.name = name, .path = path, .tasks = taskItems});
return tasks;
}
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)) {
if (!vectorUtils::contains(tags, matches[0].str())) {
tags.push_back(matches[0]);
}
metadata = matches.suffix();
}
return tags;
}
void TodoMdFormat::writeFile(TasksFile &tasks)
{
std::ofstream file(tasks.getPath());
if (!file.is_open()) {
throw std::runtime_error("can't create todo.txt");
}
std::string currentDate = "";
file << "# " << tasks.getName() << "\n";
for (const auto &task : tasks.getTasks()) {
if (currentDate != task->date) {
currentDate = task->date;
file << "\n## " << (task->date != "" ? task->date : "No date") << "\n\n";
}
file << TaskToString(*task) << '\n';
}
file.close();
}
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)
{
std::smatch matches;
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;*/
/*std::cout << "M 0 " << matches[0] << std::endl;*/
/*std::cout << "M 1 " << matches[1] << std::endl;*/
/*std::cout << "M 2 " << matches[2] << std::endl;*/
/*std::cout << "M 3 " << matches[3] << std::endl;*/
/*std::cout << "M 4 " << matches[4] << std::endl;*/
/*std::cout << "M 5 " << matches[5] << std::endl;*/
/*std::cout << "M 6 " << matches[6] << std::endl;*/
/*std::cout << "M 7 " << matches[7] << std::endl;*/
std::string text = stringUtils::trim(matches[5]);
TaskItem taskItem = {.text = text,
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
.date = date,
.startTime = matches[3],
.endTime = matches[4],
.tags = extractTagsFromMetadata(matches[7])};
return taskItem;
}
std::string TodoMdFormat::TaskToString(const TaskItem &task)
{
std::string str = task.getText();
if (task.getTags().size() > 0) {
str += " --";
for (const std::string &tag : task.getTags()) {
str += " " + tag;
}
}
if (task.getStartTime() != "" && task.getEndTime() != "") {
str = task.getStartTime() + "-" + task.getEndTime() + " > " + str;
}
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
return str;
}
} // namespace mirai

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -20,23 +20,23 @@
#include <string>
#include <vector>
namespace mirai {
namespace mirai
{
class TodoMdFormat {
public:
class TodoMdFormat
{
public:
static TasksFile readFile(const std::string &path);
static void writeFile(TasksFile &tasks);
static TasksFile readFile(const std::string& path);
static void writeFile(TasksFile& tasks);
static std::string TaskToString(const TaskItem &task);
static TaskItem StringToTask(const std::string &str, const std::string &date);
static std::string TaskToString(const TaskItem& task);
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);
};
}
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

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -20,76 +20,75 @@
/*namespace mirai {*/
/*class TodoTxtFormat {*/
/*public:*/
/*class TodoTxtFormat {*/
/*public:*/
/*static TaskList readFile() {*/
/*std::ifstream file("../newqml/todo.txt");*/
/*if (!file.is_open()) {*/
/*throw std::runtime_error("todo.txt file not found");*/
/*}*/
/*std::vector<TaskItem> taskItems;*/
/*std::string line;*/
/*while (std::getline(file, line)) {*/
/*auto taskItem = parseLine(line);*/
/*taskItems.push_back(taskItem);*/
/*}*/
/*file.close();*/
/*TaskList tasks({*/
/*.tasks = taskItems*/
/*});*/
/*return tasks;*/
/*}*/
/*static TaskList readFile() {*/
/*std::ifstream file("../newqml/todo.txt");*/
/*if (!file.is_open()) {*/
/*throw std::runtime_error("todo.txt file not found");*/
/*}*/
/*std::vector<TaskItem> taskItems;*/
/*std::string line;*/
/*while (std::getline(file, line)) {*/
/*auto taskItem = parseLine(line);*/
/*taskItems.push_back(taskItem);*/
/*}*/
/*file.close();*/
/*TaskList tasks({*/
/*.tasks = taskItems*/
/*});*/
/*return tasks;*/
/*}*/
/*static void writeFile(TaskList& tasks) {*/
/*std::ofstream file("../newqml/todo.txt");*/
/*if (!file.is_open()) {*/
/*throw std::runtime_error("can't create todo.txt");*/
/*}*/
/*for (const auto& task : tasks.getTasks()) {*/
/*file << fieldWithSpace(task->state == DONE ? "x" : task->priority);*/
/*file << fieldWithSpace(task->state == DONE ? task->getDate() : "");*/
/*file << fieldWithSpace(task->getCreationDate());*/
/*file << task->getText() << '\n';*/
/*}*/
/*file.close();*/
/*}*/
/*static void writeFile(TaskList& tasks) {*/
/*std::ofstream file("../newqml/todo.txt");*/
/*if (!file.is_open()) {*/
/*throw std::runtime_error("can't create todo.txt");*/
/*}*/
/*for (const auto& task : tasks.getTasks()) {*/
/*file << fieldWithSpace(task->state == DONE ? "x" : task->priority);*/
/*file << fieldWithSpace(task->state == DONE ? task->getDate() : "");*/
/*file << fieldWithSpace(task->getCreationDate());*/
/*file << task->getText() << '\n';*/
/*}*/
/*file.close();*/
/*}*/
/*private:*/
/*private:*/
/*static std::string fieldWithSpace(const std::string& field) {*/
/*if (field.length() == 0)*/
/*return "";*/
/*return (field + " ");*/
/*}*/
/*static std::string fieldWithSpace(const std::string& field) {*/
/*if (field.length() == 0)*/
/*return "";*/
/*return (field + " ");*/
/*}*/
/*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_match(line, matches, regex);*/
/*for (size_t i = 0; i < matches.size(); ++i) {*/
/*std::ssub_match sub_match = matches[i];*/
/*std::string piece = sub_match.str();*/
/*}*/
/*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_match(line, matches, regex);*/
/*const TaskItemState taskState = trim_copy(matches[1].str()) == "x" ? DONE : TODO;*/
/*const std::string priority = trim_copy(matches[2].str());*/
/*const std::string firstDate = trim_copy(matches[3].str());*/
/*const std::string secondDate = trim_copy(matches[4].str());*/
/*const std::string text = trim_copy(matches[5].str());*/
/*for (size_t i = 0; i < matches.size(); ++i) {*/
/*std::ssub_match sub_match = matches[i];*/
/*std::string piece = sub_match.str();*/
/*}*/
/*const std::string date = taskState == DONE ? firstDate : "";*/
/*const TaskItemState taskState = trim_copy(matches[1].str()) == "x" ? DONE : TODO;*/
/*const std::string priority = trim_copy(matches[2].str());*/
/*const std::string firstDate = trim_copy(matches[3].str());*/
/*const std::string secondDate = trim_copy(matches[4].str());*/
/*const std::string text = trim_copy(matches[5].str());*/
/*return {*/
/*.text = text,*/
/*.state = taskState,*/
/*.date = date,*/
/*};*/
/*}*/
/*};*/
/*const std::string date = taskState == DONE ? firstDate : "";*/
/*return {*/
/*.text = text,*/
/*.state = taskState,*/
/*.date = date,*/
/*};*/
/*}*/
/*};*/
/*}*/
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -11,8 +11,9 @@
#include <string>
#include <vector>
namespace mirai {
using Tags = std::vector<std::string>;
namespace mirai
{
using Tags = std::vector<std::string>;
}
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -6,9 +6,11 @@
#include "utils.h"
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
{
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

@ -1,4 +1,4 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
@ -7,19 +7,19 @@
#ifndef MIRAI_UTILS_H
#define MIRAI_UTILS_H
#include <algorithm>
#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 stringUtils = cpputils::string;
namespace vectorUtils = cpputils::vector;
bool isDate(const std::string& dateStr);
}
namespace mirai
{
namespace stringUtils = cpputils::string;
namespace vectorUtils = cpputils::vector;
bool isDate(const std::string &dateStr);
} // namespace mirai
#endif

View file

@ -1,12 +1,12 @@
/*
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* 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>
@ -17,7 +17,7 @@ int main(int argc, char *argv[])
{
try {
QGuiApplication app(argc, argv);
qreal refDpi = 54.;
qreal refHeight = 1440.;
qreal refWidth = 2560.;
@ -25,21 +25,22 @@ int main(int argc, char *argv[])
qreal height = qMax(rect.width(), rect.height());
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_ratio = qMin(height/refHeight, width/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();
} catch (const std::exception& e) {
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
}
}