fixed only handling two fields of a check
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QIODevice>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QVector>
|
||||
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
||||
: checks(checks), QAbstractTableModel{parent}
|
||||
{}
|
||||
@@ -33,13 +33,15 @@ bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &val
|
||||
if (!index.isValid() || index.row() >= checks->size())
|
||||
return false;
|
||||
unsigned int row = index.row();
|
||||
Check &c = checks->at(row);
|
||||
switch (index.column()) {
|
||||
case 0: {
|
||||
checks->at(row).set_date(value.value<std::string>());
|
||||
case 0:
|
||||
c.set_date(value.value<std::string>());
|
||||
break;
|
||||
} case 1:
|
||||
checks->at(row).set_total(value.value<double>());
|
||||
case 1:
|
||||
c.set_total(value.value<double>());
|
||||
break;
|
||||
emit dataChanged(index, index, {role});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -51,10 +53,8 @@ QVariant CheckQueueTableModel::headerData(int section, Qt::Orientation orientati
|
||||
switch (section) {
|
||||
case 0:
|
||||
return tr("Date&Time");
|
||||
break;
|
||||
case 1:
|
||||
return tr("Total");
|
||||
break;
|
||||
}
|
||||
} else if (role == Qt::DisplayRole && orientation == Qt::Vertical) {
|
||||
return section + 1;
|
||||
@@ -117,9 +117,16 @@ QMimeData* CheckQueueTableModel::mimeData(const QModelIndexList &indexes) const
|
||||
|
||||
for (const QModelIndex &i : indexes) {
|
||||
if (i.isValid() && i.column() == 0) {
|
||||
QString date = data(i, Qt::DisplayRole).toString();
|
||||
double total = data(index(i.row(), i.column() + 1), Qt::DisplayRole).toDouble();
|
||||
stream << date << total;
|
||||
Check &c = checks->at(i.row());
|
||||
QString date = QString::fromStdString(c.get_date()),
|
||||
fn = QString::fromStdString(c.get_fn()),
|
||||
fd = QString::fromStdString(c.get_fd()),
|
||||
fi = QString::fromStdString(c.get_fi());
|
||||
double total = c.get_total();
|
||||
OperationType type = c.get_operationType();
|
||||
std::vector<Goods> goods = c.get_goods();
|
||||
|
||||
stream << date << total << type << fn << fd << fi << goods;
|
||||
}
|
||||
}
|
||||
mimeData->setData(CheckQueueTableModel::MimeType, encodedData);
|
||||
@@ -138,23 +145,40 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac
|
||||
int rows = 0;
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
QString date;
|
||||
QString date, fn, fd, fi;
|
||||
double total;
|
||||
stream >> date >> total;
|
||||
Check c;
|
||||
c.set_date(date.toStdString());
|
||||
c.set_total(total);
|
||||
OperationType type;
|
||||
std::vector<Goods> goods;
|
||||
|
||||
stream >> date >> total >> type >> fn >> fd >> fi >> goods;
|
||||
Check c = Check(
|
||||
date.toStdString(),
|
||||
total,
|
||||
type,
|
||||
fn.toStdString(),
|
||||
fd.toStdString(),
|
||||
fi.toStdString(),
|
||||
goods
|
||||
);
|
||||
newItems.push_back(c);
|
||||
++rows;
|
||||
}
|
||||
|
||||
insertRows(row, rows, QModelIndex());
|
||||
|
||||
for (Check &c : newItems) {
|
||||
QModelIndex date_index = index(row, 0, QModelIndex());
|
||||
QModelIndex total_index = index(row, 1, QModelIndex());
|
||||
setData(date_index, QVariant::fromValue(c.get_date()), Qt::EditRole);
|
||||
setData(total_index, QVariant::fromValue(c.get_total()), Qt::EditRole);
|
||||
for (Check item : newItems) {
|
||||
// (*checks)[row] = std::move(item);
|
||||
Check &c = checks->at(row);
|
||||
c.set_date(item.get_date());
|
||||
c.set_total(item.get_total());
|
||||
c.set_fn(item.get_fn());
|
||||
c.set_fd(item.get_fd());
|
||||
c.set_fi(item.get_fi());
|
||||
c.set_operation_type(item.get_operationType());
|
||||
for (Goods &g : item.get_goods()) {
|
||||
c.add_goods(g);
|
||||
}
|
||||
emit dataChanged(index(row, 0), index(row, 1));
|
||||
row++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user