~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/VISUAL/ParamEditor.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
//
23
 
// --------------------------------------------------------------------------
24
 
// $Maintainer: Timo Sachsenberg$
25
 
// $Authors: Marc Sturm $
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
//
 
30
// --------------------------------------------------------------------------
 
31
// $Maintainer: Timo Sachsenberg $
 
32
// $Authors: Marc Sturm, Chris Bielow $
26
33
// --------------------------------------------------------------------------
27
34
 
28
35
#include <OpenMS/VISUAL/ParamEditor.h>
39
46
#include <QtCore/QStringList>
40
47
#include <QtGui/QLabel>
41
48
#include <QtGui/QFileDialog>
42
 
 
 
49
 
43
50
#include <stack>
44
51
#include <limits>
45
52
#include <sstream>
51
58
Description of the data stored in the items:
52
59
 
53
60
            | Column 0  | Column 1    | Column 2 | Column 3         |
54
 
---------------------------------------------------------------------  
 
61
---------------------------------------------------------------------
55
62
DisplayRole | name      | value       | type     | restr. (display) |
56
63
UserRole    | NODE/ITEM | description | restr.   |                  |
57
64
 
60
67
 
61
68
namespace OpenMS
62
69
{
63
 
        namespace Internal
64
 
        {
65
 
                ParamEditorDelegate::ParamEditorDelegate(QObject* parent)
66
 
                        : QItemDelegate(parent)
67
 
                {
68
 
                }
69
 
                
70
 
                QWidget *ParamEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& , const QModelIndex& index) const
71
 
                {
72
 
                        Int type = index.sibling(index.row(),0).data(Qt::UserRole).toInt();
 
70
  namespace Internal
 
71
  {
 
72
    void OpenMSLineEdit::focusInEvent ( QFocusEvent * e )
 
73
    {
 
74
      //std::cerr << "got focus";
 
75
    }
 
76
 
 
77
    void OpenMSLineEdit::focusOutEvent ( QFocusEvent * e )
 
78
    {
 
79
      //std::cerr << "lost focus";
 
80
      emit lostFocus();
 
81
    }
 
82
 
 
83
    ParamEditorDelegate::ParamEditorDelegate(QObject * parent) :
 
84
      QItemDelegate(parent)
 
85
    {
 
86
    }
 
87
 
 
88
    QWidget * ParamEditorDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem &, const QModelIndex & index) const
 
89
    {
 
90
      Int type = index.sibling(index.row(), 0).data(Qt::UserRole).toInt();
73
91
 
74
92
      // only create editor for first column (value column)
75
 
                        if(index.column()==1 && type!=ParamEditor::NODE)
76
 
                        {
77
 
                                QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
78
 
                                QString restrictions = index.sibling(index.row(),2).data(Qt::UserRole).toString();
79
 
                                QString value = index.sibling(index.row(),1).data(Qt::DisplayRole).toString();
80
 
                                if (dtype=="string" && restrictions!="") //Drop-down list for enums
81
 
                                {
82
 
                                        QComboBox* editor = new QComboBox(parent);
83
 
                                        QStringList list;
84
 
                                        list.append("");
85
 
                                        list += restrictions.split(",");
86
 
                                        editor->addItems(list);
87
 
                                        connect(editor,SIGNAL(activated(int)),this, SLOT(commitAndCloseComboBox_()));
88
 
                                        return editor;
89
 
                                }
90
 
                                else if(dtype == "output file")
91
 
                                {
92
 
                                        QLineEdit* editor = new QLineEdit(parent);
93
 
                                        QString dir="";// = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
 
93
      if (index.column() == 1 && type != ParamEditor::NODE)
 
94
      {
 
95
        has_uncommited_data_ = false; // by default all data is committed
 
96
 
 
97
        QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
 
98
        QString restrictions = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
 
99
        QString value = index.sibling(index.row(), 1).data(Qt::DisplayRole).toString();
 
100
        if (dtype == "string" && restrictions != "")     //Drop-down list for enums
 
101
        {
 
102
          QComboBox * editor = new QComboBox(parent);
 
103
          QStringList list;
 
104
          list.append("");
 
105
          list += restrictions.split(",");
 
106
          editor->addItems(list);
 
107
          connect(editor, SIGNAL(activated(int)), this, SLOT(commitAndCloseComboBox_()));
 
108
          return editor;
 
109
        }
 
110
        else if (dtype == "output file")
 
111
        {
 
112
          QLineEdit * editor = new QLineEdit(parent);
 
113
          QString dir = "";        // = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
94
114
          if (File::isDirectory(value) || File::writable(value))
95
115
          {
96
116
            dir = File::absolutePath(value).toQString();
97
117
          }
98
 
                                        fileName_ = QFileDialog::getSaveFileName(editor,tr("Output File"),dir);
99
 
                                        return editor;
100
 
                                }
101
 
                                else if(dtype == "input file")
102
 
                                {
103
 
                                        QLineEdit* editor = new QLineEdit(parent);
104
 
                                        QString dir="";// = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
 
118
          fileName_ = QFileDialog::getSaveFileName(editor, tr("Output File"), dir);
 
119
          return editor;
 
120
        }
 
121
        else if (dtype == "input file")
 
122
        {
 
123
          QLineEdit * editor = new QLineEdit(parent);
 
124
          QString dir = "";        // = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
105
125
          if (File::isDirectory(value) || File::exists(value))
106
126
          {
107
127
            dir = File::absolutePath(value).toQString();
108
128
          }
109
 
                                        fileName_ = QFileDialog::getOpenFileName(editor,tr("Input File"),dir);
110
 
                                        return editor;
111
 
                                }
112
 
                                else if(dtype =="string list" || dtype =="int list" || dtype=="double list" || dtype =="input file list" || dtype =="output file list" ) // for lists
113
 
                                {
114
 
                                        QString str = "<"+ index.sibling(index.row(),0).data(Qt::DisplayRole).toString() + "> " +"(<" + dtype + ">)";
115
 
                                        ListEditor *editor = new ListEditor(0,str);
116
 
                                        editor->setTypeName(index.sibling(index.row(),0).data(Qt::DisplayRole).toString());
117
 
                                        editor->setModal(true);
118
 
                                        connect(editor,SIGNAL(accepted()),this, SLOT(commitAndCloseListEditor_()));
119
 
                                        connect(editor,SIGNAL(rejected()),this, SLOT(closeListEditor_()));
120
 
                                        return editor;
121
 
                                }                                               
122
 
                                else //LineEditor for rest
123
 
                                {
124
 
                                        QLineEdit *editor = new QLineEdit(parent);
125
 
                                        editor->setFocusPolicy(Qt::StrongFocus);
126
 
                                        return editor;
127
 
                                }
128
 
                        }
129
 
                        return 0;
130
 
                }
131
 
                
132
 
                void ParamEditorDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
133
 
                {
134
 
                        QString str = index.data(Qt::DisplayRole).toString();
 
129
          fileName_ = QFileDialog::getOpenFileName(editor, tr("Input File"), dir);
 
130
          return editor;
 
131
        }
 
132
        else if (dtype == "string list" || dtype == "int list" || dtype == "double list" || dtype == "input file list" || dtype == "output file list")   // for lists
 
133
        {
 
134
          QString str = "<" + index.sibling(index.row(), 0).data(Qt::DisplayRole).toString() + "> " + "(<" + dtype + ">)";
 
135
          ListEditor * editor = new ListEditor(0, str);
 
136
          editor->setTypeName(index.sibling(index.row(), 0).data(Qt::DisplayRole).toString());
 
137
          editor->setModal(true);
 
138
          connect(editor, SIGNAL(accepted()), this, SLOT(commitAndCloseListEditor_()));
 
139
          connect(editor, SIGNAL(rejected()), this, SLOT(closeListEditor_()));
 
140
          return editor;
 
141
        }
 
142
        else         //LineEditor for rest
 
143
        {
 
144
          OpenMSLineEdit * editor = new OpenMSLineEdit(parent);
 
145
          editor->setFocusPolicy(Qt::StrongFocus);
 
146
          connect(editor, SIGNAL(lostFocus()), this, SLOT(commitAndCloseLineEdit_()));
 
147
          //std::cerr << "created ... \n";
 
148
          has_uncommited_data_ = true;
 
149
          return editor;
 
150
        }
 
151
      }
 
152
      return 0;
 
153
    }
 
154
 
 
155
    void ParamEditorDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
 
156
    {
 
157
      QString str = index.data(Qt::DisplayRole).toString();
135
158
 
136
159
      // only set editor data for first column (value column)
137
 
                        if(index.column()==1)
138
 
                        {
139
 
                                if(qobject_cast<QComboBox*>(editor)) //Drop-down list for enums
140
 
                                {
141
 
                                        int index = static_cast<QComboBox*>(editor)->findText(str);
142
 
                                        if (index==-1)
143
 
                                        {
144
 
                                                index = 0;
145
 
                                        }
146
 
                                        static_cast<QComboBox*>(editor)->setCurrentIndex(index);
147
 
                                }
148
 
                                else if(qobject_cast<QLineEdit*>(editor))// LineEdit for other values
149
 
                                {
150
 
                                        QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
151
 
                                        if(dtype == "output file" || dtype == "input file") /// for output/input file
152
 
                                        {
153
 
                                                if(!fileName_.isNull())
154
 
                                                {
155
 
                                                        static_cast<QLineEdit*>(editor)->setText(fileName_);
156
 
                                                }
157
 
                                        }
158
 
                                        else
159
 
                                        {
160
 
                                                if(str == "" && (dtype == "int" || dtype == "float"))
161
 
                                                {
162
 
              if (dtype == "int") static_cast<QLineEdit*>(editor)->setText("0");
163
 
              else if (dtype == "float") static_cast<QLineEdit*>(editor)->setText("nan");
164
 
                                                }
165
 
                                                else
166
 
                                                {
167
 
                                                        static_cast<QLineEdit*>(editor)->setText(str);
168
 
                                                }
169
 
                                        }
170
 
                                }
171
 
                                else            // ListEditor for lists 
172
 
                                {
173
 
                                        String list;
174
 
                                        list = str.mid(1,str.length()-2);
175
 
                                        QString type = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
176
 
                                        StringList rlist = StringList::create(list);
177
 
                                        for(UInt i = 0; i < rlist.size(); ++i)
178
 
                                        {
179
 
                                                rlist[i]  = rlist[i].trim();
180
 
                                        }
181
 
                                        if(type == "int list")
182
 
                                        {
183
 
                                                static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::INT);
184
 
                                        }
185
 
                                        else if(type == "double list")
186
 
                                        {
187
 
                                                static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::FLOAT);
188
 
                                        }
189
 
                                        else if(type == "string list")
190
 
                                        {
191
 
                                                static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::STRING);
192
 
                                        }
193
 
                                        else if(type == "input file list")
194
 
                                        {
195
 
                                                static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::INPUT_FILE);
196
 
                                        }
197
 
                                        else if(type == "output file list")
198
 
                                        {
199
 
                                                static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::OUTPUT_FILE);
200
 
                                        }
