check queue WIP
This commit is contained in:
94
widgets/checkqueuetablemodel.cpp
Normal file
94
widgets/checkqueuetablemodel.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#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;
|
||||
}
|
||||
30
widgets/checkqueuetablemodel.h
Normal file
30
widgets/checkqueuetablemodel.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef CHECKQUEUETABLEMODEL_H
|
||||
#define CHECKQUEUETABLEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include <check/check.h>
|
||||
|
||||
class CheckQueueTableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CheckQueueTableModel(std::vector<Check> *checks, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
bool insertRow(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
private:
|
||||
std::vector<Check> *checks;
|
||||
signals:
|
||||
void editCompleted(const QString &);
|
||||
};
|
||||
|
||||
#endif // CHECKQUEUETABLEMODEL_H
|
||||
Reference in New Issue
Block a user