From cee60c1a250f3fbda0fdf01e25e6e84048cf0e5a Mon Sep 17 00:00:00 2001 From: birkeh Date: Tue, 8 Oct 2019 23:22:18 +0200 Subject: [PATCH] initial commit --- cmonthlyitemdelegate.cpp | 9 +++++++++ cmonthlyitemdelegate.h | 2 ++ cmonthlyview.cpp | 20 ++++++++++++++++++++ cmonthlyview.h | 7 ++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmonthlyitemdelegate.cpp b/cmonthlyitemdelegate.cpp index 450096c..6bf9441 100644 --- a/cmonthlyitemdelegate.cpp +++ b/cmonthlyitemdelegate.cpp @@ -97,16 +97,25 @@ void cMonthlyItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *m model->setData(index, "", Qt::EditRole); else model->setData(index, lpTimeEdit->time().toString(), Qt::EditRole); + + emit timeChanged(index.row()+1, index.column(), lpTimeEdit->time()); + break; } case COL_CODE: { QComboBox* lpComboBox = qobject_cast(editor); model->setData(index, m_code.key(lpComboBox->currentText()), Qt::EditRole); + + emit textChanged(index.row()+1, index.column(), lpComboBox->currentText()); + break; } case COL_INFORMATION: QStyledItemDelegate::setModelData(editor, model, index); + + emit textChanged(index.row()+1, index.column(), model->data(index, Qt::EditRole).toString()); + break; default: break; diff --git a/cmonthlyitemdelegate.h b/cmonthlyitemdelegate.h index 145e98a..b5eb7d0 100644 --- a/cmonthlyitemdelegate.h +++ b/cmonthlyitemdelegate.h @@ -22,6 +22,8 @@ public: virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; signals: + void timeChanged(const int day, const int field, const QTime& time) const; + void textChanged(const int day, const int field, const QString& text) const; private: QMap m_code; diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp index bfc6748..7b487cd 100644 --- a/cmonthlyview.cpp +++ b/cmonthlyview.cpp @@ -3,6 +3,8 @@ #include "common.h" +#include + cMonthlyView::cMonthlyView(const QDate& date, QWidget *parent) : QWidget(parent), @@ -18,9 +20,13 @@ cMonthlyView::cMonthlyView(const QDate& date, QWidget *parent) : m_lpMonthlyListModel = new QStandardItemModel(0, 1); ui->m_lpMonthlyList->setModel(m_lpMonthlyListModel); + ui->m_lpMonthlyList->setItemDelegate(new cMonthlyItemDelegate(m_code)); setDate(date); + + connect(static_cast(ui->m_lpMonthlyList->itemDelegate()), &cMonthlyItemDelegate::timeChanged, this, &cMonthlyView::onTimeChanged); + connect(static_cast(ui->m_lpMonthlyList->itemDelegate()), &cMonthlyItemDelegate::textChanged, this, &cMonthlyView::onTextChanged); } void cMonthlyView::setDate(const QDate& date) @@ -116,3 +122,17 @@ cMonthlyView::~cMonthlyView() { delete ui; } + +void cMonthlyView::onTimeChanged(const int day, const int field, const QTime& time) +{ + qDebug() << "Day: " << day; + qDebug() << "field: " << field; + qDebug() << "time: " << time; +} + +void cMonthlyView::onTextChanged(const int day, const int field, const QString& text) +{ + qDebug() << "Day: " << day; + qDebug() << "field: " << field; + qDebug() << "time: " << text; +} diff --git a/cmonthlyview.h b/cmonthlyview.h index f008baa..e66b004 100644 --- a/cmonthlyview.h +++ b/cmonthlyview.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace Ui { @@ -21,11 +22,15 @@ public: explicit cMonthlyView(const QDate& date, QWidget *parent = nullptr); ~cMonthlyView(); - void setDate(const QDate& date); + void setDate(const QDate& date); private: Ui::cMonthlyView* ui; QStandardItemModel* m_lpMonthlyListModel; QMap m_code; + +private slots: + void onTimeChanged(const int day, const int field, const QTime& time); + void onTextChanged(const int day, const int field, const QString& text); }; #endif // CMONTHLYVIEW_H