41
41
42
42
#include < openstudio/utilities/core/Assert.hpp>
43
43
#include < openstudio/utilities/core/Filesystem.hpp>
44
+ #include < openstudio/utilities/core/Compare.hpp>
44
45
45
46
#include < QGridLayout>
46
47
#include < QLabel>
50
51
#include < QTextStream>
51
52
#include < QPlainTextEdit>
52
53
#include < QPushButton>
54
+ #include < Qt> // Qt namespace, for SplitBehaviorFlags
53
55
54
56
namespace openstudio {
55
57
@@ -310,7 +312,14 @@ void ScheduleFileInspectorView::attach(openstudio::model::ScheduleFile& sch) {
310
312
311
313
// OSIntegerEdit2
312
314
m_columnNumber->bind (*m_sch, IntGetter (std::bind (&model::ScheduleFile::columnNumber, m_sch.get_ptr ())),
313
- boost::optional<IntSetter>(std::bind (&model::ScheduleFile::setColumnNumber, m_sch.get_ptr (), std::placeholders::_1)));
315
+ boost::optional<IntSetter>([this ](int value) -> bool {
316
+ bool result = m_sch->setColumnNumber (value);
317
+ if (result) {
318
+ refreshContent ();
319
+ refreshError ();
320
+ }
321
+ return result;
322
+ }));
314
323
315
324
m_rowstoSkipatTop->bind (*m_sch, IntGetter (std::bind (&model::ScheduleFile::rowstoSkipatTop, m_sch.get_ptr ())),
316
325
boost::optional<IntSetter>([this ](int value) -> bool {
@@ -433,6 +442,21 @@ void ScheduleFileInspectorView::refreshContent() {
433
442
if (openstudio::filesystem::is_regular_file (fpath)) {
434
443
const int rowstoSkipatTop = m_sch->rowstoSkipatTop ();
435
444
445
+ const int colNum = m_sch->columnNumber () - 1 ; // Turn 1-indexed to 0-indexed
446
+
447
+ QString sep;
448
+ Qt::SplitBehavior behavior = Qt::KeepEmptyParts;
449
+ if (openstudio::istringEqual (m_sch->columnSeparator (), " Comma" )) {
450
+ sep = ' ,' ;
451
+ } else if (openstudio::istringEqual (m_sch->columnSeparator (), " Tab" )) {
452
+ sep = ' \t ' ;
453
+ } else if (openstudio::istringEqual (m_sch->columnSeparator (), " Space" )) {
454
+ sep = ' ' ; // QRegularExpression("\\s+")
455
+ behavior = Qt::SkipEmptyParts;
456
+ } else if (openstudio::istringEqual (m_sch->columnSeparator (), " Semicolon" )) {
457
+ sep = ' ;' ;
458
+ } // Fixed: not handled
459
+
436
460
if (m_lines.isEmpty ()) {
437
461
m_lines.clear ();
438
462
@@ -453,20 +477,34 @@ void ScheduleFileInspectorView::refreshContent() {
453
477
454
478
const int read_n_lines = std::min (std::max (rowstoSkipatTop + 2 , 10 ), static_cast <int >(m_lines.size ()));
455
479
480
+ auto constructStyledLine = [&sep, &behavior, &colNum](const QString& line, const QString& color) {
481
+ QStringList vals = line.split (sep, behavior);
482
+ QString str;
483
+ for (int j = 0 ; j < vals.size (); ++j) {
484
+ QString val = vals[j];
485
+ if (j == colNum) {
486
+ str.append (QString (" <span style='color: %1'>%2</span>" ).arg (color).arg (val));
487
+ } else {
488
+ str.append (QString (" <span style='color: gray'>%1</span>" ).arg (val));
489
+ }
490
+ if (j < vals.size () - 1 ) {
491
+ str.append (" ," );
492
+ }
493
+ }
494
+ return str;
495
+ };
496
+
456
497
int curLine = 0 ;
457
498
for (const QString& line : m_lines) {
458
499
if (curLine < rowstoSkipatTop) {
459
- m_contentLines->appendHtml (QString ( " <span style='color: gray'>%1</span> " ). arg (line ));
460
- } else if (m_displayAllContent || (curLine < read_n_lines)) {
461
- m_contentLines->appendHtml (QString ( " <span style='color: green'>%1</span> " ). arg (line ));
500
+ m_contentLines->appendHtml (constructStyledLine (line, " black " ));
501
+ } else if (m_displayAllContent || (curLine < read_n_lines) || (curLine > m_lines. size () - 5 ) ) {
502
+ m_contentLines->appendHtml (constructStyledLine (line, " green" ));
462
503
} else if (curLine == read_n_lines) {
463
504
m_contentLines->appendHtml (" <strong>[...]</strong>" );
464
- } else if (curLine > m_lines.size () - 5 ) {
465
- m_contentLines->appendHtml (QString (" <span style='color: green'>%1</span>" ).arg (line));
466
505
}
467
506
++curLine;
468
507
}
469
-
470
508
} else {
471
509
m_contentLines->setPlainText (QString (" File not found at '%1'" ).arg (toQString (fpath)));
472
510
}
0 commit comments