Added strips

This commit is contained in:
0xFEEDC0DE64
2017-12-02 11:43:38 +01:00
parent e8710becd3
commit bd9b8cb09d
10 changed files with 372 additions and 28 deletions

View File

@@ -14,6 +14,8 @@
#include "dialogs/aboutmedialog.h"
#include "dialogs/buchungdialog.h"
#include "dialogs/kontierungdialog.h"
#include "strips/buchungstrip.h"
#include "strips/kontierungstrip.h"
#include "models/buchungenmodel.h"
#include "models/kontierungenmodel.h"
@@ -79,6 +81,28 @@ MainWindow::~MainWindow()
delete ui;
}
int MainWindow::timeToSeconds(const QTime &time)
{
return QTime(0, 0).secsTo(time);
}
QTime MainWindow::timeBetween(const QTime &l, const QTime &r)
{
Q_ASSERT(l <= r);
return QTime(0, 0).addSecs(l.secsTo(r));
}
QTime MainWindow::timeAdd(const QTime &l, const QTime &r)
{
Q_ASSERT(timeToSeconds(l) + timeToSeconds(r) < 86400);
return l.addSecs(QTime(0, 0).secsTo(r));
}
QTime MainWindow::timeNormalise(const QTime &time)
{
return time.addSecs(-time.second());
}
void MainWindow::refresh()
{
ui->actionToday->setEnabled(false);
@@ -119,6 +143,8 @@ void MainWindow::refresh()
ui->actionRefresh->setEnabled(true);
ui->dateEditDate->setReadOnly(false);
}
clearStrips();
}
void MainWindow::getProjekteFinished(bool success, const QString &message, const QVector<Zeiterfassung::Projekt> &projekte)
@@ -215,6 +241,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewBuchungen->setEnabled(false);
clearStrips();
if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_buchungenModel, &BuchungenModel::refreshFinished,
@@ -263,6 +291,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewBuchungen->setEnabled(false);
clearStrips();
if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_buchungenModel, &BuchungenModel::refreshFinished,
@@ -315,6 +345,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewBuchungen->setEnabled(false);
clearStrips();
if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_buchungenModel, &BuchungenModel::refreshFinished,
@@ -385,6 +417,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewKontierungen->setEnabled(false);
clearStrips();
if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_kontierungenModel, &KontierungenModel::refreshFinished,
@@ -433,6 +467,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewKontierungen->setEnabled(false);
clearStrips();
if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_kontierungenModel, &KontierungenModel::refreshFinished,
@@ -485,6 +521,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos)
ui->pushButtonEnd->setEnabled(false);
ui->treeViewKontierungen->setEnabled(false);
clearStrips();
if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
{
connect(m_kontierungenModel, &KontierungenModel::refreshFinished,
@@ -718,6 +756,7 @@ void MainWindow::validateEntries()
}
m_lastKontierungStart = startBuchung.time;
ui->verticalLayout2->addWidget(new BuchungStrip(startBuchung.time, startBuchung.type, ui->scrollAreaWidgetContents));
if(kontierungenIter == m_kontierungenModel->constEnd())
{
@@ -737,6 +776,9 @@ void MainWindow::validateEntries()
return;
}
ui->verticalLayout2->addWidget(new KontierungStrip(QTime(0, 0), kontierung.timespan, kontierung.projekt,
kontierung.subprojekt, kontierung.workpackage, kontierung.text));
if(kontierung.timespan == QTime(0, 0))
{
if(buchungenIter != m_buchungenModel->constEnd())
@@ -876,6 +918,8 @@ void MainWindow::validateEntries()
m_kontierungTime = timeAdd(m_kontierungTime, kontierung.timespan);
}
}
ui->verticalLayout2->addWidget(new BuchungStrip(endBuchung.time, endBuchung.type, ui->scrollAreaWidgetContents));
}
}
}
@@ -955,24 +999,12 @@ void MainWindow::updateComboboxes()
}
}
int MainWindow::timeToSeconds(const QTime &time)
void MainWindow::clearStrips()
{
return QTime(0, 0).secsTo(time);
}
QTime MainWindow::timeBetween(const QTime &l, const QTime &r)
{
Q_ASSERT(l <= r);
return QTime(0, 0).addSecs(l.secsTo(r));
}
QTime MainWindow::timeAdd(const QTime &l, const QTime &r)
{
Q_ASSERT(timeToSeconds(l) + timeToSeconds(r) < 86400);
return l.addSecs(QTime(0, 0).secsTo(r));
}
QTime MainWindow::timeNormalise(const QTime &time)
{
return time.addSecs(-time.second());
QLayoutItem *item;
while(item = ui->verticalLayout2->takeAt(0))
{
item->widget()->deleteLater();
delete item;
}
}

View File

@@ -19,6 +19,11 @@ public:
explicit MainWindow(QSettings &settings, Zeiterfassung &erfassung, const Zeiterfassung::UserInfo &userInfo, QWidget *parent = 0);
~MainWindow();
static int timeToSeconds(const QTime &time);
static QTime timeBetween(const QTime &l, const QTime &r);
static QTime timeAdd(const QTime &l, const QTime &r);
static QTime timeNormalise(const QTime &time);
private Q_SLOTS:
void refresh();
void getProjekteFinished(bool success, const QString &message, const QVector<Zeiterfassung::Projekt> &projekte);
@@ -34,11 +39,7 @@ private Q_SLOTS:
private:
void validateEntries();
void updateComboboxes();
static int timeToSeconds(const QTime &time);
static QTime timeBetween(const QTime &l, const QTime &r);
static QTime timeAdd(const QTime &l, const QTime &r);
static QTime timeNormalise(const QTime &time);
void clearStrips();
Ui::MainWindow *ui;
QSettings &m_settings;

