full-featured moving and deleting from the queue completed
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
#include "checklistviewwidget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <check/check.h>
|
||||
#include <iostream>
|
||||
|
||||
CheckListViewWidget::CheckListViewWidget(QWidget *parent, Check check) : QWidget(parent), check(check) {
|
||||
mw = (MainWindow*) parent;
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
|
||||
QLabel *date_label = new QLabel(QString::fromStdString(check.get_date()));
|
||||
QLabel *summ_label = new QLabel(QString::number(check.get_total()));
|
||||
|
||||
QPushButton *deleteButton = new QPushButton(tr("Delete"));
|
||||
|
||||
deleteButton->connect(deleteButton, &QPushButton::clicked, this, &CheckListViewWidget::delete_button_pressed);
|
||||
|
||||
layout->addWidget(date_label);
|
||||
layout->addWidget(summ_label);
|
||||
layout->addSpacing(10);
|
||||
layout->addWidget(deleteButton);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
Check &CheckListViewWidget::get_check(){
|
||||
return check;
|
||||
}
|
||||
|
||||
void CheckListViewWidget::delete_button_pressed() {
|
||||
emit mw->deleteCheckFromList(this->check);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef CHECKLISTVIEWWIDGET_H
|
||||
#define CHECKLISTVIEWWIDGET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <mainwindow.h>
|
||||
|
||||
#include <check/check.h>
|
||||
|
||||
class CheckListViewWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Check check;
|
||||
MainWindow* mw;
|
||||
public:
|
||||
explicit CheckListViewWidget(QWidget *parent = nullptr, Check check = Check());
|
||||
|
||||
Check &get_check();
|
||||
void delete_button_pressed();
|
||||
signals:
|
||||
Check deleteButtonPressed();
|
||||
};
|
||||
|
||||
#endif // CHECKLISTVIEWWIDGET_H
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -132,8 +132,7 @@ bool OutputColumnModel::dropMimeData(const QMimeData *data, Qt::DropAction actio
|
||||
}
|
||||
|
||||
insertRows(row, rows, QModelIndex());
|
||||
for (const OutputColumn &column : newItems)
|
||||
{
|
||||
for (const OutputColumn &column : newItems) {
|
||||
QModelIndex idx = index(row, 0, QModelIndex());
|
||||
setData(idx, QVariant::fromValue(column), 0x102);
|
||||
row++;
|
||||
@@ -141,4 +140,3 @@ bool OutputColumnModel::dropMimeData(const QMimeData *data, Qt::DropAction actio
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ public:
|
||||
|
||||
// QStringList mimeTypes() const override;
|
||||
bool canDropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex&);
|
||||
QMimeData* mimeData(const QModelIndexList &indexes) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
QMimeData* mimeData(const QModelIndexList &indexes) const override;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||
};
|
||||
|
||||
#endif // OUTPUTCOLUMNMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user