From f7593bd416a25d7690f801de23ccff23d07acdd2 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Tue, 8 Oct 2019 16:26:48 +0200 Subject: [PATCH] initial commit --- cmainwindow.cpp | 39 ++++++++++++- cmainwindow.h | 9 ++- cmainwindow.ui | 44 +++++++++++---- cmonthlyitemdelegate.cpp | 114 +++++++++++++++++++++++++++++++++++++ cmonthlyitemdelegate.h | 30 ++++++++++ cmonthlyview.cpp | 118 +++++++++++++++++++++++++++++++++++++++ cmonthlyview.h | 31 ++++++++++ cmonthlyview.ui | 50 +++++++++++++++++ common.h | 24 ++++++++ cpublicholiday.cpp | 7 +++ cpublicholiday.h | 11 ++++ main.cpp | 17 +++++- workingHours.pro | 12 +++- 13 files changed, 490 insertions(+), 16 deletions(-) create mode 100644 cmonthlyitemdelegate.cpp create mode 100644 cmonthlyitemdelegate.h create mode 100644 cmonthlyview.cpp create mode 100644 cmonthlyview.h create mode 100644 cmonthlyview.ui create mode 100644 common.h create mode 100644 cpublicholiday.cpp create mode 100644 cpublicholiday.h diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 9a9a230..8a00d3e 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1,15 +1,52 @@ #include "cmainwindow.h" #include "ui_cmainwindow.h" +#include + +#include + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::cMainWindow) + ui(new Ui::cMainWindow), + m_lpMonthlyView(nullptr) { ui->setupUi(this); + + QSettings settings; + qint32 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); + qint32 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt(); + qint32 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt(); + qint32 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + + m_lpMonthlyView = new cMonthlyView(QDate(2019, 10, 8), this); + ui->m_lpMainTab->addTab(m_lpMonthlyView, "Monthly"); } cMainWindow::~cMainWindow() { + if(m_lpMonthlyView) + delete m_lpMonthlyView; + delete ui; } + +void cMainWindow::closeEvent(QCloseEvent *event) +{ + QSettings settings; + settings.setValue("main/width", QVariant::fromValue(size().width())); + settings.setValue("main/height", QVariant::fromValue(size().height())); + settings.setValue("main/x", QVariant::fromValue(x())); + settings.setValue("main/y", QVariant::fromValue(y())); + if(this->isMaximized()) + settings.setValue("main/maximized", QVariant::fromValue(true)); + else + settings.setValue("main/maximized", QVariant::fromValue(false)); + + event->accept(); +} diff --git a/cmainwindow.h b/cmainwindow.h index 8968eb0..74c9625 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -2,7 +2,10 @@ #define CMAINWINDOW_H +#include "cmonthlyview.h" + #include +#include namespace Ui { @@ -18,7 +21,11 @@ public: ~cMainWindow(); private: - Ui::cMainWindow *ui; + Ui::cMainWindow* ui; + cMonthlyView* m_lpMonthlyView; + +protected: + void closeEvent(QCloseEvent* event); }; #endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui index 2f025dc..b236a98 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -1,24 +1,46 @@ + cMainWindow - - + + 0 0 - 400 - 300 + 939 + 742 - + cMainWindow - - - - + + + + + + + + + + + 0 + 0 + 939 + 21 + + + + + + TopToolBarArea + + + false + + + - - + diff --git a/cmonthlyitemdelegate.cpp b/cmonthlyitemdelegate.cpp new file mode 100644 index 0000000..450096c --- /dev/null +++ b/cmonthlyitemdelegate.cpp @@ -0,0 +1,114 @@ +#include "cmonthlyitemdelegate.h" +#include "common.h" + + +cMonthlyItemDelegate::cMonthlyItemDelegate(const QMap& code, QObject* parent) : + QStyledItemDelegate(parent), + m_code(code) +{ +} + +cMonthlyItemDelegate::~cMonthlyItemDelegate() +{ +} + +QWidget* cMonthlyItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const +{ + switch(index.column()) + { + case COL_COME1: + case COL_GO1: + case COL_COME2: + case COL_GO2: + case COL_COME3: + case COL_GO3: + case COL_BREAK: + { + QTimeEdit* lpTimeEdit = new QTimeEdit(parent); + lpTimeEdit->setDisplayFormat("HH:mm:ss"); + return(lpTimeEdit); + } + case COL_CODE: + { + QComboBox* lpComboBox = new QComboBox(parent); + + for(QMap::const_iterator i = m_code.constBegin();i != m_code.constEnd();i++) + lpComboBox->addItem(i.value()); + return(lpComboBox); + } + case COL_INFORMATION: + return(QStyledItemDelegate::createEditor(parent, option, index)); + default: + return(nullptr); + } +} + +void cMonthlyItemDelegate::setEditorData ( QWidget *editor, const QModelIndex &index ) const +{ + switch(index.column()) + { + case COL_COME1: + case COL_GO1: + case COL_COME2: + case COL_GO2: + case COL_COME3: + case COL_GO3: + case COL_BREAK: + { + QTimeEdit* lpTimeEdit = qobject_cast(editor); + lpTimeEdit->setTime(QTime::fromString(index.data(Qt::EditRole).toString())); + break; + } + case COL_CODE: + { + QComboBox* lpComboBox = qobject_cast(editor); + QString currentText = index.data(Qt::EditRole).toString(); + int cbIndex = lpComboBox->findText(m_code.value(currentText)); + + if(cbIndex >= 0) + lpComboBox->setCurrentIndex(cbIndex); + + break; + } + case COL_INFORMATION: + QStyledItemDelegate::setEditorData(editor, index); + break; + default: + break; + } +} + +void cMonthlyItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const +{ + switch(index.column()) + { + case COL_COME1: + case COL_GO1: + case COL_COME2: + case COL_GO2: + case COL_COME3: + case COL_GO3: + case COL_BREAK: + { + QTimeEdit* lpTimeEdit = qobject_cast(editor); + if(!lpTimeEdit->time().hour() && + !lpTimeEdit->time().minute() && + !lpTimeEdit->time().second()) + model->setData(index, "", Qt::EditRole); + else + model->setData(index, lpTimeEdit->time().toString(), Qt::EditRole); + break; + } + case COL_CODE: + { + QComboBox* lpComboBox = qobject_cast(editor); + model->setData(index, m_code.key(lpComboBox->currentText()), Qt::EditRole); + break; + } + case COL_INFORMATION: + QStyledItemDelegate::setModelData(editor, model, index); + break; + default: + break; + } +} diff --git a/cmonthlyitemdelegate.h b/cmonthlyitemdelegate.h new file mode 100644 index 0000000..145e98a --- /dev/null +++ b/cmonthlyitemdelegate.h @@ -0,0 +1,30 @@ +#ifndef CMONTHLYITEMDELEGATE_H +#define CMONTHLYITEMDELEGATE_H + + +#include +#include +#include +#include + +#include + + +class cMonthlyItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + cMonthlyItemDelegate(const QMap& code, QObject* parent = nullptr); + ~cMonthlyItemDelegate(); + + virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; + virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + +signals: + +private: + QMap m_code; +}; + +#endif // CMONTHLYITEMDELEGATE_H diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp new file mode 100644 index 0000000..bfc6748 --- /dev/null +++ b/cmonthlyview.cpp @@ -0,0 +1,118 @@ +#include "cmonthlyview.h" +#include "ui_cmonthlyview.h" + +#include "common.h" + + +cMonthlyView::cMonthlyView(const QDate& date, QWidget *parent) : + QWidget(parent), + ui(new Ui::cMonthlyView) +{ + m_code.insert(" ", tr("")); + m_code.insert("G", tr("Gleitzeit")); + m_code.insert("U", tr("Urlaub")); + m_code.insert("K", tr("Krank")); + m_code.insert("SU", tr("Sonderurlaub")); + + ui->setupUi(this); + + m_lpMonthlyListModel = new QStandardItemModel(0, 1); + ui->m_lpMonthlyList->setModel(m_lpMonthlyListModel); + ui->m_lpMonthlyList->setItemDelegate(new cMonthlyItemDelegate(m_code)); + + setDate(date); +} + +void cMonthlyView::setDate(const QDate& date) +{ + m_lpMonthlyListModel->clear(); + + QStringList header; + header << tr("day") << tr("public holiday") << tr("come1") << tr("go1") << tr("come2") << tr("go2") << tr("come3") << tr("go3") << tr("break") << tr("code") << tr("is") << tr("should") << tr("+/-") << tr("information") << tr("current +/-") << tr("hours dec") << tr("day"); + m_lpMonthlyListModel->setHorizontalHeaderLabels(header); + + QList items; + for(int y = 0;y < header.count();y++) + items.append(new QStandardItem); + + items[COL_DAY1]->setText("99"); + items[COL_PUBLIC_HOLIDAY]->setText(""); + items[COL_COME1]->setText("00:00:00"); + items[COL_GO1]->setText("00:00:00"); + items[COL_COME2]->setText("00:00:00"); + items[COL_GO2]->setText("00:00:00"); + items[COL_COME3]->setText("00:00:00"); + items[COL_GO3]->setText("00:00:00"); + items[COL_BREAK]->setText("00:00:00"); + items[COL_CODE]->setText(""); + items[COL_IS]->setText("00:00:00"); + items[COL_SHOULD]->setText("00:00:00"); + items[COL_DIFF]->setText("00:00:00"); + items[COL_INFORMATION]->setText(""); + items[COL_CURRENT]->setText("00:00:00"); + items[COL_HOURS_DEC]->setText("0.0"); + items[COL_DAY2]->setText("99"); + + m_lpMonthlyListModel->appendRow(items); + + for(int y = 0;y < header.count();y++) + ui->m_lpMonthlyList->resizeColumnToContents(y); + + m_lpMonthlyListModel->removeRows(0, 1); + + QDate date1 = date; + date1.setDate(date.year(), date.month(), 1); + + for(;date1.month() == date.month();date1 = date1.addDays(1)) + { + items.clear(); + + for(int y = 0;y < header.count();y++) + items.append(new QStandardItem); + + items[COL_DAY1]->setText(date1.toString("dddd dd")); + items[COL_PUBLIC_HOLIDAY]->setText(""); + items[COL_COME1]->setText(""); + items[COL_GO1]->setText(""); + items[COL_COME2]->setText(""); + items[COL_GO2]->setText(""); + items[COL_COME3]->setText(""); + items[COL_GO3]->setText(""); + items[COL_BREAK]->setText("00:00:00"); + items[COL_CODE]->setText(""); + items[COL_IS]->setText("00:00:00"); + items[COL_SHOULD]->setText("00:00:00"); + items[COL_DIFF]->setText("00:00:00"); + items[COL_INFORMATION]->setText(""); + items[COL_CURRENT]->setText("00:00:00"); + items[COL_HOURS_DEC]->setText("0.0"); + items[COL_DAY2]->setText(date1.toString("dd dddd")); + + items[COL_DAY1]->setTextAlignment(Qt::AlignRight); + items[COL_PUBLIC_HOLIDAY]->setTextAlignment(Qt::AlignHCenter); + items[COL_COME1]->setTextAlignment(Qt::AlignHCenter); + items[COL_GO1]->setTextAlignment(Qt::AlignHCenter); + items[COL_COME2]->setTextAlignment(Qt::AlignHCenter); + items[COL_GO2]->setTextAlignment(Qt::AlignHCenter); + items[COL_COME3]->setTextAlignment(Qt::AlignHCenter); + items[COL_GO3]->setTextAlignment(Qt::AlignHCenter); + items[COL_BREAK]->setTextAlignment(Qt::AlignHCenter); + items[COL_CODE]->setTextAlignment(Qt::AlignHCenter); + items[COL_IS]->setTextAlignment(Qt::AlignHCenter); + items[COL_SHOULD]->setTextAlignment(Qt::AlignHCenter); + items[COL_DIFF]->setTextAlignment(Qt::AlignHCenter); + items[COL_INFORMATION]->setTextAlignment(Qt::AlignLeft); + items[COL_CURRENT]->setTextAlignment(Qt::AlignHCenter); + items[COL_HOURS_DEC]->setTextAlignment(Qt::AlignRight); + items[COL_DAY2]->setTextAlignment(Qt::AlignLeft); + + m_lpMonthlyListModel->appendRow(items); + } + ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY1); + ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY2); +} + +cMonthlyView::~cMonthlyView() +{ + delete ui; +} diff --git a/cmonthlyview.h b/cmonthlyview.h new file mode 100644 index 0000000..f008baa --- /dev/null +++ b/cmonthlyview.h @@ -0,0 +1,31 @@ +#ifndef CMONTHLYVIEW_H +#define CMONTHLYVIEW_H + + +#include "cmonthlyitemdelegate.h" + +#include +#include +#include + + +namespace Ui { +class cMonthlyView; +} + +class cMonthlyView : public QWidget +{ + Q_OBJECT + +public: + explicit cMonthlyView(const QDate& date, QWidget *parent = nullptr); + ~cMonthlyView(); + + void setDate(const QDate& date); +private: + Ui::cMonthlyView* ui; + QStandardItemModel* m_lpMonthlyListModel; + QMap m_code; +}; + +#endif // CMONTHLYVIEW_H diff --git a/cmonthlyview.ui b/cmonthlyview.ui new file mode 100644 index 0000000..1e32c4f --- /dev/null +++ b/cmonthlyview.ui @@ -0,0 +1,50 @@ + + + cMonthlyView + + + + 0 + 0 + 996 + 525 + + + + Form + + + + + + true + + + + + 0 + 0 + 976 + 505 + + + + + + + true + + + false + + + + + + + + + + + + diff --git a/common.h b/common.h new file mode 100644 index 0000000..1818e6f --- /dev/null +++ b/common.h @@ -0,0 +1,24 @@ +#ifndef COMMON_H +#define COMMON_H + + +#define COL_DAY1 0 +#define COL_PUBLIC_HOLIDAY 1 +#define COL_COME1 2 +#define COL_GO1 3 +#define COL_COME2 4 +#define COL_GO2 5 +#define COL_COME3 6 +#define COL_GO3 7 +#define COL_BREAK 8 +#define COL_CODE 9 +#define COL_IS 10 +#define COL_SHOULD 11 +#define COL_DIFF 12 +#define COL_INFORMATION 13 +#define COL_CURRENT 14 +#define COL_HOURS_DEC 15 +#define COL_DAY2 16 + + +#endif // COMMON_H diff --git a/cpublicholiday.cpp b/cpublicholiday.cpp new file mode 100644 index 0000000..2f6cb9e --- /dev/null +++ b/cpublicholiday.cpp @@ -0,0 +1,7 @@ +#include "cpublicholiday.h" + + +cPublicHoliday::cPublicHoliday() +{ + +} diff --git a/cpublicholiday.h b/cpublicholiday.h new file mode 100644 index 0000000..af06d8c --- /dev/null +++ b/cpublicholiday.h @@ -0,0 +1,11 @@ +#ifndef CPUBLICHOLIDAY_H +#define CPUBLICHOLIDAY_H + + +class cPublicHoliday +{ +public: + cPublicHoliday(); +}; + +#endif // CPUBLICHOLIDAY_H diff --git a/main.cpp b/main.cpp index a90eb7a..b935f10 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,26 @@ #include "cmainwindow.h" #include +#include + + int main(int argc, char *argv[]) { QApplication a(argc, argv); + + a.setApplicationDisplayName("workingHours"); + a.setOrganizationName("WIN-DESIGN"); + a.setOrganizationDomain("windesign.at"); + a.setApplicationName("workingHours"); + + QSettings settings; + cMainWindow w; - w.show(); + + if(settings.value("main/maximized").toBool()) + w.showMaximized(); + else + w.show(); return a.exec(); } diff --git a/workingHours.pro b/workingHours.pro index bb02bf8..96b6153 100644 --- a/workingHours.pro +++ b/workingHours.pro @@ -25,14 +25,22 @@ DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++11 SOURCES += \ + cmonthlyitemdelegate.cpp \ + cmonthlyview.cpp \ + cpublicholiday.cpp \ main.cpp \ cmainwindow.cpp HEADERS += \ - cmainwindow.h + cmainwindow.h \ + cmonthlyitemdelegate.h \ + cmonthlyview.h \ + common.h \ + cpublicholiday.h FORMS += \ - cmainwindow.ui + cmainwindow.ui \ + cmonthlyview.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin