21 #ifndef CSVIMPORTCONFIGURATIONWIDGET_H
22 #define CSVIMPORTCONFIGURATIONWIDGET_H
26 #include <QTableWidget>
27 #include <QHeaderView>
29 #include <tulip/CSVContentHandler.h>
30 #include <tulip/CSVGraphImport.h>
31 #include <tulip/tulipconf.h>
34 class Ui_CSVPropertyDialog;
37 class CSVImportConfigurationWidget;
41 class PropertyNameValidator;
46 class 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,
bool defValue =
false);
64 QString getPropertyName()
const;
66 void setPropertyName(
const QString &name,
bool defValue =
false);
70 unsigned int getPropertyNumber()
const;
73 PropertyNameValidator *propertyNameValidator;
74 QPushButton *propertyEditButton;
75 Ui_CSVPropertyDialog *ui;
77 unsigned int propertyNumber;
78 void addException(
const std::string &value, CSVColumn::Action action);
81 void showPropertyCreationDialog();
82 void typeCBChanged(
const QString &index);
85 void delCurrentException();
88 void stateChange(
bool state);
94 class TLP_QT_SCOPE PropertyNameValidator :
public QValidator {
96 PropertyNameValidator(
const std::vector<PropertyConfigurationWidget *> &widgets,
97 QObject *parent =
nullptr)
98 : QValidator(parent), widgets(widgets) {}
99 ~PropertyNameValidator()
override {}
104 QValidator::State validate(QString &input,
int &pos)
const override;
107 void setCurrentIndex(
unsigned int index) {
108 currentIndex = index;
112 unsigned int currentIndex;
113 const std::vector<PropertyConfigurationWidget *> &widgets;
116 class CSVTableHeader :
public QHeaderView {
119 const std::vector<PropertyConfigurationWidget *> &widgets;
122 CSVTableHeader(QWidget *parent, std::vector<PropertyConfigurationWidget *> &propertyWidgets);
125 void paintSection(QPainter *painter,
const QRect &rect,
int logicalIndex)
const override;
128 void checkBoxPressed(
int logicalIndex);
135 class TLP_QT_SCOPE CSVTableWidget :
public QTableWidget,
public CSVContentHandler {
137 CSVTableWidget(QWidget *parent =
nullptr);
138 bool begin()
override;
139 bool line(
unsigned int row,
const std::vector<CSVToken> &lineTokens)
override;
140 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
145 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
147 maxLineNumber = lineNumber + 1;
150 unsigned int getFirstLineIndex() {
151 return firstLineIndex;
154 void setFirstLineIndex(
unsigned int index) {
155 firstLineIndex = index;
158 int getNbCommentsLines() {
159 return nbCommentsLines;
163 unsigned int maxLineNumber;
164 unsigned int firstLineIndex;
165 bool checkCommentsLines;
175 class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
178 CSVImportConfigurationWidget(QWidget *parent =
nullptr);
179 ~CSVImportConfigurationWidget()
override;
180 bool begin()
override;
181 bool line(
unsigned int row,
const std::vector<CSVToken> &lineTokens)
override;
182 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
183 void setFirstLineIndex(
int firstLine);
188 void setNewParser(tlp::CSVParser *parser);
195 CSVImportParameters getImportParameters()
const;
199 static const std::set<std::string> &getPropsForTypename(
const std::string &type);
202 void updateWidget(
const std::string &title =
"Generating preview");
204 const std::vector<CSVColumn *> getPropertiesToImport()
const;
206 void updateLineNumbers(
bool resetValues);
208 bool useFirstLineAsPropertyName()
const;
209 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
210 unsigned int rowCount()
const;
211 unsigned int columnCount()
const;
217 unsigned int getFirstLineIndex()
const;
222 unsigned int getLastLineIndex()
const;
229 unsigned int getFirstImportedLineIndex()
const;
234 void clearPropertiesTypeList();
238 void addPropertyToPropertyList(
const std::string &propertyName,
bool isEditable,
239 const std::string &propertyType = std::string(
""));
251 virtual PropertyConfigurationWidget *
252 createPropertyConfigurationWidget(
unsigned int propertyNumber,
const QString &propertyName,
253 bool propertyNameIsEditable,
const std::string &propertyType,
260 QString generateColumnName(
unsigned int col)
const;
265 std::string getColumnType(
unsigned int col)
const;
267 std::vector<PropertyConfigurationWidget *> propertyWidgets;
271 void filterPreviewLineNumber(
bool filter);
272 void previewLineNumberChanged(
int value);
274 void toLineValueChanged(
int value);
276 void updateTableHeaders();
278 void useFirstLineAsHeaderUpdated();
279 void propertyStateChanged(
bool activated);
286 const std::string &guessPropertyDataType(
const std::string &data,
287 const std::string &previousType)
const;
292 const std::string &combinePropertyDataType(
const std::string &previousType,
293 const std::string &newType)
const;
299 const std::string &guessDataType(
const std::string &data)
const;
302 void setMaxPreviewLineNumber(
unsigned int lineNumber);
305 std::vector<std::string> columnHeaderType;
307 std::vector<std::string> columnType;
309 Ui::CSVImportConfigurationWidget *ui;
310 PropertyNameValidator *validator;
311 unsigned int maxLineNumber;
312 unsigned int headerColumnCount;
313 tlp::CSVParser *parser;
314 unsigned int firstLine;
315 bool guessFirstLineIsHeader;
316 bool keepPropertyWidgets;