inputstrlist.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  */
14 
15 #include "inputstrlist.h"
16 #include "helplabel.h"
17 #include "doxywizard.h"
18 #include "config.h"
19 
20 #include <QToolBar>
21 #include <QGridLayout>
22 #include <QLineEdit>
23 #include <QListWidget>
24 #include <QFileInfo>
25 #include <QFileDialog>
26 #include <QTextStream>
27 #include <QTextCodec>
28 
29 InputStrList::InputStrList( QGridLayout *layout,int &row,
30  const QString & id,
31  const QStringList &sl, ListMode lm,
32  const QString & docs)
33  : m_default(sl), m_strList(sl), m_docs(docs), m_id(id)
34 {
35  m_lab = new HelpLabel( id );
36 
37  m_le = new QLineEdit;
38  m_le->clear();
39 
40  QToolBar *toolBar = new QToolBar;
41  toolBar->setIconSize(QSize(24,24));
42  m_add = toolBar->addAction(QIcon(QString::fromLatin1(":/images/add.png")),QString(),
43  this,SLOT(addString()));
44  m_add->setToolTip(tr("Add item"));
45  m_del = toolBar->addAction(QIcon(QString::fromLatin1(":/images/del.png")),QString(),
46  this,SLOT(delString()));
47  m_del->setToolTip(tr("Delete selected item"));
48  m_upd = toolBar->addAction(QIcon(QString::fromLatin1(":/images/refresh.png")),QString(),
49  this,SLOT(updateString()));
50  m_upd->setToolTip(tr("Update selected item"));
51 
52  m_lb = new QListWidget;
53  //m_lb->setMinimumSize(400,100);
54  foreach (QString s, m_strList) m_lb->addItem(s);
55 
56  m_brFile=0;
57  m_brDir=0;
58  if (lm!=ListString)
59  {
60  if (lm&ListFile)
61  {
62  m_brFile = toolBar->addAction(QIcon(QString::fromLatin1(":/images/file.png")),QString(),
63  this,SLOT(browseFiles()));
64  m_brFile->setToolTip(tr("Browse to a file"));
65  }
66  if (lm&ListDir)
67  {
68  m_brDir = toolBar->addAction(QIcon(QString::fromLatin1(":/images/folder.png")),QString(),
69  this,SLOT(browseDir()));
70  m_brDir->setToolTip(tr("Browse to a folder"));
71  }
72  }
73  QHBoxLayout *rowLayout = new QHBoxLayout;
74  rowLayout->addWidget( m_le );
75  rowLayout->addWidget( toolBar );
76  layout->addWidget( m_lab, row,0 );
77  layout->addLayout( rowLayout, row,1,1,2 );
78  layout->addWidget( m_lb, row+1,1,1,2 );
79  row+=2;
80 
82 
83  connect(m_le, SIGNAL(returnPressed()),
84  this, SLOT(addString()) );
85  connect(m_lb, SIGNAL(currentTextChanged(const QString &)),
86  this, SLOT(selectText(const QString &)));
87  connect( m_lab, SIGNAL(enter()), SLOT(help()) );
88  connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
89 }
90 
92 {
93  showHelp(this);
94 }
95 
96 
98 {
99  if (!m_le->text().isEmpty())
100  {
101  m_lb->addItem(m_le->text());
102  m_strList.append(m_le->text());
103  m_value = m_strList;
104  updateDefault();
105  emit changed();
106  m_le->clear();
107  }
108 }
109 
111 {
112  if (m_lb->currentRow()!=-1)
113  {
114  int itemIndex = m_lb->currentRow();
115  delete m_lb->currentItem();
116  m_strList.removeAt(itemIndex);
117  m_value = m_strList;
118  updateDefault();
119  emit changed();
120  }
121 }
122 
124 {
125  if (m_lb->currentRow()!=-1 && !m_le->text().isEmpty())
126  {
127  m_lb->currentItem()->setText(m_le->text());
128  m_strList.insert(m_lb->currentRow(),m_le->text());
129  m_strList.removeAt(m_lb->currentRow()+1);
130  m_value = m_strList;
131  updateDefault();
132  emit changed();
133  }
134 }
135 
137 {
138  m_le->setText(s);
139 }
140 
141 void InputStrList::setEnabled(bool state)
142 {
143  m_lab->setEnabled(state);
144  m_le->setEnabled(state);
145  m_add->setEnabled(state);
146  m_del->setEnabled(state);
147  m_upd->setEnabled(state);
148  m_lb->setEnabled(state);
149  if (m_brFile) m_brFile->setEnabled(state);
150  if (m_brDir) m_brDir->setEnabled(state);
151  updateDefault();
152 }
153 
155 {
156  QString path = QFileInfo(MainWindow::instance().configFileName()).path();
157  QStringList fileNames = QFileDialog::getOpenFileNames();
158 
159  if (!fileNames.isEmpty())
160  {
162  for ( it= fileNames.begin(); it != fileNames.end(); ++it )
163  {
165  QDir dir(path);
166  if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
167  {
168  fileName = dir.relativeFilePath(*it);
169  }
170  if (fileName.isEmpty())
171  {
172  fileName = *it;
173  }
174  m_lb->addItem(fileName);
175  m_strList.append(fileName);
176  m_value = m_strList;
177  updateDefault();
178  emit changed();
179  }
180  m_le->setText(m_strList[0]);
181  }
182 }
183 
185 {
186  QString path = QFileInfo(MainWindow::instance().configFileName()).path();
187  QString dirName = QFileDialog::getExistingDirectory();
188 
189  if (!dirName.isNull())
190  {
191  QDir dir(path);
192  if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
193  {
194  dirName = dir.relativeFilePath(dirName);
195  }
196  if (dirName.isEmpty())
197  {
198  dirName=QString::fromLatin1(".");
199  }
200  m_lb->addItem(dirName);
201  m_strList.append(dirName);
202  m_value = m_strList;
203  updateDefault();
204  emit changed();
205  m_le->setText(dirName);
206  }
207 }
208 
210 {
211  m_le->clear();
212  m_lb->clear();
213  m_strList = sl;
214  for (int i=0;i<m_strList.size();i++)
215  {
216  m_lb->addItem(m_strList[i].trimmed());
217  }
218  updateDefault();
219 }
220 
222 {
223  return m_value;
224 }
225 
227 {
228  setValue(m_value.toStringList());
229 }
230 
232 {
233  if (m_strList==m_default || !m_lab->isEnabled())
234  {
235  m_lab->setText(QString::fromLatin1("<qt>")+m_id+QString::fromLatin1("</qt"));
236  }
237  else
238  {
239  m_lab->setText(QString::fromLatin1("<qt><font color='red'>")+m_id+QString::fromLatin1("</font></qt>"));
240  }
241 }
242 
244 {
246 }
247 
249 {
250  bool first=true;
251  foreach (QString s, m_strList)
252  {
253  if (!first)
254  {
255  t << " \\" << endl;
256  t << " ";
257  }
258  first=false;
259  writeStringValue(t,codec,s);
260  }
261 }
262 
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
bool isEmpty() const
Definition: qstring.h:682
Iterator append(const T &x)
Definition: qvaluelist.h:372
Iterator insert(Iterator it, const T &x)
Definition: qvaluelist.h:370
void changed()
void writeValue(QTextStream &t, QTextCodec *codec)
Iterator end()
Definition: qvaluelist.h:363
void setValue(const QStringList &sl)
QLabel * m_lab
Definition: inputstrlist.h:77
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QAction * m_add
Definition: inputstrlist.h:79
string dir
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
def connect(nxgraph, k1, k2, p1=0, p2=0, kwds)
Definition: graph.py:30
void browseFiles()
void addString()
fileName
Definition: dumpTree.py:9
QLineEdit * m_le
Definition: inputstrlist.h:78
QAction * m_brFile
Definition: inputstrlist.h:82
A list of strings.
Definition: qstringlist.h:51
QVariant m_value
Definition: inputstrlist.h:87
QStringList m_strList
Definition: inputstrlist.h:86
void updateDefault()
void showHelp(Input *)
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
Definition: qtextstream.h:53
QAction * m_brDir
Definition: inputstrlist.h:83
void setEnabled(bool)
QVariant & value()
QStringList m_default
Definition: inputstrlist.h:85
QString m_id
Definition: inputstrlist.h:89
void writeStringValue(QTextStream &t, QTextCodec *codec, const QString &s)
QAction * m_upd
Definition: inputstrlist.h:81
Iterator begin()
Definition: qvaluelist.h:361
bool isNull() const
Definition: qstring.h:379
void selectText(const QString &s)
bool isEmpty() const
Definition: qvaluelist.h:368
QListWidget * m_lb
Definition: inputstrlist.h:84
QAction * m_del
Definition: inputstrlist.h:80
Provides conversion between text encodings.
Definition: qtextcodec.h:62
void updateString()
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
static MainWindow & instance()
Definition: doxywizard.cpp:34
static QCString * s
Definition: config.cpp:1042
virtual bool exists() const
Definition: qdir.cpp:820
QTextStream & endl(QTextStream &s)
InputStrList(QGridLayout *layout, int &row, const QString &id, const QStringList &sl, ListMode v, const QString &docs)