Skip to content

Commit

Permalink
Add CSV loader date-time format help dialog (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartimaeus- authored Dec 18, 2022
1 parent 30d424e commit 5edd5f0
Show file tree
Hide file tree
Showing 7 changed files with 734 additions and 9 deletions.
6 changes: 5 additions & 1 deletion plotjuggler_plugins/DataLoadCSV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ include_directories( ../ )
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)

QT5_WRAP_UI ( UI_SRC dataload_csv.ui )
QT5_WRAP_UI ( UI_SRC
dataload_csv.ui
datetimehelp.ui
)

SET( SRC
dataload_csv.cpp
datetimehelp.cpp
)

add_library(DataLoadCSV SHARED ${SRC} ${UI_SRC} )
Expand Down
8 changes: 8 additions & 0 deletions plotjuggler_plugins/DataLoadCSV/dataload_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QInputDialog>
#include <QPushButton>
#include "QSyntaxStyle"
#include "datetimehelp.h"


#include <QStandardItemModel>
Expand Down Expand Up @@ -97,6 +98,9 @@ DataLoadCSV::DataLoadCSV()
_ui = new Ui::DialogCSV();
_ui->setupUi(_dialog);

_dateTime_dialog = new DateTimeHelp(_dialog);


_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

connect(_ui->radioButtonSelect, &QRadioButton::toggled, this, [this](bool checked) {
Expand All @@ -117,6 +121,9 @@ DataLoadCSV::DataLoadCSV()
connect(_ui->checkBoxDateFormat, &QCheckBox::toggled, this,
[this](bool checked) { _ui->lineEditDateFormat->setEnabled(checked); });

connect(_ui->dateTimeHelpButton,&QPushButton::clicked, this, [this](){
_dateTime_dialog->show();
});
_ui->rawText->setHighlighter(&_csvHighlighter);

QSizePolicy sp_retain = _ui->tableView->sizePolicy();
Expand All @@ -134,6 +141,7 @@ DataLoadCSV::~DataLoadCSV()
{
delete _ui;
delete _dialog;
delete _dateTime_dialog;
}

const std::vector<const char*>& DataLoadCSV::compatibleFileExtensions() const
Expand Down
4 changes: 4 additions & 0 deletions plotjuggler_plugins/DataLoadCSV/dataload_csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

using namespace PJ;

class DateTimeHelp;

class DataLoadCSV : public DataLoader
{
Q_OBJECT
Expand Down Expand Up @@ -52,8 +54,10 @@ class DataLoadCSV : public DataLoader

QDialog* _dialog;
Ui::DialogCSV* _ui;
DateTimeHelp *_dateTime_dialog;

QStandardItemModel *_model;

bool multiple_columns_warning_ = true;

};
36 changes: 28 additions & 8 deletions plotjuggler_plugins/DataLoadCSV/dataload_csv.ui
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,34 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Visit &lt;a href=&quot;https://doc.qt.io/qt-5/qtime.html#toString&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;this link&lt;/span&gt;&lt;/a&gt; to learn more about the Date-Time format.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="dateTimeHelpButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Date Format Help</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
Expand Down
64 changes: 64 additions & 0 deletions plotjuggler_plugins/DataLoadCSV/datetimehelp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "datetimehelp.h"
#include "ui_datetimehelp.h"

#include <QScrollBar>

//Source: https://stackoverflow.com/a/42458736
void verticalResizeTableViewToContents(QTableView *tableView)
{
int count=tableView->verticalHeader()->count();
int scrollBarHeight = 0;
if(tableView->horizontalScrollBar()->isVisible())
{
scrollBarHeight=tableView->horizontalScrollBar()->height();
}
int horizontalHeaderHeight=tableView->horizontalHeader()->height();
int rowTotalHeight=0;
for (int i = 0; i < count; ++i) {
// 2018-03 edit: only account for row if it is visible
if (!tableView->verticalHeader()->isSectionHidden(i)) {
rowTotalHeight+=tableView->verticalHeader()->sectionSize(i);
}
}
tableView->setMinimumHeight(horizontalHeaderHeight+rowTotalHeight+scrollBarHeight);
}

DateTimeHelp::DateTimeHelp(QDialog *parent) :
QDialog(parent), ui(new Ui::DateTimeHelp), _parent(parent)
{
ui->setupUi(this);

verticalResizeTableViewToContents(ui->dateFormatTable);
verticalResizeTableViewToContents(ui->timeFormatTable);

refreshExample();

connect(ui->exampleDateTimeDateTimeEdit,&QDateTimeEdit::dateTimeChanged,this, [this](){
refreshExample();
});

connect(ui->exampleFormatStringLineEdit,&QLineEdit::textChanged,this, [this](){
refreshExample();
});

connect(_parent,&QDialog::finished,this,[this](){
if(ui->autoCloseCheckBox->isChecked())
{
accept();
}

});

}

DateTimeHelp::~DateTimeHelp()
{
delete ui;
}

void DateTimeHelp::refreshExample()
{
auto dateTime = ui->exampleDateTimeDateTimeEdit->dateTime();
auto formatString = ui->exampleFormatStringLineEdit->text();
ui->resultLineEdit->setText(dateTime.toString(formatString));
}
26 changes: 26 additions & 0 deletions plotjuggler_plugins/DataLoadCSV/datetimehelp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef DATETIMEHELP_H
#define DATETIMEHELP_H

#include <QDialog>

namespace Ui {
class DateTimeHelp;
}

class DateTimeHelp : public QDialog
{
Q_OBJECT

public:
explicit DateTimeHelp(QDialog *parent = nullptr);
~DateTimeHelp();

void refreshExample();

private:
Ui::DateTimeHelp *ui;

QDialog* _parent;
};

#endif // DATETIMEHELP_H
Loading

0 comments on commit 5edd5f0

Please sign in to comment.