more on sellerdialog

This commit is contained in:
Martin Brodbeck 2018-07-16 12:00:17 +02:00
parent 31d46866f2
commit 207edb27ba
13 changed files with 168 additions and 17 deletions

View File

@ -5,7 +5,8 @@
"includePath": [
"${workspaceFolder}/**",
"/usr/include/qt",
"/usr/include/qt/QtWidgets"
"/usr/include/qt/QtWidgets",
"/usr/include/qt/QtCore"
],
"defines": [],
"compilerPath": "/usr/bin/clang",

View File

@ -61,5 +61,6 @@
"utility": "cpp",
"variant": "cpp",
"algorithm": "cpp"
}
},
"C_Cpp.clang_format_path": "/usr/bin/clang-format"
}

View File

@ -19,6 +19,7 @@ class Entity
void setSourceNo(int sourceNo);
const boost::uuids::uuid& getUuid() const { return uuid_; };
std::string getUuidAsString() const { return boost::uuids::to_string(uuid_); }
virtual State getState() const;
virtual int getSourceNo() const;

View File

@ -1,9 +1,18 @@
#include "marketplace.h"
#include "database.h"
void Marketplace::storeToDb() {
Marketplace::Marketplace()
{
auto seller = std::make_shared<Seller>("Max", "Mustermann");
sellers_.push_back(seller);
}
void Marketplace::storeToDb()
{
const std::string DB_PATH{"/tmp/kima2.db"};
Database db(DB_PATH);
db.storeSellers(sellers_);
}
std::vector<std::shared_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }

View File

@ -10,8 +10,11 @@
class Marketplace
{
public:
Marketplace();
void storeToDb();
void loadFromDb();
std::vector<std::shared_ptr<Seller>>& getSellers();
private:
std::vector<std::shared_ptr<Seller>> sellers_;
std::vector<std::shared_ptr<Sale>> sales_;

View File

@ -12,6 +12,9 @@ set(GUI_SOURCES
kima2.cpp
mainwindow.cpp
mainwindow.ui
sellerdialog.cpp
sellerdialog.ui
sellermodel.cpp
)
add_executable(kima2 ${GUI_SOURCES})

View File

@ -1,11 +1,19 @@
#include "mainwindow.h"
#include "sellerdialog.h"
MainWindow::MainWindow()
{
ui_.setupUi(this);
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
connect(ui_.actionEditSeller, &QAction::triggered, this, &MainWindow::on_actionEditSeller_triggered);
marketplace_ = std::make_unique<Marketplace>();
}
void MainWindow::on_actionEditSeller_triggered()
{
auto dialog = std::make_unique<SellerDialog>(this);
dialog->exec();
}

View File

@ -1,9 +1,10 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include <marketplace.h>
#include "ui_mainwindow.h"
#include <QMainWindow>
#include <memory>
@ -14,8 +15,11 @@ class MainWindow : public QMainWindow
public:
MainWindow();
Marketplace* getMarketplace() {return marketplace_.get();}
private:
void on_actionEditSeller_triggered();
Ui::MainWindow ui_;
std::unique_ptr<Marketplace> marketplace_;
};

12
src/gui/sellerdialog.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "sellerdialog.h"
#include "mainwindow.h"
SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ui_.setupUi(this);
SellerModel* model = new SellerModel(
dynamic_cast<MainWindow*>(parent)->getMarketplace()->getSellers(), ui_.tableView);
ui_.tableView->setModel(model);
ui_.tableView->setColumnHidden(0, true); // hide the uuid
}

22
src/gui/sellerdialog.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SELLER_DIALOG_H
#define SELLER_DIALOG_H
#include "ui_sellerdialog.h"
#include "sellermodel.h"
#include <QDialog>
class SellerDialog : public QDialog
{
Q_OBJECT
public:
SellerDialog(QWidget* parent = nullptr,
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
private:
Ui::SellerDialog ui_;
};
#endif

View File

@ -1,17 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>sellerDialog</class>
<widget class="QDialog" name="sellerDialog">
<class>SellerDialog</class>
<widget class="QDialog" name="SellerDialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Verkäufer Dialog</string>
@ -23,7 +21,17 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="tableView"/>
<widget class="QTableView" name="tableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -82,7 +90,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>sellerDialog</receiver>
<receiver>SellerDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -98,7 +106,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>sellerDialog</receiver>
<receiver>SellerDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

58
src/gui/sellermodel.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "sellermodel.h"
SellerModel::SellerModel(std::vector<std::shared_ptr<Seller>>& sellers, QObject* parent)
: QAbstractTableModel(parent), sellers_(&sellers)
{
}
int SellerModel::rowCount(const QModelIndex& parent) const { return sellers_->size(); }
int SellerModel::columnCount(const QModelIndex& parent) const { return 5; }
QVariant SellerModel::data(const QModelIndex& index, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
Seller* seller = sellers_->at(index.row()).get();
switch (index.column()) {
case 0:
return seller->getUuidAsString().c_str();
case 1:
return seller->getSellerNo();
case 2:
return seller->getFirstName().c_str();
case 3:
return QString(seller->getLastName().c_str());
case 4:
return seller->numArticlesOffered();
default:
return "???";
}
return QVariant{};
}
QVariant SellerModel::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 "Vorname";
case 3:
return "Nachname";
case 4:
return "Anz. Artikel";
default:
return "???";
}
return QStringLiteral("%1").arg(section);
} else
return "";
}

21
src/gui/sellermodel.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef SELLER_MODEL_H
#define SELLER_MODEL_H
#include <marketplace.h>
#include <QAbstractTableModel>
class SellerModel : public QAbstractTableModel
{
public:
explicit SellerModel(std::vector<std::shared_ptr<Seller>>& sellers, 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:
std::vector<std::shared_ptr<Seller>>* sellers_;
};
#endif