23
Model::Model(const QStringList& watchedJids_, const QStringList& Sounds_, QObject* parent)
24
: QAbstractTableModel(parent)
25
, watchedJids(watchedJids_)
23
Model::Model(const QStringList& watchedJids_, const QStringList& Sounds_, const QStringList& enabledJids_, QObject* parent)
24
: QAbstractTableModel(parent)
25
, watchedJids(watchedJids_)
27
, enabledJids(enabledJids_)
29
30
<< tr("Watch for JIDs")
36
35
tmpWatchedJids_ = watchedJids;
37
36
tmpSounds_ = sounds;
38
foreach (QString enabledJid, enabledJids_) {
39
tmpEnabledJids_ << (enabledJid == "true" ? true : false);
40
43
QVariant Model::headerData ( int section, Qt::Orientation orientation, int role) const
42
45
if (role == Qt::DisplayRole) {
43
if (orientation == Qt::Horizontal) {
44
return headers.at(section);
46
if (orientation == Qt::Horizontal) {
47
return headers.at(section);
81
84
int i = index.column();
84
if (role == Qt::CheckStateRole) {
85
return selected.at(index.row()) ? 2:0;
86
} else if (role == Qt::TextAlignmentRole) {
87
return (int)(Qt::AlignRight | Qt::AlignVCenter);
88
} else if (role == Qt::DisplayRole)
91
if (role == Qt::TextAlignmentRole) {
92
return (int)(Qt::AlignRight | Qt::AlignVCenter);
93
} else if (role == Qt::DisplayRole)
87
if (role == Qt::CheckStateRole) {
88
return tmpEnabledJids_.at(index.row()) ? 2:0;
89
} else if (role == Qt::TextAlignmentRole) {
90
return (int)(Qt::AlignRight | Qt::AlignVCenter);
91
} else if (role == Qt::DisplayRole)
94
if (role == Qt::TextAlignmentRole) {
95
return (int)(Qt::AlignRight | Qt::AlignVCenter);
96
} else if (role == Qt::DisplayRole)
94
97
return QVariant(tmpWatchedJids_.at(index.row()));
96
if (role == Qt::TextAlignmentRole) {
97
return (int)(Qt::AlignRight | Qt::AlignVCenter);
98
} else if (role == Qt::DisplayRole)
99
return QVariant(tmpSounds_.at(index.row()));
101
if (role == Qt::TextAlignmentRole) {
102
return (int)(Qt::AlignRight | Qt::AlignVCenter);
103
} else if (role == Qt::DisplayRole)
106
if (role == Qt::TextAlignmentRole) {
107
return (int)(Qt::AlignRight | Qt::AlignVCenter);
108
} else if (role == Qt::DisplayRole)
99
if (role == Qt::TextAlignmentRole) {
100
return (int)(Qt::AlignRight | Qt::AlignVCenter);
101
} else if (role == Qt::DisplayRole)
102
return QVariant(tmpSounds_.at(index.row()));
104
if (role == Qt::TextAlignmentRole) {
105
return (int)(Qt::AlignRight | Qt::AlignVCenter);
106
} else if (role == Qt::DisplayRole)
109
if (role == Qt::TextAlignmentRole) {
110
return (int)(Qt::AlignRight | Qt::AlignVCenter);
111
} else if (role == Qt::DisplayRole)
111
114
return QVariant();
143
146
int column = index.column();
144
147
if(column == 0) {
145
bool b = selected.at( index.row() );
148
bool b = tmpEnabledJids_.at( index.row() );
146
149
switch(value.toInt()) {
148
selected.replace( index.row(), false);
151
selected.replace( index.row(), true);
154
selected.replace( index.row(), !b);
151
tmpEnabledJids_.replace( index.row(), false);
154
tmpEnabledJids_.replace( index.row(), true);
157
tmpEnabledJids_.replace( index.row(), !b);
171
174
statuses.insert(jid, status);
174
void Model::deleteSelected()
177
void Model::deleteRows(const QModelIndexList &indexList)
176
emit layoutAboutToBeChanged ();
179
QList<bool> selected;
180
for (int i = 0; i < tmpWatchedJids_.size(); i++) {
184
foreach (QModelIndex index, indexList) {
185
selected[index.row()] = true;
177
188
QStringList tmpJids, tmpSounds;
178
for(int i=0; i<watchedJids.size(); i++) {
179
if(!selected.at(i)) {
180
tmpJids.append(watchedJids.at(i));
181
tmpSounds.append(sounds.at(i));
189
QList<bool> tmpEnabledJids;
190
for (int i = tmpWatchedJids_.size() - 1; i >= 0; i--) {
185
tmpWatchedJids_.clear();
187
tmpWatchedJids_ = tmpJids;
188
tmpSounds_ = tmpSounds;
197
bool Model::removeRows(int row, int count, const QModelIndex &parent)
199
beginRemoveRows(parent, row, row + count - 1);
200
for (int i = 0; i < count; i++) {
201
tmpWatchedJids_.removeAt(row);
202
tmpSounds_.removeAt(row);
203
tmpEnabledJids_.removeAt(row);
193
209
void Model::reset()
195
211
tmpWatchedJids_ = watchedJids;
196
212
tmpSounds_ = sounds;
200
void Model::selectAll()
204
foreach(QString jid, tmpWatchedJids_) {
206
selected.append(true);
209
emit layoutChanged();
212
void Model::unselectAll()
216
foreach(QString jid, watchedJids) {
217
selected.append(false);
220
emit layoutChanged();
214
tmpEnabledJids_.clear();
215
foreach (QString enabledJid, enabledJids) {
216
tmpEnabledJids_ << (enabledJid == "true" ? true : false);
223
220
void Model::addRow(const QString& jid)
254
252
watchedJids = tmpWatchedJids_;
255
253
sounds = tmpSounds_;
255
foreach (bool enabledJid, tmpEnabledJids_) {
256
enabledJids << (enabledJid ? "true" : "false");
258
260
QString Model::statusByJid(const QString& jid) const
290
QStringList Model::getEnabledJids() const
295
void Model::setJidEnabled(const QString& jid, bool enabled)
297
// Do nothing if need to disable jid which is not in watcher list
298
if (!getWatchedJids().contains(jid, Qt::CaseInsensitive) && !enabled) {
302
// Before add Jid to watcher list
303
if (!getWatchedJids().contains(jid, Qt::CaseInsensitive)) {
307
QModelIndex ind = index(indexByJid(jid), 0);
308
setData(ind, enabled ? 2 : 0);
311
bool Model::jidEnabled(const QString& jid)
313
// watcher doesn't applied for this jid
314
if (!getWatchedJids().contains(jid, Qt::CaseInsensitive )) {
318
QModelIndex ind = index(indexByJid(jid), 0);
319
return (data(ind, Qt::CheckStateRole) == 2) ? true : false;