201
 
                                        static_cast<ListEditor*>(editor)->setListRestrictions(index.sibling(index.row(),2).data(Qt::UserRole).toString());
202
 
                                }
203
 
                        }
204
 
                }
205
 
                
206
 
                void ParamEditorDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
207
 
                {
208
 
                        QVariant present_value = index.data(Qt::DisplayRole);
209
 
                        QVariant new_value;
210
 
                        StringList list;
211
 
                        bool new_list = false;
 
160
      if (index.column() == 1)
 
161
      {
 
162
        if (qobject_cast<QComboBox *>(editor))       //Drop-down list for enums
 
163
        {
 
164
          int index = static_cast<QComboBox *>(editor)->findText(str);
 
165
          if (index == -1)
 
166
          {
 
167
            index = 0;
 
168
          }
 
169
          static_cast<QComboBox *>(editor)->setCurrentIndex(index);
 
170
        }
 
171
        else if (qobject_cast<QLineEdit *>(editor))      // LineEdit for other values
 
172
        {
 
173
          QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
 
174
          if (dtype == "output file" || dtype == "input file")          /// for output/input file
 
175
          {
 
176
            if (!fileName_.isNull())
 
177
            {
 
178
              static_cast<QLineEdit *>(editor)->setText(fileName_);
 
179
            }
 
180
          }
 
181
          else
 
182
          {
 
183
            if (str == "" && (dtype == "int" || dtype == "float"))
 
184
            {
 
185
              if (dtype == "int")
 
186
                static_cast<QLineEdit *>(editor)->setText("0");
 
187
              else if (dtype == "float")
 
188
                static_cast<QLineEdit *>(editor)->setText("nan");
 
189
            }
 
190
            else
 
191
            {
 
192
              static_cast<QLineEdit *>(editor)->setText(str);
 
193
            }
 
194
          }
 
195
        }
 
196
        else                // ListEditor for lists
 
197
        {
 
198
          String list;
 
199
          list = str.mid(1, str.length() - 2);
 
200
          QString type = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
 
201
          StringList rlist = StringList::create(list);
 
202
          for (UInt i = 0; i < rlist.size(); ++i)
 
203
          {
 
204
            rlist[i]  = rlist[i].trim();
 
205
          }
 
206
          if (type == "int list")
 
207
          {
 
208
            static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::INT);
 
209
          }
 
210
          else if (type == "double list")
 
211
          {
 
212
            static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::FLOAT);
 
213
          }
 
214
          else if (type == "string list")
 
215
          {
 
216
            static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::STRING);
 
217
          }
 
218
          else if (type == "input file list")
 
219
          {
 
220
            static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::INPUT_FILE);
 
221
          }
 
222
          else if (type == "output file list")
 
223
          {
 
224
            static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::OUTPUT_FILE);
 
225
          }
 
226
          static_cast<ListEditor *>(editor)->setListRestrictions(index.sibling(index.row(), 2).data(Qt::UserRole).toString());
 
227
        }
 
228
      }
 
229
    }
 
230
 
 
231
    void ParamEditorDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
 
232
    {
 
233
      QVariant present_value = index.data(Qt::DisplayRole);
 
234
      QVariant new_value;
 
235
      StringList list;
 
236
      bool new_list = false;
212
237
      // only set model data for first column (value column)
213
 
                        if(index.column()==1)
214
 
                        {
215
 
                                //extract new value
216
 
                                if(qobject_cast<QComboBox*>(editor)) //Drop-down list for enums
217
 
                                {
218
 
                                        new_value = QVariant(static_cast<QComboBox*>(editor)->currentText());
219
 
                                }
220
 
                                else if(qobject_cast<QLineEdit*>(editor))
221
 
                                {
222
 
                                        QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
223
 
                                        if(dtype =="output file" || dtype == "input file")// input/outut file 
224
 
                                        {
225
 
 
226
 
                                                new_value = QVariant(static_cast<QLineEdit*>(editor)->text());
227
 
                                                fileName_ = "\0";
228
 
                                        }
229
 
                                        else if(static_cast<QLineEdit*>(editor)->text() == "" && ((dtype == "int") || (dtype == "float"))) //numeric
230
 
          {
231
 
            if (dtype == "int") new_value = QVariant("0");
232
 
            else if (dtype == "float") new_value = QVariant("nan");
233
 
                                        }
234
 
                                        else
235
 
                                        {
236
 
                                                new_value = QVariant(static_cast<QLineEdit*>(editor)->text());
237
 
                                        }
238
 
                                }
239
 
                                else
240
 
                                {
241
 
                                        list = static_cast<ListEditor*>(editor)->getList();
242
 
                                        for(UInt i = 1; i < list.size(); ++i)
243
 
                                        {
244
 
                                                list[i] = "\n" + list[i] ;
245
 
                                        }
246
 
                                        new_list = true;
247
 
                                }
248
 
                                //check if it matches the restrictions or is empty
249
 
                                if (new_value.toString()!="")
250
 
                                {
251
 
                                        QString type = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
252
 
                                        bool restrictions_met = true;
253
 
                                        String restrictions = index.sibling(index.row(),2).data(Qt::UserRole).toString();
254
 
                                        if (type=="int") //check if valid integer
255
 
                                        {
256
 
                                                bool ok(true);
257
 
                                                new_value.toString().toLong(&ok);
258
 
                                                if (!ok)
259
 
                                                {
260
 
                                                        QMessageBox::warning(0,"Invalid value",QString("Cannot convert '%1' to integer number!").arg(new_value.toString()) );
261
 
                                                        new_value = present_value;
262
 
                                                }
263
 
                                                //restrictions
264
 
                                                vector<String> parts;
265
 
                                                if (restrictions.split(' ',parts))
266
 
                                                {
267
 
                                                        if (parts[0]!="" && new_value.toInt()<parts[0].toInt())
268
 
                                                        {
269
 
                                                                restrictions_met = false;
270
 
                                                        }
271
 
                                                        if (parts[1]!="" && new_value.toInt()>parts[1].toInt())
272
 
                                                        {
273
 
                                                                restrictions_met = false;
274
 
                                                        }
275
 
                                                }
276
 
                                        }
277
 
                                        else if (type=="float") //check if valid float
278
 
                                        {
279
 
                                                bool ok(true);
280
 
                                                new_value.toString().toDouble(&ok);
281
 
                                                if (!ok)
282
 
                                                {
283
 
                                                        QMessageBox::warning(0,"Invalid value",QString("Cannot convert '%1' to floating point number!").arg(new_value.toString()) );
284
 
                                                        new_value = present_value;
285
 
                                                }
286
 
                                                //restrictions
287
 
                                                vector<String> parts;
288
 
                                                if (restrictions.split(' ',parts))
289
 
                                                {
290
 
                                                        if (parts[0]!="" && new_value.toDouble()<parts[0].toDouble())
291
 
                                                        {
292
 
                                                                restrictions_met = false;
293
 
                                                        }
294
 
                                                        if (parts[1]!="" && new_value.toDouble()>parts[1].toDouble())
295
 
                                                        {
296
 
                                                                restrictions_met = false;
297
 
                                                        }
298
 
                                                }
299
 
                                        }
300
 
                                        if(!restrictions_met)
301
 
                                        {
302
 
                                                QMessageBox::warning(0,"Invalid value",QString("Value restrictions not met: %1").arg(index.sibling(index.row(),3).data(Qt::DisplayRole).toString()) );
303
 
                                                new_value = present_value;
304
 
                                        }
305
 
                                }
306
 
                        }
307
 
                        if(new_list)
308
 
                        {
309
 
                                stringstream ss;
310
 
                                ss << list;
311
 
                                QVariant new_value;
312
 
                                new_value = QVariant(QString::fromStdString(ss.str()));
313
 
                                model->setData(index, new_value);
314
 
                                model->setData(index,QBrush(Qt::yellow),Qt::BackgroundRole);
315
 
                                emit modified(true);
316
 
                        }                               
317
 
                        else
318
 
                        {
319
 
                                //check if modified
320
 
                                if(new_value!=present_value)
321
 
                                {
322
 
                                        model->setData(index, new_value);
323
 
                                        model->setData(index,QBrush(Qt::yellow),Qt::BackgroundRole);
324
 
                                        emit modified(true);
325
 
                                }
326
 
                        }
327
 
                }
