full-featured moving and deleting from the queue completed
This commit is contained in:
@@ -8,7 +8,7 @@ CheckQueueTableModel::CheckQueueTableModel(std::vector<Check> *checks, QObject *
|
||||
{}
|
||||
|
||||
int CheckQueueTableModel::rowCount(const QModelIndex &parent) const { return checks->size(); }
|
||||
int CheckQueueTableModel::columnCount(const QModelIndex &parent) const { return 3; }
|
||||
int CheckQueueTableModel::columnCount(const QModelIndex &parent) const { return 2; }
|
||||
|
||||
QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid() || index.row() >= checks->size())
|
||||
@@ -22,9 +22,6 @@ QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const {
|
||||
case 1:
|
||||
return QVariant::fromValue(c.get_total());
|
||||
break;
|
||||
case 2:
|
||||
return QVariant::fromValue(QString("кнопка"));
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
@@ -32,7 +29,7 @@ QVariant CheckQueueTableModel::data(const QModelIndex &index, int role) const {
|
||||
|
||||
bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||
if (role == Qt::EditRole) {
|
||||
if (!checkIndex(index))
|
||||
if (!index.isValid() || index.row() >= checks->size())
|
||||
return false;
|
||||
unsigned int row = index.row();
|
||||
switch (index.column()) {
|
||||
@@ -42,9 +39,6 @@ bool CheckQueueTableModel::setData(const QModelIndex &index, const QVariant &val
|
||||
} case 1:
|
||||
checks->at(row).set_total(value.value<double>());
|
||||
break;
|
||||
case 2:
|
||||
// delete Button
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -60,10 +54,9 @@ QVariant CheckQueueTableModel::headerData(int section, Qt::Orientation orientati
|
||||
case 1:
|
||||
return tr("Total");
|
||||
break;
|
||||
case 2:
|
||||
return tr("Delete button");
|
||||
break;
|
||||
}
|
||||
} else if (role == Qt::DisplayRole && orientation == Qt::Vertical) {
|
||||
return section + 1;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
@@ -85,7 +78,6 @@ Qt::DropActions CheckQueueTableModel::supportedDropActions() const {
|
||||
|
||||
bool CheckQueueTableModel::insertRows(int position, int rows, const QModelIndex &index) {
|
||||
beginInsertRows(QModelIndex(), position, position+rows-1);
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
checks->emplace(checks->begin() + position, Check());
|
||||
|
||||
@@ -109,9 +101,10 @@ QStringList CheckQueueTableModel::mimeTypes() const {
|
||||
return types;
|
||||
}
|
||||
|
||||
bool CheckQueueTableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &) {
|
||||
bool CheckQueueTableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int, const QModelIndex &) {
|
||||
if (action != Qt::MoveAction || !data->hasFormat(CheckQueueTableModel::MimeType))
|
||||
return false;
|
||||
if (row > checks->size()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -133,12 +126,11 @@ QMimeData* CheckQueueTableModel::mimeData(const QModelIndexList &indexes) const
|
||||
}
|
||||
|
||||
bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) {
|
||||
if (!canDropMimeData(data, action, row, column, parent))
|
||||
return false;
|
||||
if (action == Qt::IgnoreAction)
|
||||
return true;
|
||||
else if (action != Qt::MoveAction)
|
||||
return false;
|
||||
if (!canDropMimeData(data, action, row, column, parent)) return false;
|
||||
if (action == Qt::IgnoreAction) return true;
|
||||
else if (action != Qt::MoveAction) return false;
|
||||
if (row > checks->size()) return false;
|
||||
|
||||
QByteArray encodedData = data->data(CheckQueueTableModel::MimeType);
|
||||
QDataStream stream(&encodedData, QIODevice::ReadOnly);
|
||||
std::vector<Check> newItems;
|
||||
@@ -156,6 +148,7 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac
|
||||
}
|
||||
|
||||
insertRows(row, rows, QModelIndex());
|
||||
|
||||
for (Check &c : newItems) {
|
||||
QModelIndex date_index = index(row, 0, QModelIndex());
|
||||
QModelIndex total_index = index(row, 1, QModelIndex());
|
||||
@@ -164,5 +157,6 @@ bool CheckQueueTableModel::dropMimeData(const QMimeData *data, Qt::DropAction ac
|
||||
row++;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user