3
3
* Copyright (C) 1997-2019 by Dimitri van Heesch.
4
4
*
5
5
* Permission to use, copy, modify, and distribute this software and its
6
- * documentation under the terms of the GNU General Public License is hereby
7
- * granted. No representations are made about the suitability of this software
6
+ * documentation under the terms of the GNU General Public License is hereby
7
+ * granted. No representations are made about the suitability of this software
8
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
9
* See the GNU General Public License for more details.
10
10
*
25
25
#include < QTextCodec>
26
26
27
27
InputStrList::InputStrList ( QGridLayout *layout,int &row,
28
- const QString & id,
28
+ const QString & id,
29
29
const QStringList &sl, ListMode lm,
30
30
const QString & docs)
31
31
: m_default(sl), m_strList(sl), m_docs(docs), m_id(id)
@@ -50,7 +50,7 @@ InputStrList::InputStrList( QGridLayout *layout,int &row,
50
50
m_lb = new QListWidget;
51
51
// m_lb->setMinimumSize(400,100);
52
52
foreach (QString s, m_strList) m_lb->addItem (s);
53
-
53
+
54
54
m_brFile=0 ;
55
55
m_brDir=0 ;
56
56
if (lm!=ListString)
@@ -60,7 +60,7 @@ InputStrList::InputStrList( QGridLayout *layout,int &row,
60
60
m_brFile = toolBar->addAction (QIcon (QString::fromLatin1 (" :/images/file.png" )),QString (),
61
61
this ,SLOT (browseFiles ()));
62
62
m_brFile->setToolTip (tr (" Browse to a file" ));
63
- }
63
+ }
64
64
if (lm&ListDir)
65
65
{
66
66
m_brDir = toolBar->addAction (QIcon (QString::fromLatin1 (" :/images/folder.png" )),QString (),
@@ -78,9 +78,9 @@ InputStrList::InputStrList( QGridLayout *layout,int &row,
78
78
79
79
m_value = m_strList;
80
80
81
- connect (m_le, SIGNAL (returnPressed ()),
81
+ connect (m_le, SIGNAL (returnPressed ()),
82
82
this , SLOT (addString ()) );
83
- connect (m_lb, SIGNAL (currentTextChanged (const QString &)),
83
+ connect (m_lb, SIGNAL (currentTextChanged (const QString &)),
84
84
this , SLOT (selectText (const QString &)));
85
85
connect ( m_lab, SIGNAL (enter ()), SLOT (help ()) );
86
86
connect ( m_lab, SIGNAL (reset ()), SLOT (reset ()) );
@@ -154,7 +154,7 @@ void InputStrList::browseFiles()
154
154
QString path = QFileInfo (MainWindow::instance ().configFileName ()).path ();
155
155
QStringList fileNames = QFileDialog::getOpenFileNames ();
156
156
157
- if (!fileNames.isEmpty ())
157
+ if (!fileNames.isEmpty ())
158
158
{
159
159
QStringList::Iterator it;
160
160
for ( it= fileNames.begin (); it != fileNames.end (); ++it )
@@ -184,7 +184,7 @@ void InputStrList::browseDir()
184
184
QString path = QFileInfo (MainWindow::instance ().configFileName ()).path ();
185
185
QString dirName = QFileDialog::getExistingDirectory ();
186
186
187
- if (!dirName.isNull ())
187
+ if (!dirName.isNull ())
188
188
{
189
189
QDir dir (path);
190
190
if (!MainWindow::instance ().configFileName ().isEmpty () && dir.exists ())
@@ -228,7 +228,7 @@ void InputStrList::update()
228
228
229
229
void InputStrList::updateDefault ()
230
230
{
231
- if (m_strList==m_default || !m_lab->isEnabled ())
231
+ if (isDefault () || !m_lab->isEnabled ())
232
232
{
233
233
m_lab->setText (QString::fromLatin1 (" <qt>" )+m_id+QString::fromLatin1 (" </qt" ));
234
234
}
@@ -246,9 +246,9 @@ void InputStrList::reset()
246
246
void InputStrList::writeValue (QTextStream &t,QTextCodec *codec)
247
247
{
248
248
bool first=true ;
249
- foreach (QString s, m_strList)
249
+ foreach (QString s, m_strList)
250
250
{
251
- if (!first)
251
+ if (!first)
252
252
{
253
253
t << " \\ " << endl;
254
254
t << " " ;
@@ -258,9 +258,48 @@ void InputStrList::writeValue(QTextStream &t,QTextCodec *codec)
258
258
}
259
259
}
260
260
261
+ #include < QMessageBox>
261
262
bool InputStrList::isDefault ()
262
263
{
263
- return m_strList==m_default;
264
+ bool isEq = m_strList==m_default;
265
+
266
+ if (!isEq)
267
+ {
268
+ isEq = true ;
269
+
270
+ auto it1 = m_strList.begin ();
271
+ auto it2 = m_default.begin ();
272
+ while (it1!=m_strList.end () && it2!=m_default.end ())
273
+ {
274
+ // skip over empty values
275
+ while (it1!=m_strList.end () && (*it1).isEmpty ())
276
+ {
277
+ ++it1;
278
+ }
279
+ while (it2!=m_default.end () && (*it2).isEmpty ())
280
+ {
281
+ ++it2;
282
+ }
283
+ if ((it1!=m_strList.end ()) && (it2!=m_default.end ()))
284
+ {
285
+ if ((*it1).trimmed ()!= (*it2).trimmed ()) // difference so not the default
286
+ {
287
+ isEq=false ;
288
+ break ;
289
+ }
290
+ ++it1;
291
+ ++it2;
292
+ }
293
+ else if ((it1!=m_strList.end ()) || (it2!=m_default.end ()))
294
+ {
295
+ // one list empty so cannot be the default
296
+ isEq=false ;
297
+ break ;
298
+ }
299
+ }
300
+ }
301
+
302
+ return isEq;
264
303
}
265
304
266
305
bool InputStrList::isEmpty ()
0 commit comments