diff --git a/source/MetaDataModel.cpp b/source/MetaDataModel.cpp
index ea04dfb..026d37c 100644
--- a/source/MetaDataModel.cpp
+++ b/source/MetaDataModel.cpp
@@ -40,12 +40,71 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+Qt::ItemFlags MetaDataModel::flags(const QModelIndex &index) const
+{
+ return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
+}
+
+bool MetaDataModel::setData(
+ const QModelIndex &index, const QVariant &value, int role)
+{
+ if (role != Qt::EditRole)
+ {
+ return QAbstractTableModel::setData(index, value, role);
+ }
+
+ bool valueChanged = false;
+
+ switch (index.column())
+ {
+ case 0:
+ if (value.toString() != m_participant)
+ {
+ m_participant = value.toString();
+ valueChanged = true;
+ }
+ break;
+ case 1:
+ if (value.toString() != m_instructor)
+ {
+ m_instructor = value.toString();
+ valueChanged = true;
+ }
+ break;
+ case 2:
+ if (value.toDate() != m_dateOfTest)
+ {
+ m_dateOfTest = value.toDate();
+ valueChanged = true;
+ }
+ break;
+ case 3:
+ if (value.toDate() != m_dateOfBirth)
+ {
+ m_dateOfBirth = value.toDate();
+ valueChanged = true;
+ }
+ break;
+ case 4:
+ if (value.toString() != m_remarks)
+ {
+ m_remarks = value.toString();
+ valueChanged = true;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return valueChanged;
+}
+
void MetaDataModel::write(QJsonObject &json) const
{
json["participant name"] = m_participant;
json["instructor name"] = m_instructor;
- json["date of birth"] = m_dateOfBirth.toString(Qt::TextDate);
- json["date of test"] = m_dateOfTest.toString(Qt::TextDate);
+ json["date of birth"] = m_dateOfBirth.toString(Qt::ISODate);
+ json["date of test"] = m_dateOfTest.toString(Qt::ISODate);
json["remarks"] = m_remarks;
}
@@ -66,13 +125,13 @@ void MetaDataModel::read(const QJsonObject &json)
const auto &dateOfBirth = json["date of birth"];
if (dateOfBirth.isString())
{
- m_dateOfBirth.fromString(dateOfBirth.toString());
+ m_dateOfBirth = QDate::fromString(dateOfBirth.toString(), Qt::ISODate);
}
const auto &dateOfTest = json["date of test"];
if (dateOfTest.isString())
{
- m_dateOfTest.fromString(dateOfTest.toString());
+ m_dateOfTest = QDate::fromString(dateOfTest.toString(), Qt::ISODate);
}
const auto &remarks = json["remarks"];
diff --git a/source/MetaDataModel.h b/source/MetaDataModel.h
index db179ae..94de6a3 100644
--- a/source/MetaDataModel.h
+++ b/source/MetaDataModel.h
@@ -22,6 +22,9 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(
const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override;
void write(QJsonObject &json) const;
void read(const QJsonObject &json);
diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp
index 055f656..3109e17 100644
--- a/source/mainwindow.cpp
+++ b/source/mainwindow.cpp
@@ -28,10 +28,8 @@ MainWindow::MainWindow(QWidget *parent)
m_widgetMapper->addMapping(ui->lineEdit_2, 1);
m_widgetMapper->addMapping(ui->dateEdit, 2);
m_widgetMapper->addMapping(ui->dateEdit_2, 3);
- m_widgetMapper->addMapping(ui->textEdit, 4);
+ m_widgetMapper->addMapping(ui->plainTextEdit, 4);
m_widgetMapper->toFirst();
-
- connect(ui->calendarWidget, SIGNAL(selectionChanged()), m_widgetMapper, SLOT(submit()));
}
MainWindow::~MainWindow()
diff --git a/source/mainwindow.ui b/source/mainwindow.ui
index 4165469..21c2d5a 100644
--- a/source/mainwindow.ui
+++ b/source/mainwindow.ui
@@ -42,45 +42,6 @@
- -
-
-
-
- 2018
- 9
- 10
-
-
-
- Qt::Monday
-
-
- QCalendarWidget::ShortDayNames
-
-
- QCalendarWidget::NoVerticalHeader
-
-
-
- -
-
-
- Qt::Monday
-
-
- false
-
-
- QCalendarWidget::NoVerticalHeader
-
-
- true
-
-
- true
-
-
-
-
@@ -91,10 +52,10 @@
- -
+
-
- -
+
-
@@ -108,7 +69,7 @@
-
-
+