328
 
                 
329
 
                void ParamEditorDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& ) const
330
 
                {
331
 
                                editor->setGeometry(option.rect);
332
 
                }
333
 
 
334
 
                bool ParamEditorDelegate::exists_(QString name, QModelIndex index) const
335
 
                {
336
 
                        UInt current_index = 0;
337
 
                        while(index.parent().child(current_index,0).isValid())
338
 
                        {
339
 
                                if (
340
 
                                                current_index != (UInt)(index.row())
341
 
                                                && 
342
 
                                                index.parent().child(current_index,0).data(Qt::DisplayRole).toString()==name
343
 
                                                &&
344
 
                                                (
345
 
                                                (index.data(Qt::UserRole).toInt()==0 && index.parent().child(current_index,0).data(Qt::UserRole).toInt()==0)
346
 
                                                ||
347
 
                                                (index.data(Qt::UserRole).toInt()!=0 && index.parent().child(current_index,0).data(Qt::UserRole).toInt()!=0)
348
 
                                                )
349
 
                                         )
350
 
                                {
351
 
                                        return true;
352
 
                                }
353
 
                                ++current_index;
354
 
                        }
355
 
                        return false;
356
 
                }
357
 
                
358
 
                void ParamEditorDelegate::commitAndCloseListEditor_()
359
 
                {
360
 
                        ListEditor* editor = qobject_cast<ListEditor*>(sender());
361
 
                        emit commitData(editor);
362
 
                        emit closeEditor(editor);
363
 
                }
364
 
 
365
 
                void ParamEditorDelegate::commitAndCloseComboBox_()
366
 
                {
367
 
                        QComboBox* editor = qobject_cast<QComboBox*>(sender());
368
 
                        emit commitData(editor);
369
 
                        emit closeEditor(editor);
370
 
                }
371
 
                
372
 
                void ParamEditorDelegate::closeListEditor_()
373
 
                {
374
 
                        ListEditor* editor = qobject_cast<ListEditor*>(sender());
375
 
                        emit closeEditor(editor);
376
 
                }
377
 
 
378
 
                ///////////////////ParamTree/////////////////////////////////
379
 
        
380
 
                ParamTree::ParamTree(QWidget* parent)
381
 
                        : QTreeWidget(parent)
382
 
                {
383
 
                }
384
 
        
385
 
                void ParamTree::selectionChanged(const QItemSelection& s, const QItemSelection&)
386
 
                {
387
 
                        if (!s.empty())
388
 
                        {
389
 
                                emit selected(s.indexes().first());
390
 
                        }
391
 
                }
392
 
 
393
 
                bool ParamTree::edit(const QModelIndex& index, EditTrigger trigger, QEvent* event)
394
 
                {
395
 
                        if (trigger == QAbstractItemView::EditKeyPressed)
396
 
                        {
397
 
                                return QAbstractItemView::edit(index.sibling(index.row(),1), trigger, event);
398
 
                        }
399
 
                        return QAbstractItemView::edit(index, trigger, event);
400
 
                }
401
 
 
402
 
        }
403
 
 
404
 
        ///////////////////ParamEditor/////////////////////////////////
405
 
 
406
 
        ParamEditor::ParamEditor(QWidget* parent)
407
 
          : QWidget(parent),
408
 
                param_(0),
409
 
                        modified_(false),
410
 
                        advanced_mode_(false)
411
 
        {
412
 
                setupUi(this);
413
 
                tree_ = new Internal::ParamTree(this);
414
 
                tree_->setMinimumSize(450,200);
415
 
                tree_->setAllColumnsShowFocus(true);
416
 
                tree_->setColumnCount(4);
417
 
                QStringList list;
 
238
      if (index.column() == 1)
 
239
      {
 
240
        //extract new value
 
241
        if (qobject_cast<QComboBox *>(editor))       //Drop-down list for enums
 
242
        {
 
243
          new_value = QVariant(static_cast<QComboBox *>(editor)->currentText());
 
244
        }
 
245
        else if (qobject_cast<QLineEdit *>(editor))
 
246
        {
 
247
          QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
 
248
          if (dtype == "output file" || dtype == "input file")        // input/outut file
 
249
          {
 
250
 
 
251
            new_value = QVariant(static_cast<QLineEdit *>(editor)->text());
 
252
            fileName_ = "\0";
 
253
          }
 
254
          else if (static_cast<QLineEdit *>(editor)->text() == "" && ((dtype == "int") || (dtype == "float")))         //numeric
 
255
          {
 
256
            if (dtype == "int")
 
257
              new_value = QVariant("0");
 
258
            else if (dtype == "float")
 
259
              new_value = QVariant("nan");
 
260
          }
 
261
          else
 
262
          {
 
263
            new_value = QVariant(static_cast<QLineEdit *>(editor)->text());
 
264
          }
 
265
        }
 
266
        else
 
267
        {
 
268
          list = static_cast<ListEditor *>(editor)->getList();
 
269
          for (UInt i = 1; i < list.size(); ++i)
 
270
          {
 
271
            list[i] = "\n" + list[i];
 
272
          }
 
273
          new_list = true;
 
274
        }
 
275
        //check if it matches the restrictions or is empty
 
276
        if (new_value.toString() != "")
 
277
        {
 
278
          QString type = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
 
279
          bool restrictions_met = true;
 
280
          String restrictions = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
 
281
          if (type == "int")         //check if valid integer
 
282
          {
 
283
            bool ok(true);
 
284
            new_value.toString().toLong(&ok);
 
285
            if (!ok)
 
286
            {
 
287
              QMessageBox::warning(0, "Invalid value", QString("Cannot convert '%1' to integer number!").arg(new_value.toString()));
 
288
              new_value = present_value;
 
289
            }
 
290
            //restrictions
 
291
            vector<String> parts;
 
292
            if (restrictions.split(' ', parts))
 
293
            {
 
294
              if (parts[0] != "" && new_value.toInt() < parts[0].toInt())
 
295
              {
 
296
                restrictions_met = false;
 
297
              }
 
298
              if (parts[1] != "" && new_value.toInt() > parts[1].toInt())
 
299
              {
 
300
                restrictions_met = false;
 
301
              }
 
302
            }
 
303
          }
 
304
          else if (type == "float")         //check if valid float
 
305
          {
 
306
            bool ok(true);
 
307
            new_value.toString().toDouble(&ok);
 
308
            if (!ok)
 
309
            {
 
310
              QMessageBox::warning(0, "Invalid value", QString("Cannot convert '%1' to floating point number!").arg(new_value.toString()));
 
311
              new_value = present_value;
 
312
            }
 
313
            //restrictions
 
314
            vector<String> parts;
 
315
            if (restrictions.split(' ', parts))
 
316
            {
 
317
              if (parts[0] != "" && new_value.toDouble() < parts[0].toDouble())
 
318
              {
 
319
                restrictions_met = false;
 
320
              }
 
321
              if (parts[1] != "" && new_value.toDouble() > parts[1].toDouble())
 
322
              {
 
323
                restrictions_met = false;
 
324
              }
 
325
            }
 
326
          }
 
327
          if (!restrictions_met)
 
328
          {
 
329
            QMessageBox::warning(0, "Invalid value", QString("Value restrictions not met: %1").arg(index.sibling(index.row(), 3).data(Qt::DisplayRole).toString()));
 
330
            new_value = present_value;
 
331
          }
 
332
        }
 
333
      }
 
334
      if (new_list)
 
335
      {
 
336
        stringstream ss;
 
337
        ss << list;
 
338
        QVariant new_value;
 
339
        new_value = QVariant(QString::fromStdString(ss.str()));
 
340
        model->setData(index, new_value);
 
341
        model->setData(index, QBrush(Qt::yellow), Qt::BackgroundRole);
 
342
        emit modified(true);
 
343
      }
 
344
      else
 
345
      {
 
346
        //check if modified
 
347
        if (new_value != present_value)
 
348
        {
 
349
          model->setData(index, new_value);
 
350
          model->setData(index, QBrush(Qt::yellow), Qt::BackgroundRole);
 
351
          emit modified(true);
 
352
        }
 
353
      }
 
354
    }
 
355
 
 
356
    void ParamEditorDelegate::updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex &) const
 
357
    {
 
358
      editor->setGeometry(option.rect);
 
359
    }
 
360
 
 
361
    bool ParamEditorDelegate::exists_(QString name, QModelIndex index) const
 
362
    {
 
363
      UInt current_index = 0;
 
364
      while (index.parent().child(current_index, 0).isValid())
 
365
      {
 
366
        if (
 
367
          current_index != (UInt)(index.row())
 
368
           &&
 
369
          index.parent().child(current_index, 0).data(Qt::DisplayRole).toString() == name
 
370
           &&
 
371
          (
 
372
            (index.data(Qt::UserRole).toInt() == 0 && index.parent().child(current_index, 0).data(Qt::UserRole).toInt() == 0)
 
373
          ||
 
374
            (index.data(Qt::UserRole).toInt() != 0 && index.parent().child(current_index, 0).data(Qt::UserRole).toInt() != 0)
 
375
          )
 
376
          )
 
377
        {
 
378
          return true;
 
379
        }
 
380
        ++current_index;
 
381
      }
 
382
      return false;
 
383
    }
 
