filesearchpath.cpp
1 //------------------------------------------------------------------------------
2 // filesearchpath.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2013 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "filesearchpath.h"
24 
25 #include <QStringList>
26 
27 FileSearchPath::FileSearchPath()
28 {
29  recursive_ = false;
30 }
31 
32 FileSearchPath::FileSearchPath(const QString& path)
33 {
34  path_ = path;
35  recursive_ = false;
36 }
37 
38 QList<FileSearchPath> FileSearchPath::fromStringList(const QStringList& collection)
39 {
40  QList<FileSearchPath> result;
41  foreach (QString path, collection)
42  {
43  result << path;
44  }
45  return result;
46 }
47 
48 FileSearchPath FileSearchPath::fromVariant(const QVariant& var)
49 {
50  FileSearchPath result;
51  QVariantList list = var.toList();
52  if (list.size() >= 1 && list.size() <= 2)
53  {
54  result.setPath(list[0].toString());
55  if (list.size() == 2)
56  {
57  result.setRecursive(list[1].toBool());
58  }
59  }
60  return result;
61 }
62 
63 QList<FileSearchPath> FileSearchPath::fromVariantList(const QVariantList& collection)
64 {
65  QList<FileSearchPath> result;
66  foreach (const QVariant& variant, collection)
67  {
68  result << fromVariant(variant);
69  }
70  return result;
71 }
72 
73 bool FileSearchPath::isValid() const
74 {
75  return path_.isNull();
76 }
77 
78 QVariant FileSearchPath::toVariant() const
79 {
80  QVariantList var;
81  var << path_;
82  var << recursive_;
83  return var;
84 }
85 
86 QVariantList FileSearchPath::toVariantList(const QList<FileSearchPath>& collection)
87 {
88  QVariantList result;
89  foreach (const FileSearchPath& path, collection)
90  {
91  result << path.toVariant();
92  }
93  return result;
94 }