source: ntrip/trunk/GnssCenter/inpedit/tabwidget.cpp@ 5834

Last change on this file since 5834 was 5103, checked in by mervart, 12 years ago
File size: 3.0 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_tabWidget
7 *
8 * Purpose: RTNet Input File
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include "tabwidget.h"
19#include "keyword.h"
20#include "panel.h"
21
22using namespace std;
23using namespace GnssCenter;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_tabWidget::t_tabWidget() : QTabWidget() {
28}
29
30// Destructor
31////////////////////////////////////////////////////////////////////////////
32t_tabWidget::~t_tabWidget() {
33 QMapIterator<QString, t_keyword*> it(_keywords);
34 while (it.hasNext()) {
35 it.next();
36 delete it.value();
37 }
38}
39
40//
41////////////////////////////////////////////////////////////////////////////
42void t_tabWidget::readInputFile(const QString& fileName) {
43
44 _fileName = fileName;
45
46 _staticLines.clear();
47
48 QFile file(_fileName);
49 file.open(QIODevice::ReadOnly | QIODevice::Text);
50 QTextStream inStream(&file);
51
52 int iPanel = 0;
53
54 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
55 QString line = inStream.readLine().trimmed();
56
57 // Skip Comments and empty Lines
58 // -----------------------------
59 if (line.isEmpty() || line[0] == '!') {
60 _staticLines << line;
61 continue;
62 }
63
64 // Read Panels
65 // -----------
66 else if (line[0] == '#' && line.indexOf("BEGIN_PANEL") != -1) {
67 t_panel* panel = new t_panel(line, inStream, &_keywords, _staticLines);
68 if (panel->ok()) {
69 ++iPanel;
70 addTab(panel, QString("Panel %1").arg(iPanel));
71 }
72 else {
73 delete panel;
74 }
75 }
76
77 // Read Keywords
78 // -------------
79 else {
80 t_keyword* keyword = new t_keyword(line, inStream, _staticLines);
81 if (keyword->ok()) {
82 _keywords[keyword->name()] = keyword;
83 }
84 else {
85 delete keyword;
86 }
87 }
88 }
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void t_tabWidget::writeInputFile(const QString& fileName) {
94 QFile file(fileName);
95 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
96 return;
97 }
98 QTextStream out(&file);
99 for (int ii = 0; ii < _staticLines.size(); ii++) {
100 QString tLine = _staticLines[ii].trimmed();
101 if (tLine.isEmpty() || tLine[0] == '!' || tLine[0] == '#') {
102 out << _staticLines[ii] << '\n';
103 }
104 else {
105 if (_keywords.contains(tLine)) {
106 const t_keyword* keyword = _keywords[tLine];
107 if (keyword) {
108 const QStringList& values = keyword->values();
109 out << tLine << ' ' << values.size();
110 if (values.size() != 1) {
111 out << '\n';
112 }
113 for (int ii = 0; ii < values.size(); ii++) {
114 out << " \"" << values[ii] << "\"\n";
115 }
116 }
117 }
118 }
119 }
120}
Note: See TracBrowser for help on using the repository browser.