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": [ "includePath": [
"${workspaceFolder}/**", "${workspaceFolder}/**",
"/usr/include/qt", "/usr/include/qt",
"/usr/include/qt/QtWidgets" "/usr/include/qt/QtWidgets",
"/usr/include/qt/QtCore"
], ],
"defines": [], "defines": [],
"compilerPath": "/usr/bin/clang", "compilerPath": "/usr/bin/clang",

View file

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

View file

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

View file

@ -1,9 +1,18 @@
#include "marketplace.h" #include "marketplace.h"
#include "database.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"}; const std::string DB_PATH{"/tmp/kima2.db"};
Database db(DB_PATH); Database db(DB_PATH);
db.storeSellers(sellers_); db.storeSellers(sellers_);
} }
std::vector<std::shared_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }

View file

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

View file

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

View file

@ -1,11 +1,19 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "sellerdialog.h"
MainWindow::MainWindow() MainWindow::MainWindow()
{ {
ui_.setupUi(this); ui_.setupUi(this);
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit); connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
connect(ui_.actionEditSeller, &QAction::triggered, this, &MainWindow::on_actionEditSeller_triggered);
marketplace_ = std::make_unique<Marketplace>(); 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 #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include "ui_mainwindow.h"
#include <marketplace.h> #include <marketplace.h>
#include "ui_mainwindow.h"
#include <QMainWindow> #include <QMainWindow>
#include <memory> #include <memory>
@ -14,8 +15,11 @@ class MainWindow : public QMainWindow
public: public:
MainWindow(); MainWindow();
Marketplace* getMarketplace() {return marketplace_.get();}
private: private:
void on_actionEditSeller_triggered();
Ui::MainWindow ui_; Ui::MainWindow ui_;
std::unique_ptr<Marketplace> marketplace_; 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"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>sellerDialog</class> <class>SellerDialog</class>
<widget class="QDialog" name="sellerDialog"> <widget class="QDialog" name="SellerDialog">
<property name="windowModality"> <property name="windowModality">
<enum>Qt::NonModal</enum> <enum>Qt::NonModal</enum>
</property> </property>
<property name="geometry"> <property name="sizePolicy">
<rect> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<x>0</x> <horstretch>0</horstretch>
<y>0</y> <verstretch>0</verstretch>
<width>400</width> </sizepolicy>
<height>300</height>
</rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Verkäufer Dialog</string> <string>Verkäufer Dialog</string>
@ -23,7 +21,17 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <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>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -82,7 +90,7 @@
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>accepted()</signal> <signal>accepted()</signal>
<receiver>sellerDialog</receiver> <receiver>SellerDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -98,7 +106,7 @@
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>
<receiver>sellerDialog</receiver> <receiver>SellerDialog</receiver>
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <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