Added gui options for wireframe, and colour coding
[tecorrec.git] / geo / tcLandsatMetaData.cpp
blob24dbfb8478145cef27dbdd1dfcc61889fe0a0674
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec 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 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec 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 Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcLandsatMetaData.cpp
22 * @brief Landsat metadata file.
25 #include "tcLandsatMetaData.h"
27 #include <QFile>
28 #include <QRegExp>
30 #include <QtDebug>
33 * Constructors + destructor
36 /// Load metadata from a file.
37 tcLandsatMetaData::tcLandsatMetaData(QFile& file)
39 static QRegExp regexp("^\\s*(\\w+)\\s*=\\s*(\"(.*)\"|(\\S(.*\\S)?))\\s*$");
40 static QRegExp end("^\\s*END\\s*$");
41 static QRegExp blank("^\\s*$");
42 while (!file.atEnd())
44 QByteArray line = file.readLine();
45 if (regexp.exactMatch(line))
47 QString name = regexp.cap(1);
48 if ("GROUP" == name)
50 name = regexp.cap(2);
51 if (m_groups.contains(name))
53 delete m_groups[name];
54 qDebug() << "Landsat meta data has conflicting groups:" << line;
56 tcLandsatMetaData* newMeta = new tcLandsatMetaData(file);
57 m_groups[name] = newMeta;
59 else if ("END_GROUP" == name)
61 return;
63 else
65 QVariant value;
66 QString valueStr = regexp.cap(3);
67 if (valueStr.isEmpty())
69 valueStr = regexp.cap(4);
70 bool ok;
71 double d = valueStr.toDouble(&ok);
72 if (ok)
74 value = d;
76 else
78 value = valueStr;
81 else
83 value = valueStr;
85 m_values[name] = value;
88 else if (end.exactMatch(line))
90 return;
92 else if (blank.exactMatch(line))
95 else
97 qDebug() << "Parsing error reading landsat meta data:" << line;
102 /// Destructor.
103 tcLandsatMetaData::~tcLandsatMetaData()
108 * Accessors
111 /// Get the list of group names.
112 QStringList tcLandsatMetaData::groupNames() const
114 return m_groups.keys();
117 /// Get the list of value names.
118 QStringList tcLandsatMetaData::valueNames() const
120 return m_values.keys();
123 /// Access a group.
124 tcLandsatMetaData& tcLandsatMetaData::operator () (const QString& name) const
126 Q_ASSERT(m_groups.contains(name));
127 return *m_groups[name];
130 /// Access a value.
131 QVariant tcLandsatMetaData::operator [] (const QString& name) const
133 if (m_values.contains(name))
135 return m_values[name];
137 else
139 return QVariant();