384
 
 
385
    void ParamEditorDelegate::commitAndCloseListEditor_()
 
386
    {
 
387
      ListEditor * editor = qobject_cast<ListEditor *>(sender());
 
388
      emit commitData(editor);
 
389
      emit closeEditor(editor);
 
390
    }
 
391
    void ParamEditorDelegate::commitAndCloseLineEdit_()
 
392
    {
 
393
      has_uncommited_data_ = false;
 
394
      OpenMSLineEdit * editor = qobject_cast<OpenMSLineEdit *>(sender());
 
395
      emit commitData(editor);
 
396
      emit closeEditor(editor);
 
397
    }
 
398
 
 
399
    void ParamEditorDelegate::commitAndCloseComboBox_()
 
400
    {
 
401
      QComboBox * editor = qobject_cast<QComboBox *>(sender());
 
402
      emit commitData(editor);
 
403
      emit closeEditor(editor);
 
404
    }
 
405
 
 
406
    void ParamEditorDelegate::closeListEditor_()
 
407
    {
 
408
      ListEditor * editor = qobject_cast<ListEditor *>(sender());
 
409
      emit closeEditor(editor);
 
410
    }
 
411
 
 
412
    bool ParamEditorDelegate::hasUncommittedData() const
 
413
    {
 
414
      return has_uncommited_data_;
 
415
    }
 
416
 
 
417
    ///////////////////ParamTree/////////////////////////////////
 
418
 
 
419
    ParamTree::ParamTree(QWidget * parent) :
 
420
      QTreeWidget(parent)
 
421
    {
 
422
    }
 
423
 
 
424
    void ParamTree::selectionChanged(const QItemSelection & s, const QItemSelection &)
 
425
    {
 
426
      if (!s.empty())
 
427
      {
 
428
        emit selected(s.indexes().first());
 
429
      }
 
430
    }
 
431
 
 
432
    bool ParamTree::edit(const QModelIndex & index, EditTrigger trigger, QEvent * event)
 
433
    { // allow F2 or double click on any column in the current row
 
434
      if (trigger == QAbstractItemView::EditKeyPressed || trigger == QAbstractItemView::DoubleClicked)
 
435
      { // --> re-route to actual value column
 
436
        return QAbstractItemView::edit(index.sibling(index.row(), 1), trigger, event); 
 
437
      }
 
438
      return QAbstractItemView::edit(index, trigger, event);
 
439
    }
 
440
 
 
441
  }
 
442
 
 
443
  ///////////////////ParamEditor/////////////////////////////////
 
444
 
 
445
  ParamEditor::ParamEditor(QWidget * parent) :
 
446
    QWidget(parent),
 
447
    param_(0),
 
448
    modified_(false),
 
449
    advanced_mode_(false)
 
450
  {
 
451
    setupUi(this);
 
452
    tree_ = new Internal::ParamTree(this);
 
453
    tree_->setMinimumSize(450, 200);
 
454
    tree_->setAllColumnsShowFocus(true);
 
455
    tree_->setColumnCount(4);
 
456
    QStringList list;
418
457
    list << "parameter" << "value" << "type" << "restrictions";
419
 
                tree_->setHeaderLabels(list);
420
 
    dynamic_cast<QVBoxLayout*>(layout())->insertWidget(0,tree_,1);
421
 
                tree_->setItemDelegate(new Internal::ParamEditorDelegate(tree_));       // the delegate from above is set
422
 
                connect(tree_->itemDelegate(),SIGNAL(modified(bool)),this,SLOT(setModified(bool)));
423
 
                connect(advanced_,SIGNAL(toggled(bool)),this,SLOT(toggleAdvancedMode(bool)));
424
 
                connect(tree_,SIGNAL(selected(const QModelIndex&)),this,SLOT(showDocumentation(const QModelIndex&)));
425
 
        }
426
 
        
427
 
        void ParamEditor::showDocumentation(const QModelIndex& index)
428
 
        {
429
 
                doc_->setText(index.sibling(index.row(),1).data(Qt::UserRole).toString());
430
 
        }
431
 
 
432
 
        void ParamEditor::load(Param& param)
