Isis 3 Programmer Reference
BundleObservationView.cpp
Go to the documentation of this file.
1 
22 #include "BundleObservationView.h"
23 
24 #include <QDebug>
25 #include <QFile>
26 #include <QFontDatabase>
27 #include <QHeaderView>
28 #include <QSizePolicy>
29 #include <QStandardItem>
30 #include <QStandardItemModel>
31 #include <QString>
32 #include <QStringList>
33 #include <QTableView>
34 #include <QTextEdit>
35 #include <QTextStream>
36 #include <QVBoxLayout>
37 
38 
39 namespace Isis {
40 
47  AbstractProjectItemView(parent) {
48 
49  if (fileItem->fileName().contains(".csv")) {
50  displayCsvFile(fileItem);
51  }
52  else if (fileItem->fileName().contains(".txt")) {
53  displayTextFile(fileItem);
54  }
55  }
56 
57 
65 
66  if (!QFile::exists(fileItem->fileName())) {
67  return;
68  }
69 
70  QFile file(fileItem->fileName());
71  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
72  return;
73  }
74 
75  int numHeaderLines = 3;
76  if (fileItem->fileName().contains("images")) {
77  numHeaderLines = 2;
78  }
79 
80  QTextStream in(&file); // read to text stream
81 
82  // read and populate header from first two or three lines
83  QString header1;
84  QString header2;
85  QString header3;
86  QStringList lineToken1;
87  QStringList lineToken2;
88  QStringList lineToken3;
89 
90  header1 = in.readLine();
91  lineToken1 = header1.split(",");
92  header2 = in.readLine();
93  lineToken2 = header2.split(",");
94 
95  if (numHeaderLines == 2) {
96  for (int i = 0; i < lineToken1.size(); i++) {
97  QString t1 = lineToken1.at(i);
98  QString t2 = lineToken2.at(i);
99  QString head = t1 + "\n" + t2;
100  QStandardItem *v1 = new QStandardItem(head);
101  model->setHorizontalHeaderItem(i,v1);
102  }
103  }
104  if (numHeaderLines == 3) {
105  header3 = in.readLine();
106  lineToken3 = header3.split(",");
107 
108  lineToken1.append("");
109  lineToken2.append("");
110 
111  for (int i = 0; i < lineToken3.size(); i++) {
112  QString t1 = lineToken1.at(i);
113  QString t2 = lineToken2.at(i);
114  QString t3 = lineToken3.at(i);
115  QString head = t1 + "\n" + t2 + "\n" + t3;
116  QStandardItem *v1 = new QStandardItem(head);
117  model->setHorizontalHeaderItem(i,v1);
118  }
119  }
120 
121  // populate remainder of table
122  int lineindex = 0;
123  while (!in.atEnd()) {
124  QString fileLine = in.readLine();
125 
126  // parse line into separate pieces(tokens) with "," as the delimiter
127  QStringList lineToken = fileLine.split(",", QString::SkipEmptyParts);
128 
129  bool rejected = false;
130  if (lineToken.at(lineToken.size()-1) == "*") {
131  rejected = true;
132  }
133 
134  // load parsed data to model accordingly
135  for (int i = 0; i < lineToken.size(); i++) {
136  QString value = lineToken.at(i);
137 
138  QStandardItem *item = new QStandardItem(value);
139 
140  if (rejected) {
141  item->setData(QColor(200,0,0), Qt::BackgroundRole);
142  }
143 
144  model->setItem(lineindex, i, item);
145  }
146  lineindex++;
147  }
148 
149  file.close();
150 
151  QTableView *qtable=new QTableView();
152  qtable->setModel(model);
153  qtable->setSortingEnabled(true);
154 
155  // resizes to contents based on entire column
156  // NOTE: QHeaderView::ResizeToContents does not allow user to resize by dragging column divider
157  qtable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
158 
159  setCentralWidget(qtable);
160 
161  QSizePolicy policy = sizePolicy();
162  policy.setHorizontalPolicy(QSizePolicy::Expanding);
163  policy.setVerticalPolicy(QSizePolicy::Expanding);
164  setSizePolicy(policy);
165  }
166 
167 
174 
175  if (!QFile::exists(fileItem->fileName())) {
176  return;
177  }
178 
179  QFile file(fileItem->fileName());
180  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
181  return;
182  }
183 
184  QTextStream in(&file);
185  QTextEdit *qText=new QTextEdit();
186 
187  // From QFontDatabase::systemFont(SystemFont type) method description: returns most adequate
188  // font for a given typecase (here FixedFont) for proper integration with system's look and
189  // feel.
190  const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
191  qText->setFontFamily(fixedFont.family());
192 
193  while (!in.atEnd()) {
194  qText->append(in.readLine());
195  }
196 
197  file.close();
198 
199  setCentralWidget(qText);
200  qText->moveCursor(QTextCursor::Start);
201 
202  QSizePolicy policy = sizePolicy();
203  policy.setHorizontalPolicy(QSizePolicy::Expanding);
204  policy.setVerticalPolicy(QSizePolicy::Expanding);
205  setSizePolicy(policy);
206  }
207 
208 
213  }
214 }
void displayTextFile(FileItemQsp fileItem)
Creates a view showing a text file from BundleSolutionInfo.
void displayCsvFile(FileItemQsp fileItem)
Creates a view showing the CSV file from BundleSolutionInfo.
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt&#39;s model-view framework...
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
BundleObservationView(FileItemQsp fileItem, QWidget *parent=0)
Creates a view showing the CSV or text files from BundleSolutionInfo.
void setItem(int row, ProjectItem *item)
Sets the item at the top-level row.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual ProjectItemModel * model()
Returns the model used by the view.