21#ifndef CSVIMPORTCONFIGURATIONWIDGET_H
22#define CSVIMPORTCONFIGURATIONWIDGET_H
26#include <QTableWidget>
29#include <tulip/CSVContentHandler.h>
30#include <tulip/CSVGraphImport.h>
31#include <tulip/tulipconf.h>
34class Ui_CSVPropertyDialog;
37class CSVImportConfigurationWidget;
41class PropertyNameValidator;
46class TLP_QT_SCOPE PropertyConfigurationWidget :
public QWidget,
public CSVColumn {
49 PropertyConfigurationWidget(
unsigned int propertyNumber,
const QString &propertyName,
50 bool propertyNameIsEditable,
const std::string &PropertyType,
51 PropertyNameValidator *validator, QWidget *parent =
nullptr);
58 const std::string &getPropertyType()
const;
62 void setPropertyType(
const std::string &propertyType);
64 QString getPropertyName()
const;
66 void setPropertyName(
const QString &name);
70 unsigned int getPropertyNumber()
const;
73 PropertyNameValidator *propertyNameValidator;
74 QPushButton *propertyEditButton;
75 Ui_CSVPropertyDialog *ui;
77 unsigned int propertyNumber;
80 void showPropertyCreationDialog();
81 void typeCBChanged(
const QString &index);
83 void delCurrentException();
86 void stateChange(
bool state);
92class TLP_QT_SCOPE PropertyNameValidator :
public QValidator {
94 PropertyNameValidator(
const std::vector<PropertyConfigurationWidget *> &widgets,
95 QObject *parent =
nullptr)
96 : QValidator(parent), widgets(widgets) {}
97 ~PropertyNameValidator()
override {}
102 QValidator::State validate(QString &input,
int &pos)
const override;
105 void setCurrentIndex(
unsigned int index) {
106 currentIndex = index;
110 unsigned int currentIndex;
111 const std::vector<PropertyConfigurationWidget *> &widgets;
114class CSVTableHeader :
public QHeaderView {
117 const std::vector<PropertyConfigurationWidget *> &widgets;
120 CSVTableHeader(QWidget *parent, std::vector<PropertyConfigurationWidget *> &propertyWidgets);
123 void paintSection(QPainter *painter,
const QRect &rect,
int logicalIndex)
const override;
126 void checkBoxPressed(
int logicalIndex);
133class TLP_QT_SCOPE CSVTableWidget :
public QTableWidget,
public CSVContentHandler {
135 CSVTableWidget(QWidget *parent =
nullptr);
136 bool begin()
override;
137 bool line(
unsigned int row,
const std::vector<CSVToken> &lineTokens)
override;
138 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
143 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
145 maxLineNumber = lineNumber + 1;
148 unsigned int getFirstLineIndex() {
149 return firstLineIndex;
152 void setFirstLineIndex(
unsigned int index) {
153 firstLineIndex = index;
156 int getNbCommentsLines() {
157 return nbCommentsLines;
161 unsigned int maxLineNumber;
162 unsigned int firstLineIndex;
163 bool checkCommentsLines;
173class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
176 CSVImportConfigurationWidget(QWidget *parent =
nullptr);
177 ~CSVImportConfigurationWidget()
override;
178 bool begin()
override;
179 bool line(
unsigned int row,
const std::vector<CSVToken> &lineTokens)
override;
180 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
181 void setFirstLineIndex(
int firstLine);
186 void setNewParser(tlp::CSVParser *parser);
193 CSVImportParameters getImportParameters()
const;
197 static const std::set<std::string> &getPropsForTypename(
const std::string &type);
200 void updateWidget(
const std::string &title =
"Generating preview");
202 const std::vector<CSVColumn *> getPropertiesToImport()
const;
204 void updateLineNumbers(
bool resetValues);
206 bool useFirstLineAsPropertyName()
const;
207 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
208 unsigned int rowCount()
const;
209 unsigned int columnCount()
const;
215 unsigned int getFirstLineIndex()
const;
220 unsigned int getLastLineIndex()
const;
227 unsigned int getFirstImportedLineIndex()
const;
232 void clearPropertiesTypeList();
236 void addPropertyToPropertyList(
const std::string &propertyName,
bool isEditable,
237 const std::string &propertyType = std::string(
""));
249 virtual PropertyConfigurationWidget *
250 createPropertyConfigurationWidget(
unsigned int propertyNumber,
const QString &propertyName,
251 bool propertyNameIsEditable,
const std::string &propertyType,
258 QString generateColumnName(
unsigned int col)
const;
263 std::string getColumnType(
unsigned int col)
const;
265 std::vector<PropertyConfigurationWidget *> propertyWidgets;
269 void filterPreviewLineNumber(
bool filter);
270 void previewLineNumberChanged(
int value);
272 void toLineValueChanged(
int value);
274 void updateTableHeaders();
276 void useFirstLineAsHeaderUpdated();
277 void propertyStateChanged(
bool activated);
284 const std::string &guessPropertyDataType(
const std::string &data,
285 const std::string &previousType)
const;
290 const std::string &combinePropertyDataType(
const std::string &previousType,
291 const std::string &newType)
const;
297 const std::string &guessDataType(
const std::string &data)
const;
300 void setMaxPreviewLineNumber(
unsigned int lineNumber);
303 std::vector<std::string> columnHeaderType;
305 std::vector<std::string> columnType;
307 Ui::CSVImportConfigurationWidget *ui;
308 PropertyNameValidator *validator;
309 unsigned int maxLineNumber;
310 unsigned int headerColumnCount;
311 tlp::CSVParser *parser;
312 unsigned int firstLine;
313 bool guessFirstLineIsHeader;
314 bool keepPropertyWidgets;