433
 
        {
434
 
                param_= &param;
435
 
                
436
 
                tree_->clear();
437
 
                
438
 
                QTreeWidgetItem* parent=tree_->invisibleRootItem();
439
 
                QTreeWidgetItem* item = NULL;   
440
 
                
441
 
                for(Param::ParamIterator it=param.begin();it!=param.end();++it)
442
 
                {
443
 
                        //********handle opened/closed nodes********
444
 
                        const std::vector< Param::ParamIterator::TraceInfo >& trace = it.getTrace();
445
 
                        for(std::vector< Param::ParamIterator::TraceInfo >::const_iterator it2 = trace.begin(); it2!=trace.end(); ++it2)
446
 
                        {
447
 
                                if (it2->opened) //opened node
448
 
                                {
449
 
                                        item = new QTreeWidgetItem(parent);
450
 
                                        //name
451
 
                                        item->setText(0, it2->name.toQString());
 
458
    tree_->setHeaderLabels(list);
 
459
    dynamic_cast<QVBoxLayout *>(layout())->insertWidget(0, tree_, 1);
 
460
    tree_->setItemDelegate(new Internal::ParamEditorDelegate(tree_));       // the delegate from above is set
 
461
    connect(tree_->itemDelegate(), SIGNAL(modified(bool)), this, SLOT(setModified(bool)));
 
462
    connect(advanced_, SIGNAL(toggled(bool)), this, SLOT(toggleAdvancedMode(bool)));
 
463
    connect(tree_, SIGNAL(selected(const QModelIndex &)), this, SLOT(showDocumentation(const QModelIndex &)));
 
464
  }
 
465
 
 
466
  void ParamEditor::showDocumentation(const QModelIndex & index)
 
467
  {
 
468
    doc_->setText(index.sibling(index.row(), 1).data(Qt::UserRole).toString());
 
469
  }
 
470
 
 
471
  void ParamEditor::load(Param & param)
 
472
  {
 
473
    param_ = &param;
 
474
 
 
475
    tree_->clear();
 
476
 
 
477
    QTreeWidgetItem * parent = tree_->invisibleRootItem();
 
478
    QTreeWidgetItem * item = NULL;
 
479
 
 
480
    for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
 
481
    {
 
482
      //********handle opened/closed nodes********
 
483
      const std::vector<Param::ParamIterator::TraceInfo> & trace = it.getTrace();
 
484
      for (std::vector<Param::ParamIterator::TraceInfo>::const_iterator it2 = trace.begin(); it2 != trace.end(); ++it2)
 
485
      {
 
486
        if (it2->opened)         //opened node
 
487
        {
 
488
          item = new QTreeWidgetItem(parent);
 
489
          //name
 
490
          item->setText(0, it2->name.toQString());
452
491
          item->setTextColor(0, Qt::darkGray);  // color of nodes with children
453
492
 
454
 
                                        //description
455
 
          item->setData(1,Qt::UserRole, it2->description.toQString());
456
 
                                        //role
457
 
          item->setData(0,Qt::UserRole, NODE);
458
 
                                        //flags
459
 
                                        if(param_!=NULL)
460
 
                                        {
461
 
                                                item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
462
 
                                        }
463
 
                                        else 
464
 
                                        {
465
 
                                                item->setFlags( Qt::ItemIsEnabled );
466
 
                                        }
467
 
                                        parent=item;
468
 
                                }
469
 
                                else //closed node
470
 
                                {
471
 
                                        parent=parent->parent();
472
 
                                        if(parent==NULL) parent=tree_->invisibleRootItem();
473
 
                                }
474
 
                        }
475
 
                        
476
 
                        //********handle item********
477
 
                        item = new QTreeWidgetItem(parent);
 
493
          //description
 
494
          item->setData(1, Qt::UserRole, it2->description.toQString());
 
495
          //role
 
496
          item->setData(0, Qt::UserRole, NODE);
 
497
          //flags
 
498
          if (param_ != NULL)
 
499
          {
 
500
            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
 
501
          }
 
502
          else
 
503
          {
 
504
            item->setFlags(Qt::ItemIsEnabled);
 
505
          }
 
506
          parent = item;
 
507
        }
 
508
        else         //closed node
 
509
        {
 
510
          parent = parent->parent();
 
511
          if (parent == NULL)
 
512
            parent = tree_->invisibleRootItem();
 
513
        }
 
514
      }
 
515
 
 
516
      //********handle item********
 
517
      item = new QTreeWidgetItem(parent);
478
518
 
479
519
      // grey out non-editable columns (leaf nodes)
480
520
      bool is_required = it->tags.find("required") != it->tags.end();
481
521
      if (is_required)  // special color for required parameters
482
522
      {
483
 
        item->setTextColor(0, QColor(255,140,0,255)); // orange
484
 
        item->setTextColor(2, QColor(255,140,0,255));
485
 
        item->setTextColor(3, QColor(255,140,0,255));
486
 
      } else
 
523
        item->setTextColor(0, QColor(255, 140, 0, 255)); // orange
 
524
        item->setTextColor(2, QColor(255, 140, 0, 255));
 
525
        item->setTextColor(3, QColor(255, 140, 0, 255));
 
526
      }
 
527
      else
487
528
      {
488
529
        item->setTextColor(0, Qt::darkGray);
489
530
        item->setTextColor(2, Qt::darkGray);
490
531
        item->setTextColor(3, Qt::darkGray);
491
532
      }
492
533
 
493
 
                        if (it->tags.count("advanced"))
494
 
                        {
495
 
                                item->setData(0,Qt::UserRole,ADVANCED_ITEM);
496
 
                        }
497
 
                        else //advanced parameter
498
 
                        {
499
 
                                item->setData(0,Qt::UserRole,NORMAL_ITEM);                                      
500
 
                        }
501
 
                        //name
502
 
                        item->setText(0, it->name.toQString());
503
 
                        //value
504
 
                        if(it->value.valueType() == DataValue::STRING_LIST)
505
 
                        {
506
 
                                StringList string_list = it->value;
507
 
                                String list_string = String("[")+string_list.concatenate(",\n")+"]";
508
 
                                item->setText(1, list_string.toQString());
509
 
                        }
510
 
                        else if(it->value.valueType() == DataValue::INT_LIST)
511
 
                        {
512
 
                                IntList list = it->value;
513
 
                                StringList string_list;
514
 
                                for (Size i=0; i<list.size();++i)
515
 
                                {
516
 
                                        string_list.push_back(list[i]);
517
 
                                }
518
 
                                String list_string = String("[")+string_list.concatenate(",\n")+"]";
519
 
                                item->setText(1, list_string.toQString());
520
 
                        }
521
 
                        else if(it->value.valueType() == DataValue::DOUBLE_LIST)
522
 
                        {
523
 
                                DoubleList list = it->value;
524
 
                                StringList string_list;
525
 
                                for (Size i=0; i<list.size();++i)
526
 
                                {
527
 
                                        string_list.push_back(list[i]);
528
 
                                }
529
 
                                String list_string = String("[")+string_list.concatenate(",\n")+"]";
530
 
                                item->setText(1, list_string.toQString());
531
 
                        }
532
 
                        else
533
 
                        {
534
 
                                item->setText(1, String(it->value).toQString());
535
 
                        }
536
 
                        //type
537
 
                        switch(it->value.valueType())
538
 
                        {
539
 
                                case DataValue::INT_VALUE:
540
 
                                        item->setText(2, "int");
541
 
                                        break;
542
 
                                case DataValue::DOUBLE_VALUE:
543
 
                                        item->setText(2, "float");
544
 
                                        break;
545
 
                                case DataValue::STRING_VALUE:
546
 
                                        if(it->tags.count("input file"))
547
 
                                        {
548
 
                                                item->setText(2,"input file");
549
 
                                        }
550
 
                                        else if(it->tags.count("output file"))
551
 
                                        {
552
 
                                                item->setText(2,"output file");
553
 
                                        }
554
 
                                        else
555
 
                                        {
556
 
                                                item->setText(2,"string");
557
 
                                        }
558
 
                                        break;
559
 
                                case DataValue::STRING_LIST:
560
 
                                        if(it->tags.count("input file"))
561
 
                                        {
562
 
                                                item->setText(2,"input file list");
563
 
                                        }
564
 
                                        else if(it->tags.count("output file"))
565
 
                                        {
566
 
                                                item->setText(2,"output file list");
567
 
                                        }
568
 
                                        else
569
 
                                        {
570
 
                                                item->setText(2,"string list");
571
 
                                        }
572
 
                                        break;
573
 
                                case DataValue::INT_LIST:
574
 
                                        item->setText(2,"int list");
575
 
                                        break;
576
 
                                case DataValue::DOUBLE_LIST:
577
 
                                        item->setText(2,"double list");
578
 
                                        break;
579
 
                                default:
580
 
                                        break;
581
 
                        };
582
 
                        //restrictions (displayed and internal for easier parsing)
583
 
                        switch(it->value.valueType())
584
 
                        {
585
 
                                case DataValue::INT_VALUE:
586
 
                                case DataValue::INT_LIST:
587
 
                                        {
588
 
                                                String drest="", irest="";
589
 
                                                bool min_set = (it->min_int!=-numeric_limits<Int>::max());
590
 
                                                bool max_set = (it->max_int!=numeric_limits<Int>::max());
591
 
                                                if (max_set || min_set)
592
 
                                                {
593
 
                                                        if (min_set)
594
 
                                                        {
595
 
                                                                drest += String("min: ") + it->min_int;
596
 
                                                                irest += it->min_int;
597
 
                                                        }
598
 
                                                        irest += " ";
599
 
                                                        if (max_set)
600
 
                                                        {
601
 
                                                                if (min_set && max_set) drest += " ";
602
 
                                                                drest += String("max: ") + it->max_int;
603
 
                                                                irest += it->max_int;
604
 
                                                        }
605
 
                                                        item->setText(3, drest.toQString());
606
 
                                                }
607
 
                                                item->setData(2,Qt::UserRole,irest.toQString());
608
 
                                        }
609
 
                                        break;
610
 
                                case DataValue::DOUBLE_VALUE:
611
 
                                case DataValue::DOUBLE_LIST:
612
 
                                        {
613
 
                                                String drest="", irest="";
614
 
                                                bool min_set = (it->min_float!=-numeric_limits<DoubleReal>::max());
615
 
                                                bool max_set = (it->max_float!=numeric_limits<DoubleReal>::max());
616
 
                                                if (max_set || min_set)
617
 
                                                {
618
 
                                                        if (min_set)
619
 
                                                        {
620
 
                                                                drest += String("min: ") + it->min_float;
621
 
                                                                irest += it->min_float;
622
 
                                                        }
623
 
                                                        irest += " ";
624
 
                                                        if (max_set)
625
 
                                                        {
626
 
                                                                if (min_set && max_set) drest += " ";
627
 
                                                                drest += String("max: ") + it->max_float;
628
 
                                                                irest += it->max_float;
629
 
                                                        }
630
 
                                                        item->setText(3, drest.toQString());
631
 
                                                }
632
 
                                                item->setData(2,Qt::UserRole,irest.toQString());
633
 
                                        }
634
 
                                        break;
635
 
                                case DataValue::STRING_VALUE:
636
 
                                case DataValue::STRING_LIST:    
637
 
                                        {
638
 
                                                String irest="";
639
 
                                                if (it->valid_strings.size()!=0)
640
 
                                                {
641
 
                                                        irest.concatenate(it->valid_strings.begin(),it->valid_strings.end(),",");
642
 
                                                }
643
 
                                                if (irest!="")
644
 
                                                {
645
 
                                                        String r_text=irest;
646
 
                                                  if (r_text.size() > 255)
647
 
                                                        {       // truncate restriction text, as some QT versions (4.6 & 4.7) will crash if text is too long
648
 
                                                                r_text = irest.prefix(251) + "...";
649
 
                                                        }
650
 
                                                        item->setText(3, r_text.toQString());
651
 
                                                }
652
 
                                                item->setData(2,Qt::UserRole,irest.toQString());
653
 
                                        }
654
 
                                        break;
655
 
                                default:
656
 
                                        break;
657
 
                        };
658
 
 
659
 
                        //description
660
 
                        item->setData(1,Qt::UserRole,it->description.toQString());
661
 
                        //flags
662
 
                        if(param_!=NULL)
663
 
                        {
664
 
                                item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
665
 
                        }
666
 
                        else 
667
 
                        {
668
 
                                item->setFlags( Qt::ItemIsEnabled );
669
 
                        }
670
 
                }
671
 
                
672
 
                tree_->expandAll();
673
 
                toggleAdvancedMode(advanced_mode_);
674
 
                
675
 
                tree_->resizeColumnToContents(0);
676
 
                tree_->resizeColumnToContents(1);
677
 
                tree_->resizeColumnToContents(2);
678
 
                tree_->resizeColumnToContents(3);
679
 
        }
680
 
            
681
 
        void ParamEditor::store()
682
 
        {
683
 
                if(param_!=NULL)
684
 
                {
685
 
                        QTreeWidgetItem* parent=tree_->invisibleRootItem();
686
 
                        //param_->clear();
687
 
                
688
 
                        for (Int i = 0; i < parent->childCount();++i)
689
 
                        {
690
 
                                map<String,String> section_descriptions;
691
 
                                storeRecursive_(parent->child(i),"", section_descriptions);     //whole tree recursively
692
 
                        }       
693
 
                }
694
 
                        
695
 
                setModified(false);
696
 
        }
697
 
        
698
 
        void ParamEditor::clear()
699
 
        {
700
 
                tree_->clear();
701
 
        }
702
 
        
703
 
        void ParamEditor::storeRecursive_(QTreeWidgetItem* child, String path,map<String,String>& section_descriptions)
