-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandclasspaste.cpp
65 lines (53 loc) · 2.5 KB
/
commandclasspaste.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "commandclasspaste.h"
#include "maintablewidget.h"
#include "maintableoptions.h"
#include <QTableWidgetItem>
CommandClassPaste::CommandClassPaste(int currentRow, int currentColumn, \
MainTableWidget *tableWidget, QObject*)
{
this->m_tableWidget = tableWidget;
this->m_fromClass = new QTableWidgetItem( *tableWidget->item(currentRow, currentColumn) );
QStringList oldData = tableWidget->getCopiedItem()->data(Qt::UserRole).toStringList();
int section = oldData.at(MainTableOptions::ClassSection).toInt();
section += tableWidget->getCopiedItemNumber();
oldData.replace(MainTableOptions::ClassSection, QString("%1").arg(section));
QVariant *newData = new QVariant((QVariant)oldData);
QString gradeString = tableWidget->getCopiedItem()->text().split("\n"). \
at(MainTableOptions::ClassGrade);
this->m_toClass = new QTableWidgetItem( *tableWidget->getCopiedItem() );
m_toClass->setData(Qt::UserRole, *newData);
if(oldData.at(MainTableOptions::ClassNotes) == "")
{
m_toClass->setText( QString("%1\n%2\n00%3").arg(oldData.at(MainTableOptions::ClassName)). \
arg(gradeString). \
arg(oldData.at(MainTableOptions::ClassSection)) );
} else {
m_toClass->setText( QString("%1\n%2\n** 00%3 **").arg(oldData.at(MainTableOptions::ClassName)). \
arg(gradeString). \
arg(oldData.at(MainTableOptions::ClassSection)) );
}
this->toRow = currentRow;
this->toCol = currentColumn;
setText(QString("Class pasted at %1, %2").arg(currentRow).arg(currentColumn));
}
CommandClassPaste::~CommandClassPaste()
{
delete this->m_toClass;
delete this->m_fromClass;
}
void CommandClassPaste::undo()
{
this->m_tableWidget->decreaseCopiedItemNumber();
this->m_tableWidget->setItem( this->toRow, \
this->toCol, \
new QTableWidgetItem(*this->m_fromClass) );
m_tableWidget->setCurrentCell(toRow, toCol);
}
void CommandClassPaste::redo()
{
this->m_tableWidget->increaseCopiedItemNumber();
this->m_tableWidget->setItem( this->toRow, \
this->toCol, \
new QTableWidgetItem(*this->m_toClass) );
m_tableWidget->setCurrentCell(toRow, toCol);
}