Absence plugin #54
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>947</width>
|
||||||
<height>300</height>
|
<height>300</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -17,33 +17,99 @@ bool AbsencesModel::enabled() const
|
|||||||
|
|
||||||
int AbsencesModel::rowCount(const QModelIndex &parent) const
|
int AbsencesModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
|
return m_absences.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AbsencesModel::columnCount(const QModelIndex &parent) const
|
int AbsencesModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant AbsencesModel::data(const QModelIndex &index, int role) const
|
QVariant AbsencesModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(index.row() < m_absences.count());
|
||||||
|
const auto &absence = m_absences.at(index.row());
|
||||||
|
|
||||||
|
switch(role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
case Qt::EditRole:
|
||||||
|
switch(index.column())
|
||||||
|
{
|
||||||
|
case 0: return absence.altRepresentative;
|
||||||
|
case 1: return absence.compositeId;
|
||||||
|
case 2: return absence.end;
|
||||||
|
case 3: return absence.hourCategory;
|
||||||
|
case 4: return absence.openMarking;
|
||||||
|
case 5: return absence.persNr;
|
||||||
|
case 6: return absence.representative;
|
||||||
|
case 7: return absence.start;
|
||||||
|
case 8: return absence.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant AbsencesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant AbsencesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
|
switch(orientation)
|
||||||
|
{
|
||||||
|
case Qt::Horizontal:
|
||||||
|
switch(role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
case Qt::EditRole:
|
||||||
|
switch(section)
|
||||||
|
{
|
||||||
|
case 0: return tr("altRepresentative");
|
||||||
|
case 1: return tr("compositeId");
|
||||||
|
case 2: return tr("end");
|
||||||
|
case 3: return tr("hourCategory");
|
||||||
|
case 4: return tr("openMarking");
|
||||||
|
case 5: return tr("persNr");
|
||||||
|
case 6: return tr("representative");
|
||||||
|
case 7: return tr("start");
|
||||||
|
case 8: return tr("text");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
qt_noop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbsencesModel::setDate(const QDate &date)
|
void AbsencesModel::setDate(const QDate &date)
|
||||||
{
|
{
|
||||||
m_date = date;
|
m_date = date;
|
||||||
|
|
||||||
|
auto oldEnabled = enabled();
|
||||||
|
|
||||||
m_reply = m_erfassung.doGetAbsences(m_userId, m_date, m_date);
|
m_reply = m_erfassung.doGetAbsences(m_userId, m_date, m_date);
|
||||||
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &AbsencesModel::finished);
|
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &AbsencesModel::finished);
|
||||||
|
|
||||||
|
if(oldEnabled != enabled())
|
||||||
|
Q_EMIT enabledChanged(enabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbsencesModel::finished()
|
void AbsencesModel::finished()
|
||||||
{
|
{
|
||||||
|
if(!m_reply->success())
|
||||||
|
Q_EMIT errorOccured(m_reply->message());
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
m_absences = m_reply->absences();
|
||||||
|
endResetModel();
|
||||||
|
|
||||||
|
auto oldEnabled = enabled();
|
||||||
|
|
||||||
|
m_reply = Q_NULLPTR;
|
||||||
|
|
||||||
|
if(oldEnabled != enabled())
|
||||||
|
Q_EMIT enabledChanged(enabled());
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ public:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void enabledChanged(bool enabled);
|
void enabledChanged(bool enabled);
|
||||||
|
void errorOccured(const QString &message);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setDate(const QDate &date);
|
void setDate(const QDate &date);
|
||||||
@@ -39,4 +40,5 @@ private:
|
|||||||
QDate m_date;
|
QDate m_date;
|
||||||
ZeiterfassungApi &m_erfassung;
|
ZeiterfassungApi &m_erfassung;
|
||||||
std::unique_ptr<GetAbsencesReply> m_reply;
|
std::unique_ptr<GetAbsencesReply> m_reply;
|
||||||
|
QVector<GetAbsencesReply::Absence> m_absences;
|
||||||
};
|
};
|
||||||
|
@@ -16,7 +16,7 @@ GetAbsencesReply::GetAbsencesReply(std::unique_ptr<QNetworkReply> &&reply, Zeite
|
|||||||
connect(m_reply.get(), &QNetworkReply::finished, this, &GetAbsencesReply::requestFinished);
|
connect(m_reply.get(), &QNetworkReply::finished, this, &GetAbsencesReply::requestFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<GetAbsencesReply::Absence> &GetAbsencesReply::getAbsences() const
|
const QVector<GetAbsencesReply::Absence> &GetAbsencesReply::absences() const
|
||||||
{
|
{
|
||||||
return m_absences;
|
return m_absences;
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ public:
|
|||||||
QString text;
|
QString text;
|
||||||
};
|
};
|
||||||
|
|
||||||
const QVector<Absence> &getAbsences() const;
|
const QVector<Absence> &absences() const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void requestFinished();
|
void requestFinished();
|
||||||
|
Reference in New Issue
Block a user