Compare commits
No commits in common. "ffbf27c1f8cb53073228bbb5ce327e05f2153206" and "e06458b419d9c66492e2a252977f4ede6184254b" have entirely different histories.
ffbf27c1f8
...
e06458b419
7 changed files with 4 additions and 60 deletions
|
@ -33,9 +33,3 @@ int Marketplace::getNextSellerNo()
|
||||||
});
|
});
|
||||||
return (*iter)->getSellerNo() + 1;
|
return (*iter)->getSellerNo() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Marketplace::getNumSellersDelete()
|
|
||||||
{
|
|
||||||
int count = std::count_if(sellers_.begin(), sellers_.end(), [](const auto& a){return a->getState() == Seller::State::DELETE;});
|
|
||||||
return count;
|
|
||||||
}
|
|
|
@ -15,7 +15,6 @@ class Marketplace
|
||||||
void loadFromDb();
|
void loadFromDb();
|
||||||
std::vector<std::unique_ptr<Seller>>& getSellers();
|
std::vector<std::unique_ptr<Seller>>& getSellers();
|
||||||
int getNextSellerNo();
|
int getNextSellerNo();
|
||||||
int getNumSellersDelete();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<Seller>> sellers_;
|
std::vector<std::unique_ptr<Seller>> sellers_;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QItemSelectionModel>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||||
|
@ -13,33 +12,13 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
||||||
ui_.tableView->setModel(model);
|
ui_.tableView->setModel(model);
|
||||||
ui_.tableView->setColumnHidden(0, true); // hide the uuid
|
ui_.tableView->setColumnHidden(0, true); // hide the uuid
|
||||||
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
|
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
|
||||||
connect(ui_.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SellerDialog::on_newButton_clicked()
|
void SellerDialog::on_newButton_clicked()
|
||||||
{
|
{
|
||||||
ui_.tableView->reset();
|
|
||||||
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
||||||
ui_.tableView->scrollToBottom();
|
ui_.tableView->scrollToBottom();
|
||||||
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1);
|
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1);
|
||||||
QModelIndex idx = ui_.tableView->model()->index(ui_.tableView->model()->rowCount() - 1, 2);
|
|
||||||
ui_.tableView->setCurrentIndex(idx);
|
|
||||||
ui_.tableView->edit(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SellerDialog::on_deleteButton_clicked()
|
|
||||||
{
|
|
||||||
auto selModel = ui_.tableView->selectionModel();
|
|
||||||
if (selModel->hasSelection() == false)
|
|
||||||
return;
|
|
||||||
auto indexes = selModel->selectedRows();
|
|
||||||
|
|
||||||
std::sort(indexes.begin(), indexes.end());
|
|
||||||
|
|
||||||
// Deleting the rows, beginning with the last one!
|
|
||||||
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
|
|
||||||
ui_.tableView->model()->removeRow(iter->row());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SellerDialog::accept()
|
void SellerDialog::accept()
|
||||||
|
@ -49,8 +28,7 @@ void SellerDialog::accept()
|
||||||
if (seller->getFirstName().empty() || seller->getLastName().empty()) {
|
if (seller->getFirstName().empty() || seller->getLastName().empty()) {
|
||||||
QMessageBox(QMessageBox::Icon::Critical, "Fehler",
|
QMessageBox(QMessageBox::Icon::Critical, "Fehler",
|
||||||
"Bitte geben Sie bei jedem Verkäufer Vorname und Nachname an.",
|
"Bitte geben Sie bei jedem Verkäufer Vorname und Nachname an.",
|
||||||
QMessageBox::StandardButton::Ok, this)
|
QMessageBox::StandardButton::Ok, this).exec();
|
||||||
.exec();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ class SellerDialog : public QDialog
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_newButton_clicked();
|
void on_newButton_clicked();
|
||||||
void on_deleteButton_clicked();
|
|
||||||
virtual void accept() override;
|
virtual void accept() override;
|
||||||
Ui::SellerDialog ui_;
|
Ui::SellerDialog ui_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,9 +39,6 @@
|
||||||
<property name="sizeAdjustPolicy">
|
<property name="sizeAdjustPolicy">
|
||||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionBehavior">
|
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -55,9 +52,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="editButton">
|
<widget class="QPushButton" name="editButton">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Bearbeiten</string>
|
<string>Bearbeiten</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -23,9 +23,9 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
||||||
|
|
||||||
/* if (seller->getState() == Seller::State::DELETE)
|
if (seller->getState() == Seller::State::DELETE)
|
||||||
return QVariant();
|
return QVariant::Invalid;
|
||||||
*/
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return seller->getUuidAsString().c_str();
|
return seller->getUuidAsString().c_str();
|
||||||
|
@ -130,22 +130,3 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
|
||||||
{
|
|
||||||
emit beginRemoveRows(parent, row, row + count - 1);
|
|
||||||
auto seller = marketplace_->getSellers().at(row).get();
|
|
||||||
if (seller->getState() == Seller::State::NEW) {
|
|
||||||
marketplace_->getSellers().erase(
|
|
||||||
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(),
|
|
||||||
[&seller](const std::unique_ptr<Seller>& a) {
|
|
||||||
return a->getUuid() == seller->getUuid();
|
|
||||||
}),
|
|
||||||
marketplace_->getSellers().end());
|
|
||||||
} else {
|
|
||||||
seller->setState(Seller::State::DELETE);
|
|
||||||
}
|
|
||||||
emit endRemoveRows();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
|
@ -16,7 +16,6 @@ class SellerModel : public QAbstractTableModel
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Marketplace* marketplace_;
|
Marketplace* marketplace_;
|
||||||
|
|
Loading…
Reference in a new issue