92
92
// fill listview with autoreplace definitions
93
void Autoreplace_Config::setAutoreplaceListView(const QStringList &autoreplaceList)
93
void Autoreplace_Config::setAutoreplaceListView(const QList<QStringList> &autoreplaceList)
96
96
patternListView->clear();
97
97
// go through the list
98
for(unsigned int index=autoreplaceList.count();index!=0;index--)
98
for (int index=0;index<autoreplaceList.count();index++)
100
100
// get autoreplace definition
101
QString definition=autoreplaceList[index-1];
101
QStringList definition=autoreplaceList[index];
102
102
// cut definition apart in name and action, and create a new listview item
103
103
QTreeWidgetItem* newItem=new QTreeWidgetItem(patternListView);
104
104
newItem->setFlags(newItem->flags() &~ Qt::ItemIsDropEnabled);
105
newItem->setCheckState(0, Qt::Checked);
105
newItem->setCheckState(0, Qt::Unchecked);
106
106
// Regular expression?
107
if(definition.section(',',0,0)=="1") newItem->setCheckState(0, Qt::Checked);
107
if (definition.at(0)=="1") newItem->setCheckState(0, Qt::Checked);
108
108
// direction input/output/both
109
if(definition.section(',',1,1)=="i") newItem->setText(1,directionCombo->itemText(DIRECTION_INPUT));
110
else if(definition.section(',',1,1)=="o") newItem->setText(1,directionCombo->itemText(DIRECTION_OUTPUT));
111
else if(definition.section(',',1,1)=="io") newItem->setText(1,directionCombo->itemText(DIRECTION_BOTH));
109
if (definition.at(1)=="i")
111
newItem->setText(1,directionCombo->itemText(DIRECTION_INPUT));
113
else if (definition.at(1)=="o")
115
newItem->setText(1,directionCombo->itemText(DIRECTION_OUTPUT));
117
else if (definition.at(1)=="io")
119
newItem->setText(1,directionCombo->itemText(DIRECTION_BOTH));
113
newItem->setText(2,definition.section(',',2,2));
122
newItem->setText(2,definition.at(2));
115
newItem->setText(3,definition.section(',',3));
124
newItem->setText(3,definition.at(3));
116
125
// hidden column, so we are independent of the i18n()ed display string
117
newItem->setText(4,definition.section(',',1,1));
126
newItem->setText(4,definition.at(1));
119
128
patternListView->setCurrentItem(patternListView->topLevelItem(0));
132
141
KConfigGroup grp = config->group("Autoreplace List");
134
143
// create empty list
135
QStringList newList=currentAutoreplaceList();
144
QList<QStringList> newList=currentAutoreplaceList();
137
146
// check if there are any patterns in the list view
138
147
if(newList.count())
140
149
// go through all patterns and save them into the configuration
150
QString regexString("Regex");
151
QString directString("Direction");
152
QString patternString("Pattern");
153
QString replaceString("Replace");
141
154
for(int index=0;index<newList.count();index++)
143
// write the current entry's pattern and replacement (adds a "#" to preserve blanks at the end of the line)
144
grp.writeEntry(QString("Autoreplace%1").arg(index),newList[index]+'#');
156
// write the current entry's pattern and replacement (adds a "#" to preserve blanks at the end of the line)
157
QString indexString(QString::number(index));
158
QStringList definition = newList[index];
159
grp.writeEntry(regexString + indexString,definition.at(0)); //regex status
160
grp.writeEntry(directString + indexString,definition.at(1)); //direction
161
grp.writeEntry(patternString + indexString,definition.at(2)+'#'); //pattern
162
grp.writeEntry(replaceString + indexString,definition.at(3)+'#'); //replace
147
166
// if there were no entries at all, write a dummy entry to prevent KConfigXT from "optimizing"
161
180
setAutoreplaceListView(Preferences::defaultAutoreplaceList());
164
QStringList Autoreplace_Config::currentAutoreplaceList()
183
QList<QStringList> Autoreplace_Config::currentAutoreplaceList()
166
185
// get first item of the autoreplace listview
167
186
QTreeWidgetItem* item=patternListView->topLevelItem(0);
168
187
// create empty list
188
QList<QStringList> newList;
171
190
// go through all items and save them into the configuration
175
if(static_cast<QTreeWidgetItem*>(item)->checkState(0) == Qt::Checked) checked="1";
194
if (static_cast<QTreeWidgetItem*>(item)->checkState(0) == Qt::Checked) regex="1";
177
196
// remember entry in internal list (col 4 is hidden for input/output)
178
newList.append(checked+','+item->text(4)+','+item->text(2)+','+item->text(3));
197
newList.append(QStringList() << regex << item->text(4) << item->text(2) << item->text(3));
179
198
// get next item in the listview
180
199
item=patternListView->itemBelow(item);
274
293
// rename pattern
275
item->setText(2,newPattern);
294
if (newPattern.length()>0)
296
item->setText(2,newPattern);
300
item->setText(2,QString("New"));
276
302
// tell the config system that something has changed
277
303
if(!m_newItemSelected) emit modified();