95 lines
2.8 KiB
C++
95 lines
2.8 KiB
C++
#include "checkqueuetablemodel.h"
|
|
|
|
#include <iostream>
|
|
|
|
CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *parent)
|
|
: checks(checks), QAbstractTableModel{parent}
|
|
{}
|
|
|
|
int CheckQueueTableModel::rowCount(const QModelIndex &parent) const { return checks->size(); }
|
|
int CheckQueueTableModel::columnCount(const QModelIndex &parent) const { return 3; }
|
|
|
|
QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const {
|
|
if (role != Qt::DisplayRole) return QVariant();
|
|
Check& c = (*checks).at(index.row());
|
|
switch (index.column()) {
|
|
case 0:
|
|
return QVariant::fromValue(QString::fromStdString(c.get_date()));
|
|
break;
|
|
case 1:
|
|
return QVariant::fromValue(c.get_total());
|
|
break;
|
|
case 2:
|
|
return QVariant::fromValue(QString("кнопка"));
|
|
break;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
|
if (role == Qt::EditRole) {
|
|
if (!checkIndex(index))
|
|
return false;
|
|
unsigned int row = index.row();
|
|
switch (index.column()) {
|
|
case 0:
|
|
checks->at(row).set_date(value.value<std::string>());
|
|
break;
|
|
case 1:
|
|
checks->at(row).set_total(value.value<double>());
|
|
break;
|
|
case 2:
|
|
// delete Button
|
|
break;
|
|
}
|
|
|
|
//for presentation purposes only: build and emit a joined string
|
|
// QString result = "dick";
|
|
// for (int row = 0; row < checks->size(); row++) {
|
|
// for (int col= 0; col < 3; col++)
|
|
// result += m_gridData[row][col] + ' ';
|
|
// }
|
|
// emit editCompleted(result);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
QVariant CheckQueueTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
|
switch (section) {
|
|
case 0:
|
|
return tr("Date&Time");
|
|
break;
|
|
case 1:
|
|
return tr("Total");
|
|
break;
|
|
case 2:
|
|
return tr("Delete button");
|
|
break;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
Qt::ItemFlags CheckQueueTableModel::flags(const QModelIndex &index) const {
|
|
Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);
|
|
|
|
if (index.isValid())
|
|
return Qt::ItemIsDragEnabled | defaultFlags;
|
|
else
|
|
return Qt::ItemIsDropEnabled | defaultFlags;
|
|
// return Qt::ItemIsSelectable | QAbstractTableModel::flags(index);
|
|
}
|
|
|
|
bool CheckQueueTableModel::insertRow(int row, int count, const QModelIndex &parent) {
|
|
beginInsertRows(QModelIndex(), row, row+count-1);
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
checks->emplace(checks->begin() + row, Check());
|
|
|
|
endInsertRows();
|
|
return true;
|
|
}
|