704
 
        {
705
 
                /**
706
 
                        
707
 
                        @todo: why would we "recreate" (setting restrictions etc) the the param object from scratch?
708
 
             updating everything that changed seems the better option, as
709
 
                                                 this is more robust against additions to Param
710
 
                        
711
 
                */
712
 
                child->setData ( 1, Qt::BackgroundRole, QBrush(Qt::white));
713
 
                
714
 
                if (path=="")
715
 
                {
716
 
                        path = child->text(0).toStdString();
717
 
                }
718
 
                else
719
 
                {
720
 
                        path += String(":") + String(child->text(0).toStdString());     
721
 
                }
722
 
                
723
 
                String description = child->data(1, Qt::UserRole).toString();
724
 
                
 
534
      if (it->tags.count("advanced"))
 
535
      {
 
536
        item->setData(0, Qt::UserRole, ADVANCED_ITEM);
 
537
      }
 
538
      else       //advanced parameter
 
539
      {
 
540
        item->setData(0, Qt::UserRole, NORMAL_ITEM);
 
541
      }
 
542
      //name
 
543
      item->setText(0, it->name.toQString());
 
544
      //value
 
545
      if (it->value.valueType() == DataValue::STRING_LIST)
 
546
      {
 
547
        StringList string_list = it->value;
 
548
        String list_string = String("[") + string_list.concatenate(",\n") + "]";
 
549
        item->setText(1, list_string.toQString());
 
550
      }
 
551
      else if (it->value.valueType() == DataValue::INT_LIST)
 
552
      {
 
553
        IntList list = it->value;
 
554
        StringList string_list;
 
555
        for (Size i = 0; i < list.size(); ++i)
 
556
        {
 
557
          string_list.push_back(list[i]);
 
558
        }
 
559
        String list_string = String("[") + string_list.concatenate(",\n") + "]";
 
560
        item->setText(1, list_string.toQString());
 
561
      }
 
562
      else if (it->value.valueType() == DataValue::DOUBLE_LIST)
 
563
      {
 
564
        DoubleList list = it->value;
 
565
        StringList string_list;
 
566
        for (Size i = 0; i < list.size(); ++i)
 
567
        {
 
568
          string_list.push_back(list[i]);
 
569
        }
 
570
        String list_string = String("[") + string_list.concatenate(",\n") + "]";
 
571
        item->setText(1, list_string.toQString());
 
572
      }
 
573
      else
 
574
      {
 
575
        item->setText(1, String(it->value).toQString());
 
576
      }
 
577
      //type
 
578
      switch (it->value.valueType())
 
579
      {
 
580
      case DataValue::INT_VALUE:
 
581
        item->setText(2, "int");
 
582
        break;
 
583
 
 
584
      case DataValue::DOUBLE_VALUE:
 
585
        item->setText(2, "float");
 
586
        break;
 
587
 
 
588
      case DataValue::STRING_VALUE:
 
589
        if (it->tags.count("input file"))
 
590
        {
 
591
          item->setText(2, "input file");
 
592
        }
 
593
        else if (it->tags.count("output file"))
 
594
        {
 
595
          item->setText(2, "output file");
 
596
        }
 
597
        else
 
598
        {
 
599
          item->setText(2, "string");
 
600
        }
 
601
        break;
 
602
 
 
603
      case DataValue::STRING_LIST:
 
604
        if (it->tags.count("input file"))
 
605
        {
 
606
          item->setText(2, "input file list");
 
607
        }
 
608
        else if (it->tags.count("output file"))
 
609
        {
 
610
          item->setText(2, "output file list");
 
611
        }
 
612
        else
 
613
        {
 
614
          item->setText(2, "string list");
 
615
        }
 
616
        break;
 
617
 
 
618
      case DataValue::INT_LIST:
 
619
        item->setText(2, "int list");
 
620
        break;
 
621
 
 
622
      case DataValue::DOUBLE_LIST:
 
623
        item->setText(2, "double list");
 
624
        break;
 
625
 
 
626
      default:
 
627
        break;
 
628
      }
 
629
      //restrictions (displayed and internal for easier parsing)
 
630
      switch (it->value.valueType())
 
631
      {
 
632
      case DataValue::INT_VALUE:
 
633
      case DataValue::INT_LIST:
 
634
      {
 
635
        String drest = "", irest = "";
 
636
        bool min_set = (it->min_int != -numeric_limits<Int>::max());
 
637
        bool max_set = (it->max_int != numeric_limits<Int>::max());
 
638
        if (max_set || min_set)
 
639
        {
 
640
          if (min_set)
 
641
          {
 
642
            drest += String("min: ") + it->min_int;
 
643
            irest += it->min_int;
 
644
          }
 
645
          irest += " ";
 
646
          if (max_set)
 
647
          {
 
648
            if (min_set && max_set)
 
649
              drest += " ";
 
650
            drest += String("max: ") + it->max_int;
 
651
            irest += it->max_int;
 
652
          }
 
653
          item->setText(3, drest.toQString());
 
654
        }
 
655
        item->setData(2, Qt::UserRole, irest.toQString());
 
656
      }
 
657
      break;
 
658
 
 
659
      case DataValue::DOUBLE_VALUE:
 
660
      case DataValue::DOUBLE_LIST:
 
661
      {
 
662
        String drest = "", irest = "";
 
663
        bool min_set = (it->min_float != -numeric_limits<DoubleReal>::max());
 
664
        bool max_set = (it->max_float != numeric_limits<DoubleReal>::max());
 
665
        if (max_set || min_set)
 
666
        {
 
667
          if (min_set)
 
668
          {
 
669
            drest += String("min: ") + it->min_float;
 
670
            irest += it->min_float;
 
671
          }
 
672
          irest += " ";
 
673
          if (max_set)
 
674
          {
 
675
            if (min_set && max_set)
 
676
              drest += " ";
 
677
            drest += String("max: ") + it->max_float;
 
678
            irest += it->max_float;
 
679
          }
 
680
          item->setText(3, drest.toQString());
 
681
        }
 
682
        item->setData(2, Qt::UserRole, irest.toQString());
 
683
      }
 
684
      break;
 
685
 
 
686
      case DataValue::STRING_VALUE:
 
687
      case DataValue::STRING_LIST:
 
688
      {
 
689
        String irest = "";
 
690
        if (it->valid_strings.size() != 0)
 
691
        {
 
692
          irest.concatenate(it->valid_strings.begin(), it->valid_strings.end(), ",");
 
693
        }
 
694
        if (irest != "")
 
695
        {
 
696
          String r_text = irest;
 
697
          if (r_text.size() > 255) // truncate restriction text, as some QT versions (4.6 & 4.7) will crash if text is too long
 
698
          {
 
699
            r_text = irest.prefix(251) + "...";
 
700
          }
 
701
          item->setText(3, r_text.toQString());
 
702
        }
 
703
        item->setData(2, Qt::UserRole, irest.toQString());
 
704
      }
 
705
      break;
 
706
 
 
707
      default:
 
708
        break;
 
709
      }
 
710
 
 
711
      //description
 
712
      item->setData(1, Qt::UserRole, it->description.toQString());
 
713
      //flags
 
714
      if (param_ != NULL)
 
715
      {
 
716
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
 
717
      }
 
718
      else
 
719
      {
 
720
        item->setFlags(Qt::ItemIsEnabled);
 
721
      }
 
722
    }
 
723
 
 
724
    tree_->expandAll();
 
725
    toggleAdvancedMode(advanced_mode_);
 
726
 
 
727
    tree_->resizeColumnToContents(0);
 
728
    tree_->resizeColumnToContents(1);
 
729
    tree_->resizeColumnToContents(2);
 
730
    tree_->resizeColumnToContents(3);
 
731
  }
 
732
 
 
733
  void ParamEditor::store()
 
734
  {
 
735
    //std::cerr << "store entered ...\n";
 
736
    
 
737
    // store only if no line-edit is opened (in which case data is uncommitted and will not be saved)
 
738
    // this applies only to INIFileEditor, where pressing Ctrl-s results in saving the current (but outdated) param
 
739
    if (param_ != NULL &&
 
740
        !static_cast<Internal::ParamEditorDelegate*>(this->tree_->itemDelegate())->hasUncommittedData())
 
741
    { 
 
742
      //std::cerr << "and done!...\n";
 
743
      QTreeWidgetItem * parent = tree_->invisibleRootItem();
 
744
      //param_->clear();
 
745
 
 
746
      for (Int i = 0; i < parent->childCount(); ++i)
 
747
      {
 
748
        map<String, String> section_descriptions;
 
749
        storeRecursive_(parent->child(i), "", section_descriptions);        //whole tree recursively
 
750
      }
 
751
 
 
752
      setModified(false);
 
753
    }
 
754
    //else std::cerr << "store aborted!\n";
 
755
 
 
756
  }
 
757
 
 
758
  void ParamEditor::clear()
 
759
  {
 
760
    tree_->clear();
 
761
  }
 
762
 
 
763
  void ParamEditor::storeRecursive_(QTreeWidgetItem * child, String path, map<String, String> & section_descriptions)
 
