7 #include <QProgressDialog> 24 QTextStream inA(file);
26 QString first_line = inA.readLine();
27 QString second_line = inA.readLine();
29 QStringList firstline_items = first_line.split(
csv_separator);
32 const int columncount = firstline_items.count();
34 for (
int i = 0; i < firstline_items.size(); i++)
37 QString field_name(firstline_items[i]);
39 if (field_name.isEmpty())
41 field_name = QString(
"_Column_%1").arg(i);
43 ordered_names.push_back(field_name.toStdString());
53 table_size.setWidth(columncount);
54 table_size.setHeight(linecount);
60 bool use_provided_configuration =
false;
64 use_provided_configuration =
true;
68 const int TIME_INDEX_NOT_DEFINED = -2;
70 int time_index = TIME_INDEX_NOT_DEFINED;
73 file.open(QFile::ReadOnly);
75 std::vector<std::string> column_names;
77 const QSize table_size =
parseHeader(&file, column_names);
78 const int tot_lines = table_size.height() - 1;
79 const int columncount = table_size.width();
82 file.open(QFile::ReadOnly);
83 QTextStream inB(&file);
85 std::vector<PlotData*> plots_vector;
87 bool interrupted =
false;
91 QProgressDialog progress_dialog;
92 progress_dialog.setLabelText(
"Loading... please wait");
93 progress_dialog.setWindowModality(Qt::ApplicationModal);
94 progress_dialog.setRange(0, tot_lines - 1);
95 progress_dialog.setAutoClose(
true);
96 progress_dialog.setAutoReset(
true);
97 progress_dialog.show();
103 std::deque<std::string> valid_field_names;
105 for (
unsigned i = 0; i < column_names.size(); i++)
107 const std::string& field_name = (column_names[i]);
111 valid_field_names.push_back(field_name);
112 plots_vector.push_back(&(it->second));
114 if (time_index == TIME_INDEX_NOT_DEFINED && use_provided_configuration)
123 if (time_index == TIME_INDEX_NOT_DEFINED && !use_provided_configuration)
125 valid_field_names.push_front(
"INDEX (auto-generated)");
128 dialog->setWindowTitle(
"Select the time axis");
129 int res = dialog->exec();
131 if (res == QDialog::Rejected)
137 if (selected_item > 0)
139 for (
unsigned i = 0; i < column_names.size(); i++)
141 if (column_names[i] == valid_field_names[selected_item])
144 time_index = selected_item - 1;
153 bool monotonic_warning =
false;
157 QString line = inB.readLine();
160 if (string_items.size() != columncount)
164 double t = linecount;
168 bool is_number =
false;
169 t = string_items[time_index].toDouble(&is_number);
173 QMessageBox::StandardButton reply;
174 reply = QMessageBox::warning(0, tr(
"Error reading file"),
175 tr(
"One of the timestamps is not a valid number. Abort\n"));
181 QMessageBox::StandardButton reply;
182 reply = QMessageBox::warning(0, tr(
"Error reading file"),
183 tr(
"Selected time in not strictly monotonic. Loading will be aborted\n"));
187 else if (t == prev_time)
189 monotonic_warning =
true;
196 for (
int i = 0; i < string_items.size(); i++)
198 bool is_number =
false;
199 double y = string_items[i].toDouble(&is_number);
203 plots_vector[index]->pushBack(point);
208 if (linecount++ % 100 == 0)
210 progress_dialog.setValue(linecount);
211 QApplication::processEvents();
212 if (progress_dialog.wasCanceled())
223 progress_dialog.cancel();
227 if (monotonic_warning)
229 QString message =
"Two consecutive samples had the same X value (i.e. time).\n" 230 "Since PlotJuggler makes the assumption that timeseries are strictly monotonic, you " 231 "might experience undefined behaviours.\n\n" 232 "You have been warned...";
233 QMessageBox::warning(0, tr(
"Warning"), message);
245 QDomElement elem = doc.createElement(
"default");
248 parent_element.appendChild(elem);
254 QDomElement elem = parent_element.firstChildElement(
"default");
257 if (elem.hasAttribute(
"time_axis"))
virtual bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
const QRegExp csv_separator("(\\,|\\;|\\|)")
virtual bool readDataFromFile(PJ::FileLoadInfo *fileload_info, PlotDataMapRef &destination) override
std::vector< const char * > _extensions
std::unordered_map< std::string, PlotData > numeric
std::vector< int > getSelectedRowNumber() const
QSize parseHeader(QFile *file, std::vector< std::string > &ordered_names)
virtual bool xmlLoadState(const QDomElement &parent_element) override
std::unordered_map< std::string, PlotData >::iterator addNumeric(const std::string &name)
std::string _default_time_axis
QDomDocument plugin_config
virtual const std::vector< const char * > & compatibleFileExtensions() const override
typename PlotDataBase< Value >::Point Point