-
Notifications
You must be signed in to change notification settings - Fork 11
/
ExportDialog.cpp
177 lines (144 loc) · 4.24 KB
/
ExportDialog.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
Copyright 2010 Warzone 2100 Project
This file is part of WMIT.
WMIT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
WMIT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with WMIT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ExportDialog.h"
#include "ui_ExportDialog.h"
ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ExportDialog)
{
ui->setupUi(this);
}
ExportDialog::~ExportDialog()
{
delete ui;
}
void ExportDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
PieExportDialog::PieExportDialog(const PieCaps &caps, QWidget* parent)
: ExportDialog(parent), m_caps(caps)
{
ui->gbExportCaps->setTitle(tr("Directives"));
ui->lblCapsDescription->setText(tr("Please select directives to allow during model export. "
"Note that you do not have to deselect directives that are not present in current model. "
"E.g. normal map will not be exported unless it was assigned and is allowed."));
model = new PieContentModel(m_caps, ui->tvExportCaps);
ui->tvExportCaps->setModel(model);
ui->tvExportCaps->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tvExportCaps->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
connect(ui->pushButton_deselect_all, SIGNAL(clicked()), this, SLOT(actionDeselectAll()));
connect(ui->pushButton_select_all, SIGNAL(clicked()), this, SLOT(actionSelectAll()));
}
void PieExportDialog::changeSelectAll(bool selected)
{
if (!model) { return; }
int rowCount = model->rowCount();
for (int row = 0; row < rowCount; ++row)
{
model->setData(model->index(row, 1), selected, Qt::CheckStateRole);
}
}
void PieExportDialog::actionDeselectAll()
{
changeSelectAll(false);
}
void PieExportDialog::actionSelectAll()
{
changeSelectAll(true);
}
PieContentModel::PieContentModel(PieCaps &caps, QObject *parent): QAbstractTableModel(parent),
m_caps(caps)
{
}
int PieContentModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_caps.size();
}
int PieContentModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant PieContentModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || (index.row() < 0))
return QVariant();
if (role == Qt::DisplayRole)
{
int row = index.row();
if (index.column() == 0)
return getPieDirectiveName(static_cast<PIE_OPT_DIRECTIVES>(row));
else if (index.column() == 2)
return getPieDirectiveDescription(static_cast<PIE_OPT_DIRECTIVES>(row));
}
else if (role == Qt::CheckStateRole)
{
int row = index.row();
if (index.column() == 1)
return m_caps.test(static_cast<PIE_OPT_DIRECTIVES>(row)) ? Qt::Checked : Qt::Unchecked;
}
return QVariant();
}
bool PieContentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid())
{
if (role == Qt::CheckStateRole)
{
int row = index.row();
if (index.column() == 1)
m_caps.set(static_cast<PIE_OPT_DIRECTIVES>(row), value.toBool());
else
return false;
emit dataChanged(index, index, {role});
return true;
}
}
return false;
}
Qt::ItemFlags PieContentModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return QAbstractTableModel::flags(index) | (index.column() == 1 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags);
}
QVariant PieContentModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
{
switch (section) {
case 0:
return tr("Directive");
case 1:
return tr("Allowed");
case 2:
return tr("Description");
default:
return QVariant();
}
}
return QVariant();
}