-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandteacheradd.cpp
92 lines (74 loc) · 2.84 KB
/
commandteacheradd.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "commandteacheradd.h"
#include "highlightitemdelegate.h"
#include "maintablewidget.h"
#include <QHeaderView>
#include <QtCore/QStringList>
CommandTeacherAdd::CommandTeacherAdd(QStringList *newTeachersNames, QStringList *hTableHeader, MainTableWidget *tableWidget, QObject*)
{
this->m_tableWidget = tableWidget;
this->teacherNames = new QStringList;
foreach(QString name, *newTeachersNames)
{
if(name.length() > 15) {
name.chop(name.length() - 15);
this->teacherNames->append(name);
} else if(name.length() < 1) {
teacherNames->removeOne(name);
} else {
this->teacherNames->append(name);
}
}
this->m_oldHTableHeader = new QStringList(*hTableHeader);
setText(QString("%1 teachers added.").arg(teacherNames->size()));
}
CommandTeacherAdd::~CommandTeacherAdd()
{
delete this->teacherNames;
delete this->m_oldHTableHeader;
}
void CommandTeacherAdd::undo()
{
for( int i=0; i < this->teacherNames->size(); i++ )
{
m_tableWidget->removeColumn( m_tableWidget->columnCount() - 1 );
this->m_tableWidget->HTableHeaderRemoveLast();
}
}
void CommandTeacherAdd::redo()
{
foreach( QString name, *teacherNames )
{
m_tableWidget->setColumnCount(m_tableWidget->columnCount() + 1);
m_tableWidget->setItemDelegateForColumn( m_tableWidget->columnCount()-1, \
new HighlightItemDelegate(m_tableWidget) );
QString formattedName;
foreach( const QChar c, name )
{
formattedName.append(c);
formattedName.append("\n");
}
m_tableWidget->HTableHeaderAppend(formattedName);
m_tableWidget->setItem( 0, m_tableWidget->columnCount() - 1, \
new QTableWidgetItem("wwwwwww") );
m_tableWidget->resizeColumnToContents(m_tableWidget->columnCount()-1);
//insert data
for (int row = 0; row < m_tableWidget->rowCount(); row++)
{
QTableWidgetItem *newItem = new QTableWidgetItem(QString(" \n \n "));
newItem->setTextAlignment(Qt::AlignCenter);
newItem->setData(Qt::UserRole, (QVariant)QString("1"));
newItem->setBackground(Qt::white);
//insert black column
if(row == 4)
{
newItem->setText(QString(" "));
newItem->setFlags(newItem->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsDropEnabled);
newItem->setData(Qt::UserRole, (QVariant)QString("0"));
newItem->setBackground(Qt::gray);
}
m_tableWidget->setItem(row, m_tableWidget->columnCount() - 1, newItem);
m_tableWidget->resizeRowToContents(row);
}
}
m_tableWidget->setHorizontalHeaderLabels(m_tableWidget->HTableHeader());
}