QSS Solver GUI  4.5.3
treemodel.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #include <QDir>
21 #include <QFileInfo>
22 
23 #include "treemodel.hpp"
24 #include "comboboxdelegate.hpp"
25 
26 TreeModel::TreeModel(const QStringList &headers, QObject *parent) : QStandardItemModel(parent) { setHorizontalHeaderLabels(headers); }
27 
29 
30 Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
31 {
32  if (!index.isValid()) return 0;
33  if (index.column() == 0) {
34  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
35  } else {
36  return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
37  }
38 }
39 
40 void TreeModel::addFiles(QString dir)
41 {
42  QDir d(dir);
43  QFileInfoList fil = d.entryInfoList(QStringList("*.dat"));
44  if (fil.isEmpty()) return;
45  QStringList lines;
46  foreach (QFileInfo f, fil) {
47  lines << f.baseName();
48  }
49  // Add file header.
50  QStandardItem *headData = new QStandardItem();
51  headData->setText(d.dirName());
52  int number = 0;
53  while (number < lines.count()) {
54  QString lineData = lines[number];
55  if (!lineData.isEmpty()) {
56  QStandardItem *var = new QStandardItem();
57  var->setText(lines[number]);
58  var->setCheckable(true);
59  var->setCheckState(Qt::Unchecked);
60  QStandardItem *settings = new QStandardItem("lines");
61  QList<QStandardItem *> childs;
62  childs << new QStandardItem() << var << settings;
63  headData->appendRow(childs);
64  }
65  number++;
66  }
67  appendRow(headData);
68 }
treemodel.hpp
TreeModel::TreeModel
TreeModel(const QStringList &headers, QObject *parent=0)
Definition: treemodel.cpp:26
TreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: treemodel.cpp:30
comboboxdelegate.hpp
TreeModel::~TreeModel
~TreeModel()
Definition: treemodel.cpp:28
TreeModel::addFiles
void addFiles(QString dir)
Definition: treemodel.cpp:40