764
  {
 
765
    /**
 
766
 
 
767
        @todo: why would we "recreate" (setting restrictions etc) the the param object from scratch?
 
768
         updating everything that changed seems the better option, as
 
769
                     this is more robust against additions to Param
 
770
 
 
771
    */
 
772
    child->setData(1, Qt::BackgroundRole, QBrush(Qt::white));
 
773
 
 
774
    if (path == "")
 
775
    {
 
776
      path = child->text(0).toStdString();
 
777
    }
 
778
    else
 
779
    {
 
780
      path += String(":") + String(child->text(0).toStdString());
 
781
    }
 
782
 
 
783
    String description = child->data(1, Qt::UserRole).toString();
 
784
 
725
785
    StringList tag_list;
726
 
    try
727
 
    { // might throw ElementNotFound
 
786
    try // might throw ElementNotFound
 
787
    {
728
788
      tag_list = param_->getTags(path);
729
789
    }
730
 
    catch (...) {}
731
 
 
732
 
                if(child->text(2)=="") // node
733
 
                {
734
 
                        if (description != "")
735
 
                        {
736
 
                                section_descriptions.insert(make_pair(path,description));
737
 
                        }
738
 
                }
739
 
                else //item + section descriptions
740
 
                {
741
 
                        if(child->text(2)=="float")
742
 
                        {
743
 
                                param_->setValue(path,child->text(1).toDouble(),description,tag_list);
744
 
                                String restrictions = child->data(2, Qt::UserRole).toString();
745
 
                                vector<String> parts;
746
 
                                if (restrictions.split(' ',parts))
747
 
                                {
748
 
                                        if (parts[0]!="")
749
 
                                        {
750
 
                                                param_->setMinFloat(path,parts[0].toDouble());
751
 
                                        }
752
 
                                        if (parts[1]!="")
753
 
                                        {
754
 
                                                param_->setMaxFloat(path,parts[1].toDouble());
755
 
                                        }
756
 
                                }
757
 
                        }
758
 
                        else if(child->text(2)=="string")
759
 
                        {
760
 
                                param_->setValue(path, child->text(1).toStdString(),description,tag_list);
761
 
                                String restrictions = child->data(2, Qt::UserRole).toString();
762
 
                                if(restrictions!="")
763
 
                                {
764
 
                                        std::vector<String> parts;
765
 
                                        restrictions.split(',', parts);
766
 
                                        param_->setValidStrings(path,parts);
767
 
                                }
768
 
                        }
769
 
                        else if(child->text(2) =="input file")
770
 
                        {
771
 
                                param_->setValue(path, child->text(1).toStdString(),description,tag_list);
772
 
                                String restrictions = child->data(2, Qt::UserRole).toString();
773
 
                                if(restrictions!="")
774
 
                                {
775
 
                                        std::vector<String> parts;
776
 
                                        restrictions.split(',', parts);
777
 
                                        param_->setValidStrings(path,parts);
778
 
                                }
779
 
                        }
780
 
                        else if(child->text(2) =="output file")
781
 
                        {
782
 
                                param_->setValue(path, child->text(1).toStdString(),description,tag_list);
783
 
                                String restrictions = child->data(2, Qt::UserRole).toString();
784
 
                                if(restrictions!="")
785
 
                                {
786
 
                                        std::vector<String> parts;
787
 
                                        restrictions.split(',', parts);
788
 
                                        param_->setValidStrings(path,parts);
789
 
                                }
790
 
                        }
791
 
                        else if(child->text(2)=="int")
792
 
                        {
793
 
                                param_->setValue(path, child->text(1).toInt(),description,tag_list);
794
 
                                String restrictions = child->data(2, Qt::UserRole).toString();
795
 
                                vector<String> parts;
796
 
                                if (restrictions.split(' ',parts))
797
 
                                {
798
 
                                        if (parts[0]!="")
799
 
                                        {
800
 
                                                param_->setMinInt(path,parts[0].toInt());
801
 
                                        }
802
 
                                        if (parts[1]!="")
803
 
                                        {
804
 
                                                param_->setMaxInt(path,parts[1].toInt());
805
 
                                        }
806
 
                                }
807
 
                        }
808
 
                        String list;
809
 
                        list = child->text(1).mid(1,child->text(1).length()-2); 
810
 
                        StringList rlist = StringList::create(list);
811
 
                        for(UInt i = 0; i < rlist.size(); ++i)
812
 
                        {
813
 
                                rlist[i] = rlist[i].trim();
814
 
                        }
815
 
                        if(child->text(2)=="string list")
816
 
                        {
817
 
                                param_->setValue(path,rlist,description,tag_list);
818
 
                                String restrictions = child->data(2,Qt::UserRole).toString();
819
 
                                if(restrictions!="")
820
 
                                {
821
 
                                        vector<String> parts;
822
 
                                        restrictions.split(',',parts);
823
 
                                        param_->setValidStrings(path,parts);
824
 
                                }
825
 
                        }
826
 
                        else if(child->text(2)=="input file list")
827
 
                        {
828
 
                                param_->setValue(path,rlist,description,tag_list);
829
 
                                String restrictions = child->data(2,Qt::UserRole).toString();
830
 
                                if(restrictions!="")
831
 
                                {
832
 
                                        vector<String> parts;
833
 
                                        restrictions.split(',',parts);
834
 
                                        param_->setValidStrings(path,parts);
835
 
                                }
836
 
                        }
837
 
                        else if(child->text(2)=="output file list")
838
 
                        {
839
 
                                param_->setValue(path,rlist,description,tag_list);
840
 
                                String restrictions = child->data(2,Qt::UserRole).toString();
841
 
                                if(restrictions!="")
842
 
                                {
843
 
                                        vector<String> parts;
844
 
                                        restrictions.split(',',parts);
845
 
                                        param_->setValidStrings(path,parts);
846
 
                                }
847
 
                        }
848
 
                        else if(child->text(2) =="double list")
849
 
                        {
850
 
                                param_->setValue(path,DoubleList::create(rlist),description,tag_list);
851
 
                                String restrictions = child->data(2,Qt::UserRole).toString();
852
 
                                vector<String> parts;
853
 
                                if(restrictions.split(' ',parts))
854
 
                                {
855
 
                                        if(parts[0]!= "")
856
 
                                        {
857
 
                                                param_->setMinFloat(path,parts[0].toFloat());
858
 
                                        }
859
 
                                        if(parts[1] != "")
860
 
                                        {
861
 
                                                param_->setMaxFloat(path,parts[1].toFloat());
862
 
                                        }
863
 
                                }
864
 
                        }
865
 
                        else if(child->text(2) == "int list")
866
 
                        {
867
 
                                param_->setValue(path,IntList::create(rlist),description,tag_list);
868
 
                                String restrictions = child->data(2,Qt::UserRole).toString();
869
 
                                vector<String> parts;
870
 
                                if(restrictions.split(' ',parts))
871
 
                                {
872
 
                                        if(parts[0]!= "")
873
 
                                        {
874
 
                                                param_->setMinInt(path,parts[0].toInt());
875
 
                                        }
876
 
                                        if(parts[1] != "")
877
 
                                        {
878
 
                                                param_->setMaxInt(path,parts[1].toInt());
879
 
                                        }
880
 
                                }                       
881
 
                        }
882
 
                        
883
 
                        // set description node description if the prefix matches
884
 
                        for (map<String,String>::const_iterator it = section_descriptions.begin(); it!=section_descriptions.end(); ++it)
885
 
                        {
886
 
                                if (path.hasPrefix(it->first))
887
 
                                {
888
 
                                        param_->setSectionDescription(it->first, it->second);
889
 
                                }
890
 
                        }
891
 
                        section_descriptions.clear();
892
 
                }
893
 
                
894
 
                for (Int i = 0; i < child->childCount();++i)
895
 
                {
896
 
                        storeRecursive_(child->child(i),path,section_descriptions);     //whole tree recursively
897
 
                }       
898
 
        }
899
 
        
900
 
        void ParamEditor::setModified(bool is_modified)
901
 
        {
902
 
                if (is_modified != modified_)
903
 
                {
904
 
                        modified_ = is_modified;
905
 
                        emit modified(modified_);
906
 
                }
907
 
        }
908
 
 
909
 
        bool ParamEditor::isModified() const
910
 
        {
911
 
                return modified_;
912
 
        }
913
 
 
914
 
        void ParamEditor::toggleAdvancedMode(bool advanced)
915
 
        {
916
 
                advanced_mode_ = advanced;
917
 
                
918
 
                stack<QTreeWidgetItem*> stack, node_stack;
919
 
                
920
 
                //show/hide items
921
 
                stack.push(tree_->invisibleRootItem());
922
 
                while(!stack.empty())
923
 
                {
924
 
                        QTreeWidgetItem* current = stack.top();
925
 
                        stack.pop();
926
 
                        
927
 
                        Int type = current->data(0,Qt::UserRole).toInt();
928
 
                        if (type!=NODE) //ITEM
929
 
                        {
930
 
                                if (advanced_mode_ && type==ADVANCED_ITEM) //advanced mode
931
 
                                {
932
 
                                        current->setHidden(false);
933
 
                                }
934
 
                                else if (!advanced_mode_ && type==ADVANCED_ITEM) //Normal mode
935
 
                                {
936
 
                                        current->setHidden(true);
937
 
                                }
938
 
                        }
939
 
                        else //NODE
940
 
                        {
941
 
                                for (Int i=0; i<current->childCount(); ++i)
942
 
                                {
943
 
                                        stack.push(current->child(i));
944
 
                                }
945
 
                                
946
 
                                if (advanced_mode_)
947
 
                                {
948
 
                                        current->setHidden(false); //show all nodes in advanced mode
949
 
                                }
950
 
                                else
951
 
                                {
952
 
                                        node_stack.push(current); //store node pointers in normal mode
953
 
                                }
954
 
                        }
955
 
                }
956
 
                
957
 
                //hide sections that have no visible items in normal mode
958
 
                while(!node_stack.empty())
959
 
                {
960
 
                        QTreeWidgetItem* current = node_stack.top();
961
 
                        node_stack.pop();
962
 
                        
963
 
                        bool has_visible_children = false;
964
 
                        for (Int i=0; i<current->childCount(); ++i)
965
 
                        {
966
 
                                if (!current->child(i)->isHidden())
967
 
                                {
968
 
                                        has_visible_children = true;
969
 
                                        break;
970
 
                                }
971
 
                        }
972
 
                        if (!has_visible_children)
973
 
                        {
974
 
                                current->setHidden(true);
975
 
                        }
976
 
                }
977
 
                
978
 
                //resize columns
979
 
                tree_->resizeColumnToContents(0);
980
 
                tree_->resizeColumnToContents(1);
981
 
                tree_->resizeColumnToContents(2);
982
 
                tree_->resizeColumnToContents(3);
983
 
        }
 
790
    catch (...)
 
791
    {
 
792
    }
 
793
 
 
794
    if (child->text(2) == "")  // node
 
795
    {
 
796
      if (description != "")
 
797
      {
 
798
        section_descriptions.insert(make_pair(path, description));
 
799
      }
 
800
    }
 
801
    else     //item + section descriptions
 
802
    {
 
803
      if (child->text(2) == "float")
 
804
      {
 
805
        param_->setValue(path, child->text(1).toDouble(), description, tag_list);
 
806
        String restrictions = child->data(2, Qt::UserRole).toString();
 
807
        vector<String> parts;
 
808
        if (restrictions.split(' ', parts))
 
809
        {
 
810
          if (parts[0] != "")
 
811
          {
 
812
            param_->setMinFloat(path, parts[0].toDouble());
 
813
          }
 
814
          if (parts[1] != "")
 
815
          {
 
816
            param_->setMaxFloat(path, parts[1].toDouble());
 
817
          }
 
818
        }
 
819
      }
 
820
      else if (child->text(2) == "string")
 
821
      {
 
822
        param_->setValue(path, child->text(1).toStdString(), description, tag_list);
 
823
        String restrictions = child->data(2, Qt::UserRole).toString();
 
824
        if (restrictions != "")
 
825
        {
 
826
          std::vector<String> parts;
 
827
          restrictions.split(',', parts);
 
828
          param_->setValidStrings(path, parts);
 
829
        }
 
830
      }
 
831
      else if (child->text(2) == "input file")
 
832
      {
 
833
        param_->setValue(path, child->text(1).toStdString(), description, tag_list);
 
834
        String restrictions = child->data(2, Qt::UserRole).toString();
 
835
        if (restrictions != "")
 
836
        {
 
837
          std::vector<String> parts;
 
838
          restrictions.split(',', parts);
 
839
          param_->setValidStrings(path, parts);
 
840
        }
 
841
      }
 
842
      else if (child->text(2) == "output file")
 
843
      {
 
844
        param_->setValue(path, child->text(1).toStdString(), description, tag_list);
 
845
        String restrictions = child->data(2, Qt::UserRole).toString();
 
846
        if (restrictions != "")
 
847
        {
 
848
          std::vector<String> parts;
 
849
          restrictions.split(',', parts);
 
850
          param_->setValidStrings(path, parts);
 
851
        }
 
852
      }
 
853
      else if (child->text(2) == "int")
 
854
      {
 
855
        param_->setValue(path, child->text(1).toInt(), description, tag_list);
 
856
        String restrictions = child->data(2, Qt::UserRole).toString();
 
857
        vector<String> parts;
 
858
        if (restrictions.split(' ', parts))
 
859
        {
 
860
          if (parts[0] != "")
 
861
          {
 
862
            param_->setMinInt(path, parts[0].toInt());
 
863
          }
 
864
          if (parts[1] != "")
 
865
          {
 
866
            param_->setMaxInt(path, parts[1].toInt());
 
867
          }
 
868
        }
 
869
      }
 
870
      String list;
 
871
      list = child->text(1).mid(1, child->text(1).length() - 2);
 
872
      StringList rlist = StringList::create(list);
 
873
      for (UInt i = 0; i < rlist.size(); ++i)
 
874
      {
 
875
        rlist[i] = rlist[i].trim();
 
876
      }
 
877
      if (child->text(2) == "string list")
 
878
      {
 
879
        param_->setValue(path, rlist, description, tag_list);
 
880
        String restrictions = child->data(2, Qt::UserRole).toString();
 
881
        if (restrictions != "")
 
882
        {
 
883
          vector<String> parts;
 
884
          restrictions.split(',', parts);
 
885
          param_->setValidStrings(path, parts);
 
886
        }
 
887
      }
 
888
      else if (child->text(2) == "input file list")
 
889
      {
 
890
        param_->setValue(path, rlist, description, tag_list);
 
891
        String restrictions = child->data(2, Qt::UserRole).toString();
 
892
        if (restrictions != "")
 
893
        {
 
894
          vector<String> parts;
 
895
          restrictions.split(',', parts);
 
896
          param_->setValidStrings(path, parts);
 
897
        }
 
898
      }
 
899
      else if (child->text(2) == "output file list")
 
900
      {
 
901
        param_->setValue(path, rlist, description, tag_list);
 
902
        String restrictions = child->data(2, Qt::UserRole).toString();
 
903
        if (restrictions != "")
 
904
        {
 
905
          vector<String> parts;
 
906
          restrictions.split(',', parts);
 
907
          param_->setValidStrings(path, parts);
 
908
        }
 
909
      }
 
910
      else if (child->text(2) == "double list")
 
911
      {
 
912
        param_->setValue(path, DoubleList::create(rlist), description, tag_list);
 
913
        String restrictions = child->data(2, Qt::UserRole).toString();
 
914
        vector<String> parts;
 
915
        if (restrictions.split(' ', parts))
 
916
        {
 
917
          if (parts[0] != "")
 
918
          {
 
919
            param_->setMinFloat(path, parts[0].toFloat());
 
920
          }
 
921
          if (parts[1] != "")
 
922
          {
 
923
            param_->setMaxFloat(path, parts[1].toFloat());
 
924
          }
 
925
        }
 
926
      }
 
927
      else if (child->text(2) == "int list")
 
928
      {
 
929
        param_->setValue(path, IntList::create(rlist), description, tag_list);
 
930
        String restrictions = child->data(2, Qt::UserRole).toString();
 
931
        vector<String> parts;
 
932
        if (restrictions.split(' ', parts))
 
933
        {
 
934
          if (parts[0] != "")
 
935
          {
 
936
            param_->setMinInt(path, parts[0].toInt());
 
937
          }
 
938
          if (parts[1] != "")
 
939
          {
 
940
            param_->setMaxInt(path, parts[1].toInt());
 
941
          }
 
942
        }
 
943
      }
 
944
 
 
945
      // set description node description if the prefix matches
 
946
      for (map<String, String>::const_iterator it = section_descriptions.begin(); it != section_descriptions.end(); ++it)
 
947
      {
 
948
        if (path.hasPrefix(it->first))
 
949
        {
 
950
          param_->setSectionDescription(it->first, it->second);
 
951
        }
 
952
      }
 
953
      section_descriptions.clear();
 
954
    }
 
955
 
 
956
    for (Int i = 0; i < child->childCount(); ++i)
 
957
    {
 
958
      storeRecursive_(child->child(i), path, section_descriptions);     //whole tree recursively
 
959
    }
 
960
  }
 