View File

@@ -176,10 +176,17 @@
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<attribute name="title">
<string>Optimized view</string>
</attribute>
<widget class="QWidget" name="scrollAreaWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout2" stretch="0,0">
</layout>
</widget>
</widget>
<widget class="QSplitter" name="splitter">
<property name="orientation">

33
strips/buchungstrip.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include "buchungstrip.h"
#include "ui_buchungstrip.h"
#include <QTime>
BuchungStrip::BuchungStrip(const QTime &time, const QString &type, QWidget *parent) :
QFrame(parent),
ui(new Ui::BuchungStrip)
{
ui->setupUi(this);
ui->labelTime->setText(time.toString("HH:mm"));
if(type == QStringLiteral("K"))
{
setStyleSheet("background-color: #7FFF7F;");
ui->labelType->setText(tr("KOMMEN"));
}
else if(type == QStringLiteral("G"))
{
setStyleSheet("background-color: #FF7F7F;");
ui->labelType->setText(tr("GEHEN"));
}
else
{
setStyleSheet("background-color: #FFFF7F;");
ui->labelType->setText(tr("UNKNOWN"));
}
}
BuchungStrip::~BuchungStrip()
{
delete ui;
}

22
strips/buchungstrip.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef BUCHUNGSTRIP_H
#define BUCHUNGSTRIP_H
#include <QFrame>
class QTime;
namespace Ui { class BuchungStrip; }
class BuchungStrip : public QFrame
{
Q_OBJECT
public:
explicit BuchungStrip(const QTime &time, const QString &type, QWidget *parent = 0);
~BuchungStrip();
private:
Ui::BuchungStrip *ui;
};
#endif // BUCHUNGSTRIP_H

72
strips/buchungstrip.ui Normal file
View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BuchungStrip</class>
<widget class="QFrame" name="BuchungStrip">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>50</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<property name="spacing">
<number>20</number>
</property>
<item>
<widget class="QLabel" name="labelTime">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelType">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,39 @@
#include "kontierungstrip.h"
#include "ui_kontierungstrip.h"
#include <QTime>
#include <QStringBuilder>
#include "mainwindow.h"
KontierungStrip::KontierungStrip(const QTime &startTime, const QTime &endTime, const QString &projekt,
const QString &subprojekt, const QString &workpackage, const QString &text,
QWidget *parent) :
QFrame(parent),
ui(new Ui::KontierungStrip)
{
ui->setupUi(this);
setStyleSheet("background-color: #7FFFFF;");
if(endTime == QTime(0, 0))
{
ui->labelTime->setText(QStringLiteral("%0 - ???").arg(startTime.toString("HH:mm")));
ui->labelDuration->setText(QStringLiteral("(???h)"));
}
else
{
ui->labelTime->setText(startTime.toString("HH:mm") % " - " % endTime.toString("HH:mm"));
ui->labelDuration->setText("(" % MainWindow::timeBetween(startTime, endTime).toString("HH:mm") % "h)");
}
ui->labelProjekt->setText(projekt);
ui->labelSubprojekt->setText(subprojekt);
ui->labelWorkpackage->setText(workpackage);
ui->labelText->setText(text);
}
KontierungStrip::~KontierungStrip()
{
delete ui;
}

24
strips/kontierungstrip.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef KONTIERUNGSTRIP_H
#define KONTIERUNGSTRIP_H
#include <QFrame>
class QTime;
namespace Ui { class KontierungStrip; }
class KontierungStrip : public QFrame
{
Q_OBJECT
public:
explicit KontierungStrip(const QTime &startTime, const QTime &endTime, const QString &projekt,
const QString &subprojekt, const QString &workpackage, const QString &text,
QWidget *parent = 0);
~KontierungStrip();
private:
Ui::KontierungStrip *ui;
};
#endif // KONTIERUNGSTRIP_H

108
strips/kontierungstrip.ui Normal file
View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KontierungStrip</class>
<widget class="QFrame" name="KontierungStrip">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>102</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>102</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="spacing">
<number>20</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelTime">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelDuration">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelProjekt">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSubprojekt">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelWorkpackage">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelText">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -23,7 +23,9 @@ SOURCES += main.cpp \
models/buchungenmodel.cpp \
dialogs/kontierungdialog.cpp \
models/kontierungenmodel.cpp \
eventloopwithstatus.cpp
eventloopwithstatus.cpp \
strips/buchungstrip.cpp \
strips/kontierungstrip.cpp
HEADERS += \
zeiterfassung.h \
@@ -34,7 +36,9 @@ HEADERS += \
models/buchungenmodel.h \
dialogs/kontierungdialog.h \
models/kontierungenmodel.h \
eventloopwithstatus.h
eventloopwithstatus.h \
strips/buchungstrip.h \
strips/kontierungstrip.h
RESOURCES += \
resources.qrc
@@ -44,4 +48,6 @@ FORMS += \
dialogs/aboutmedialog.ui \
dialogs/authenticationdialog.ui \
dialogs/buchungdialog.ui \
dialogs/kontierungdialog.ui
dialogs/kontierungdialog.ui \
strips/buchungstrip.ui \
strips/kontierungstrip.ui