38 int row =
index.row();
49 if (pre[0] !=
"token" && pre[0] !=
"npctoken")
52 QStringList acceptable = pre;
53 acceptable.removeFirst();
54 acceptable.removeFirst();
68 if ((post[0] !=
"settoken" && post[0] !=
"setnpctoken") || post[1] != pre[1] || !acceptable.contains(post[2]))
84 if (post[0] !=
"settoken" && post[0] !=
"setnpctoken")
99 if ((pre[0] !=
"token" && pre[0] !=
"npctoken") || pre[1] != post[1])
102 QStringList acceptable = pre;
103 acceptable.removeFirst();
104 acceptable.removeFirst();
105 if (!acceptable.contains(post[2]))
119 emit dataChanged(createIndex(b, 0), createIndex(b, 6));
125 emit dataChanged(createIndex(r, 0), createIndex(r, 6));
130 for (
int old : red + blue)
132 emit dataChanged(createIndex(old, 0), createIndex(old, 6));
146 return QModelIndex();
147 return createIndex(row, column);
152 return QModelIndex();
163 static QString
toDisplay(
const QList<QStringList>& list)
166 foreach(QStringList item, list)
167 data.append(item.join(
" "));
168 return data.join(
"\n");
176 if (role == Qt::BackgroundColorRole)
179 return QVariant::fromValue(QBrush(Qt::blue));
181 return QVariant::fromValue(QBrush(Qt::red));
185 if (role != Qt::DisplayRole && role != Qt::EditRole)
191 switch(
index.column())
194 return role == Qt::DisplayRole ? QVariant::fromValue(rule->
match().join(
"\n")) : QVariant::fromValue(rule->
match());
198 return role == Qt::DisplayRole ? QVariant::fromValue(
toDisplay(rule->
replies())) : QVariant::fromValue(rule->
replies());
200 return role == Qt::DisplayRole ? QVariant::fromValue(rule->
messages().join(
"\n")) : QVariant::fromValue(rule->
messages());
204 return role == Qt::DisplayRole ? QVariant::fromValue(rule->
include().join(
"\n")) : QVariant::fromValue(rule->
include());
212 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
220 return tr(
"pre-conditions");
222 return tr(
"player suggested replies");
224 return tr(
"NPC messages");
226 return tr(
"post-conditions");
228 return tr(
"includes");
236 if (!
index.isValid())
238 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
245 if (role != Qt::EditRole)
250 switch (
index.column())
253 rule->
setMatch(value.value<QStringList>());
259 rule->
setReplies(value.value<QList<QStringList>>());
285 beginInsertRows(
parent, row, row + count - 1);
304 beginRemoveRows(
parent, row, row + count);
305 while (count > 0 && row < myMessage->rules().size())
321 const int shift = up ? -1 : 1;
329 emit dataChanged(createIndex(up ? row - 1 : row, 0), createIndex(up ? row : row + 1, 6));
338 beginInsertRows(QModelIndex(), row + 1, row + 1);