961
 
 
962
  void ParamEditor::setModified(bool is_modified)
 
963
  {
 
964
    if (is_modified != modified_)
 
965
    {
 
966
      modified_ = is_modified;
 
967
      emit modified(modified_);
 
968
    }
 
969
  }
 
970
 
 
971
  bool ParamEditor::isModified() const
 
972
  {
 
973
    return modified_;
 
974
  }
 
975
 
 
976
  void ParamEditor::toggleAdvancedMode(bool advanced)
 
977
  {
 
978
    advanced_mode_ = advanced;
 
979
 
 
980
    stack<QTreeWidgetItem *> stack, node_stack;
 
981
 
 
982
    //show/hide items
 
983
    stack.push(tree_->invisibleRootItem());
 
984
    while (!stack.empty())
 
985
    {
 
986
      QTreeWidgetItem * current = stack.top();
 
987
      stack.pop();
 
988
 
 
989
      Int type = current->data(0, Qt::UserRole).toInt();
 
990
      if (type != NODE)     //ITEM
 
991
      {
 
992
        if (advanced_mode_ && type == ADVANCED_ITEM)       //advanced mode
 
993
        {
 
994
          current->setHidden(false);
 
995
        }
 
996
        else if (!advanced_mode_ && type == ADVANCED_ITEM)       //Normal mode
 
997
        {
 
998
          current->setHidden(true);
 
999
        }
 
1000
      }
 
1001
      else       //NODE
 
1002
      {
 
1003
        for (Int i = 0; i < current->childCount(); ++i)
 
1004
        {
 
1005
          stack.push(current->child(i));
 
1006
        }
 
1007
 
 
1008
        if (advanced_mode_)
 
1009
        {
 
1010
          current->setHidden(false);           //show all nodes in advanced mode
 
1011
        }
 
1012
        else
 
1013
        {
 
1014
          node_stack.push(current);           //store node pointers in normal mode
 
1015
        }
 
1016
      }
 
1017
    }
 
1018
 
 
1019
    //hide sections that have no visible items in normal mode
 
1020
    while (!node_stack.empty())
 
1021
    {
 
1022
      QTreeWidgetItem * current = node_stack.top();
 
1023
      node_stack.pop();
 
1024
 
 
1025
      bool has_visible_children = false;
 
1026
      for (Int i = 0; i < current->childCount(); ++i)
 
1027
      {
 
1028
        if (!current->child(i)->isHidden())
 
1029
        {
 
1030
          has_visible_children = true;
 
1031
          break;
 
1032
        }
 
1033
      }
 
1034
      if (!has_visible_children)
 
1035
      {
 
1036
        current->setHidden(true);
 
1037
      }
 
1038
    }
 
1039
 
 
1040
    //resize columns
 
1041
    tree_->resizeColumnToContents(0);
 
1042
    tree_->resizeColumnToContents(1);
 
1043
    tree_->resizeColumnToContents(2);
 
1044
    tree_->resizeColumnToContents(3);
 
1045
  }
984
1046
 
985
1047
} // namespace OpenMS