Compare commits
2 commits
69dd1afba5
...
3ec2143f28
Author | SHA1 | Date | |
---|---|---|---|
3ec2143f28 | |||
f697487d6b |
5 changed files with 23 additions and 8 deletions
|
@ -111,6 +111,7 @@ void BasketModel::finishSale()
|
|||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
||||
marketplace_->finishCurrentSale();
|
||||
emit endRemoveRows();
|
||||
emit basketDataChanged();
|
||||
}
|
||||
|
||||
void BasketModel::cancelSale()
|
||||
|
|
|
@ -23,6 +23,9 @@ class BasketModel : public QAbstractTableModel
|
|||
void cancelSale();
|
||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
|
||||
signals:
|
||||
void basketDataChanged();
|
||||
|
||||
private:
|
||||
Marketplace* marketplace_;
|
||||
};
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "basketmodel.h"
|
||||
#include "pricedialog.h"
|
||||
#include "sellerdialog.h"
|
||||
#include "salemodel.h"
|
||||
#include "sellerdialog.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
|
@ -40,6 +40,9 @@ MainWindow::MainWindow()
|
|||
&MainWindow::onCancelArticleButtonClicked);
|
||||
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this,
|
||||
&MainWindow::onCancelAllArticlesButtonClicked);
|
||||
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
|
||||
static_cast<SaleModel*>(ui_.salesView->model()),
|
||||
&SaleModel::onBasketDataChanged);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEditSeller_triggered()
|
||||
|
@ -65,6 +68,7 @@ void MainWindow::on_paidButton_triggered()
|
|||
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
||||
ui_.lastPriceLabel1->setText(lastPrice);
|
||||
ui_.lastPriceLabel2->setText(lastPrice);
|
||||
// static_cast<SaleModel*>(ui_.salesView->model())->onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,14 +51,9 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const
|
|||
if (sale == rootItem.get())
|
||||
return QModelIndex();
|
||||
else {
|
||||
/* auto iter =
|
||||
std::find_if(marketplace_->getSales().begin(), marketplace_->getSales().end(),
|
||||
[&sale](const auto& s) { return s.get() == sale; });
|
||||
auto pos = std::distance(marketplace_->getSales().begin(), iter); */
|
||||
return createIndex(-1, 0, rootItem.get());
|
||||
}
|
||||
} else {
|
||||
// article = static_cast<Article*>(index.internalPointer());
|
||||
article = dynamic_cast<Article*>(ent);
|
||||
|
||||
if (!article) {
|
||||
|
@ -90,7 +85,6 @@ QVariant SaleModel::data(const QModelIndex& index, int role) const
|
|||
case 1:
|
||||
myFont.setFamily("monospace");
|
||||
return myFont;
|
||||
return myFont;
|
||||
default:
|
||||
return myFont;
|
||||
}
|
||||
|
@ -162,3 +156,13 @@ QVariant SaleModel::headerData(int section, Qt::Orientation orientation, int rol
|
|||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
void SaleModel::onBasketDataChanged()
|
||||
{
|
||||
emit beginResetModel();
|
||||
auto& sales = marketplace_->getSales();
|
||||
std::sort(sales.begin(), sales.end(), [](const auto& lhs, const auto& rhs) {
|
||||
return lhs->getTimestamp() > rhs->getTimestamp();
|
||||
});
|
||||
emit endResetModel();
|
||||
}
|
|
@ -19,6 +19,9 @@ class SaleModel : public QAbstractItemModel
|
|||
int columnCount(const QModelIndex& parent) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
public slots:
|
||||
void onBasketDataChanged();
|
||||
|
||||
private:
|
||||
Marketplace* marketplace_;
|
||||
std::unique_ptr<Sale> rootItem{new Sale()};
|
||||
|
|
Loading…
Reference in a new issue