12 changed files with 334 additions and 1 deletions
@ -0,0 +1,12 @@
|
||||
#include "reportdialog.h" |
||||
|
||||
#include "mainwindow.h" |
||||
|
||||
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) |
||||
{ |
||||
ui_.setupUi(this); |
||||
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace(); |
||||
model_ = std::make_unique<ReportModel>(market_, ui_.reportView); |
||||
ui_.reportView->setModel(model_.get()); |
||||
ui_.reportView->hideColumn(0); |
||||
} |
@ -0,0 +1,26 @@
|
||||
#ifndef REPORT_DIALOG_H |
||||
#define REPORT_DIALOG_H |
||||
|
||||
#include "ui_reportdialog.h" |
||||
|
||||
#include "reportmodel.h" |
||||
|
||||
#include <marketplace.h> |
||||
|
||||
#include <QDialog> |
||||
|
||||
class ReportDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
ReportDialog(QWidget* parent = nullptr, |
||||
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint); |
||||
|
||||
private: |
||||
Ui::ReportDialog ui_; |
||||
Marketplace* market_; |
||||
std::unique_ptr<ReportModel> model_; |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>ReportDialog</class> |
||||
<widget class="QDialog" name="ReportDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>800</width> |
||||
<height>600</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Auswertung</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout_2"> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QTableView" name="reportView"/> |
||||
</item> |
||||
<item> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QPushButton" name="pushButton"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Quittung drucken</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="pushButton_2"> |
||||
<property name="text"> |
||||
<string>Exportieren (.csv)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="pushButton_3"> |
||||
<property name="text"> |
||||
<string>Übersicht drucken</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="verticalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>20</width> |
||||
<height>40</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>ReportDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>ReportDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -0,0 +1,99 @@
|
||||
#include "reportmodel.h" |
||||
|
||||
#include <QFont> |
||||
|
||||
ReportModel::ReportModel(Marketplace* market, QObject* parent) |
||||
: QAbstractTableModel(parent), market_(market) |
||||
{ |
||||
} |
||||
|
||||
int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const |
||||
{ |
||||
return static_cast<int>(market_->getSellers().size()); |
||||
} |
||||
|
||||
int ReportModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 7; } |
||||
|
||||
QVariant ReportModel::data(const QModelIndex& index, int role) const |
||||
{ |
||||
if (role == Qt::FontRole) { |
||||
QFont myFont; |
||||
|
||||
switch (index.column()) { |
||||
case 4: |
||||
[[fallthrough]]; |
||||
case 5: |
||||
[[fallthrough]]; |
||||
case 6: |
||||
myFont.setFamily("monospace"); |
||||
return myFont; |
||||
default: |
||||
return myFont; |
||||
} |
||||
} |
||||
|
||||
if (role == Qt::TextAlignmentRole) { |
||||
switch (index.column()) { |
||||
case 4: |
||||
return Qt::AlignRight; |
||||
default: |
||||
return Qt::AlignLeft; |
||||
} |
||||
} |
||||
|
||||
if (role != Qt::DisplayRole) |
||||
return QVariant(); |
||||
|
||||
if (market_->getSellers().size() == 0) |
||||
return QVariant(); |
||||
|
||||
Seller* seller = market_->getSellers().at(index.row()).get(); |
||||
|
||||
switch (index.column()) { |
||||
case 0: |
||||
return seller->getUuidAsString().c_str(); |
||||
case 1: |
||||
return seller->getSellerNo(); |
||||
case 2: |
||||
return seller->getLastName().c_str(); |
||||
case 3: |
||||
return seller->getFirstName().c_str(); |
||||
case 4: |
||||
return seller->numArticlesSold(); |
||||
case 5: |
||||
return seller->sumAsString().c_str(); |
||||
case 6: |
||||
return paymentAsString(seller->sumInCents(), 20).c_str(); |
||||
default: |
||||
return "???"; |
||||
} |
||||
} |
||||
|
||||
QVariant ReportModel::headerData(int section, Qt::Orientation orientation, int role) const |
||||
{ |
||||
if (role != Qt::DisplayRole) |
||||
return QVariant(); |
||||
|
||||
if (orientation == Qt::Horizontal) { |
||||
switch (section) { |
||||
case 0: |
||||
return "ID"; |
||||
case 1: |
||||
return "Nummer"; |
||||
case 2: |
||||
return "Nachname"; |
||||
case 3: |
||||
return "Vorname"; |
||||
case 4: |
||||
return "verkauft"; |
||||
case 5: |
||||
return "Umsatz"; |
||||
case 6: |
||||
return "Auszahlung"; |
||||
default: |
||||
return "???"; |
||||
} |
||||
// return QStringLiteral("%1").arg(section);
|
||||
} else |
||||
return ""; |
||||
} |
@ -0,0 +1,21 @@
|
||||
#ifndef REPORT_MODEL_H |
||||
#define REPORT_MODEL_H |
||||
|
||||
#include <marketplace.h> |
||||
|
||||
#include <QAbstractTableModel> |
||||
|
||||
class ReportModel : public QAbstractTableModel |
||||
{ |
||||
public: |
||||
explicit ReportModel(Marketplace* market, QObject* parent = nullptr); |
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; |
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; |
||||
|
||||
private: |
||||
Marketplace* market_; |
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue