Compare commits
7 Commits
854469166a
...
main
Author | SHA1 | Date | |
---|---|---|---|
2b662e58ab | |||
1793f5b949 | |||
d479a5e242 | |||
09b1e17de0 | |||
a458d82577 | |||
6d9586ac6e | |||
f9c394e0d1 |
33
src/Project-Orion/Button.qml
Normal file
33
src/Project-Orion/Button.qml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: button
|
||||||
|
property string text: "<placeholder>"
|
||||||
|
|
||||||
|
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
|
||||||
|
|
||||||
|
width: parent.width * 0.25
|
||||||
|
height: parent.height * 0.1
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
color: clickablearea.pressed ? "dimgrey" : "gray"
|
||||||
|
radius: 2
|
||||||
|
|
||||||
|
Text
|
||||||
|
{
|
||||||
|
color: myPalette.buttonText
|
||||||
|
text: button.text
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
width: parent.width
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea
|
||||||
|
{
|
||||||
|
id: clickablearea
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: { console.error("Hehehe") }
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,11 @@ qt_add_qml_module(appProject-Orion
|
|||||||
VERSION 1.0
|
VERSION 1.0
|
||||||
QML_FILES
|
QML_FILES
|
||||||
Main.qml
|
Main.qml
|
||||||
|
SOURCES user.h user.cpp
|
||||||
|
SOURCES userlist.h userlist.cpp
|
||||||
|
SOURCES serialization.h
|
||||||
|
SOURCES serialization.cpp
|
||||||
|
QML_FILES Button.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
|
@ -4,22 +4,16 @@ Window {
|
|||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
visible: true
|
visible: true
|
||||||
title: qsTr("Lifespan viewer")
|
title: "Lifespan viewer"
|
||||||
minimumWidth: 200
|
minimumWidth: 200
|
||||||
minimumHeight: 150
|
minimumHeight: 150
|
||||||
|
|
||||||
Rectangle {
|
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
|
|
||||||
Text {
|
|
||||||
id: emptyText
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
text: qsTr("This view is currently empty :(")
|
|
||||||
height: parent.height
|
|
||||||
}
|
|
||||||
|
|
||||||
|
color: myPalette.window
|
||||||
|
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
text: "For testing purposes"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
61
src/Project-Orion/serialization.cpp
Normal file
61
src/Project-Orion/serialization.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "serialization.h"
|
||||||
|
#include <filesystem>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
UserList loadUserList(const QString &file)
|
||||||
|
{
|
||||||
|
QFile doc{std::filesystem::path{file.toStdString()}};
|
||||||
|
doc.open(QFile::ReadOnly);
|
||||||
|
|
||||||
|
QString fileContents = doc.readAll();
|
||||||
|
|
||||||
|
QJsonParseError errors;
|
||||||
|
QJsonDocument document =
|
||||||
|
QJsonDocument::fromJson(fileContents.toUtf8(),
|
||||||
|
&errors);
|
||||||
|
|
||||||
|
if (document.isNull())
|
||||||
|
{
|
||||||
|
qDebug() << errors.errorString();
|
||||||
|
throw std::runtime_error{"Could not parse JSON file"};
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray array = document.array();
|
||||||
|
QVector<User> container;
|
||||||
|
|
||||||
|
for (QJsonArray::const_iterator elem = array.constBegin(); elem != array.constEnd(); ++elem)
|
||||||
|
{
|
||||||
|
auto obj = elem->toObject();
|
||||||
|
User newUser{obj[NAME_LABEL].toString(), QDate::fromString(obj[DATE_OF_BIRTH_LABEL].toString()),
|
||||||
|
QDate::fromString(obj[DATE_OF_DEATH_LABEL].toString()), obj[DEFAULT_LABEL].toBool()};
|
||||||
|
|
||||||
|
container.append(newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveUserList(const UserList &list, const QString &file)
|
||||||
|
{
|
||||||
|
QFile doc{std::filesystem::path{file.toStdString()}};
|
||||||
|
doc.open(QFile::WriteOnly);
|
||||||
|
|
||||||
|
QJsonArray container;
|
||||||
|
|
||||||
|
for(auto &obj: list)
|
||||||
|
{
|
||||||
|
QJsonObject newObject;
|
||||||
|
newObject[NAME_LABEL] = obj.getName();
|
||||||
|
newObject[DATE_OF_BIRTH_LABEL] = obj.getDateOfBirth().toString();
|
||||||
|
newObject[DATE_OF_DEATH_LABEL] = obj.getDateOfDeath().toString();
|
||||||
|
newObject[DEFAULT_LABEL] = obj.getIsItDefault();
|
||||||
|
|
||||||
|
container.append(newObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument document{container};
|
||||||
|
doc.write(document.toJson());
|
||||||
|
}
|
14
src/Project-Orion/serialization.h
Normal file
14
src/Project-Orion/serialization.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef SERIALIZATION_H
|
||||||
|
#define SERIALIZATION_H
|
||||||
|
|
||||||
|
#define NAME_LABEL "name"
|
||||||
|
#define DATE_OF_BIRTH_LABEL "date_of_birth"
|
||||||
|
#define DATE_OF_DEATH_LABEL "date_of_death"
|
||||||
|
#define DEFAULT_LABEL "default"
|
||||||
|
|
||||||
|
#include "userlist.h"
|
||||||
|
|
||||||
|
UserList loadUserList(const QString &file);
|
||||||
|
void saveUserList(const UserList &list, const QString &file);
|
||||||
|
|
||||||
|
#endif // SERIALIZATION_H
|
45
src/Project-Orion/user.cpp
Normal file
45
src/Project-Orion/user.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "user.h"
|
||||||
|
|
||||||
|
User::User(QString name, QDate dateOfBirth, QDate dateOfDeath, bool isItDefault)
|
||||||
|
: name{name}, dateOfBirth{dateOfBirth}, dateOfDeath{dateOfDeath}, isItDefault{isItDefault}
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString User::getName() const
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setName(const QString &newName)
|
||||||
|
{
|
||||||
|
name = newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate User::getDateOfBirth() const
|
||||||
|
{
|
||||||
|
return dateOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setDateOfBirth(const QDate &newDateOfBirth)
|
||||||
|
{
|
||||||
|
dateOfBirth = newDateOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate User::getDateOfDeath() const
|
||||||
|
{
|
||||||
|
return dateOfDeath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setDateOfDeath(const QDate &newDateOfDeath)
|
||||||
|
{
|
||||||
|
dateOfDeath = newDateOfDeath;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::getIsItDefault() const
|
||||||
|
{
|
||||||
|
return isItDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setIsItDefault(bool newIsItDefault)
|
||||||
|
{
|
||||||
|
isItDefault = newIsItDefault;
|
||||||
|
}
|
29
src/Project-Orion/user.h
Normal file
29
src/Project-Orion/user.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef USER_H
|
||||||
|
#define USER_H
|
||||||
|
|
||||||
|
#include <qdatetime.h>
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
User(QString name, QDate dateOfBirth, QDate dateOfDeath, bool isItDefault = false);
|
||||||
|
|
||||||
|
QString getName() const;
|
||||||
|
void setName(const QString &newName);
|
||||||
|
|
||||||
|
QDate getDateOfBirth() const;
|
||||||
|
void setDateOfBirth(const QDate &newDateOfBirth);
|
||||||
|
|
||||||
|
QDate getDateOfDeath() const;
|
||||||
|
void setDateOfDeath(const QDate &newDateOfDeath);
|
||||||
|
|
||||||
|
bool getIsItDefault() const;
|
||||||
|
void setIsItDefault(bool newIsItDefault);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString name;
|
||||||
|
QDate dateOfBirth;
|
||||||
|
QDate dateOfDeath;
|
||||||
|
bool isItDefault = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USER_H
|
15
src/Project-Orion/userlist.cpp
Normal file
15
src/Project-Orion/userlist.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "userlist.h"
|
||||||
|
|
||||||
|
UserList::UserList(const QVector<User> &list):
|
||||||
|
list{list}
|
||||||
|
{}
|
||||||
|
|
||||||
|
QVector<User> UserList::getList() const
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserList::setList(const QVector<User> &newList)
|
||||||
|
{
|
||||||
|
list = newList;
|
||||||
|
}
|
82
src/Project-Orion/userlist.h
Normal file
82
src/Project-Orion/userlist.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#ifndef USERLIST_H
|
||||||
|
#define USERLIST_H
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class UserList : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UserList(const QVector<User> &list);
|
||||||
|
|
||||||
|
QVector<User> getList() const;
|
||||||
|
void setList(const QVector<User> &newList);
|
||||||
|
|
||||||
|
struct iteratable
|
||||||
|
{
|
||||||
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using value_type = User;
|
||||||
|
using pointer = User *; // or also value_type*
|
||||||
|
using reference = User&; // or also value_type&
|
||||||
|
|
||||||
|
iteratable(User *begin)
|
||||||
|
: ptr{begin}
|
||||||
|
{}
|
||||||
|
|
||||||
|
reference operator*() const { return *ptr; }
|
||||||
|
pointer operator->() { return ptr; }
|
||||||
|
|
||||||
|
// Prefix increment
|
||||||
|
iteratable& operator++() { ptr++; return *this; }
|
||||||
|
|
||||||
|
// Postfix increment
|
||||||
|
iteratable operator++(int) { iteratable tmp = *this; ++(*this); return tmp; }
|
||||||
|
|
||||||
|
friend bool operator== (const iteratable& a, const iteratable& b) { return a.ptr == b.ptr; };
|
||||||
|
friend bool operator!= (const iteratable& a, const iteratable& b) { return a.ptr != b.ptr; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
User* ptr;
|
||||||
|
};
|
||||||
|
struct const_interatable
|
||||||
|
{
|
||||||
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using value_type = const User;
|
||||||
|
using pointer = const User *; // or also value_type*
|
||||||
|
using reference = const User&; // or also value_type&
|
||||||
|
|
||||||
|
const_interatable(const User *begin)
|
||||||
|
: ptr{begin}
|
||||||
|
{}
|
||||||
|
|
||||||
|
reference operator*() const { return *ptr; }
|
||||||
|
pointer operator->() { return ptr; }
|
||||||
|
|
||||||
|
// Prefix increment
|
||||||
|
const_interatable& operator++() { ptr++; return *this; }
|
||||||
|
|
||||||
|
// Postfix increment
|
||||||
|
const_interatable operator++(int) { const_interatable tmp = *this; ++(*this); return tmp; }
|
||||||
|
|
||||||
|
friend bool operator== (const const_interatable& a, const const_interatable& b) { return a.ptr == b.ptr; };
|
||||||
|
friend bool operator!= (const const_interatable& a, const const_interatable& b) { return a.ptr != b.ptr; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
const User* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
iteratable begin() { return &*list.begin(); }
|
||||||
|
iteratable end() { return &*list.end(); }
|
||||||
|
|
||||||
|
const_interatable begin() const { return &*list.begin(); }
|
||||||
|
const_interatable end() const { return &*list.end(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector<User> list;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USERLIST_H
|
Reference in New Issue
Block a user