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