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);
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);
92 class 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;
114 class 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);
133 class 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<std::string> &lineTokens)
override;
138 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
143 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
145 maxLineNumber = lineNumber + 2;
151 unsigned int getMaxPreviewLineNumber()
const {
152 return maxLineNumber;
155 unsigned int getFirstLineIndex() {
156 return firstLineIndex;
159 void setFirstLineIndex(
unsigned int index) {
160 firstLineIndex = index;
163 int getNbCommentsLines() {
164 return nbCommentsLines;
168 unsigned int maxLineNumber;
169 unsigned int firstLineIndex;
170 bool checkCommentsLines;
180 class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
183 CSVImportConfigurationWidget(QWidget *parent =
nullptr);
184 ~CSVImportConfigurationWidget()
override;
185 bool begin()
override;
186 bool line(
unsigned int row,
const std::vector<std::string> &lineTokens)
override;
187 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
188 void setFirstLineIndex(
int firstLine);
193 void setNewParser(tlp::CSVParser *parser);
200 CSVImportParameters getImportParameters()
const;
204 static const std::set<std::string> &getPropsForTypename(
const std::string &type);
207 void updateWidget(
const std::string &title =
"Generating preview");
209 const std::vector<CSVColumn *> getPropertiesToImport()
const;
211 void updateLineNumbers(
bool resetValues);
213 bool useFirstLineAsPropertyName()
const;
214 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
215 unsigned int rowCount()
const;
216 unsigned int columnCount()
const;
222 unsigned int getFirstLineIndex()
const;
227 unsigned int getLastLineIndex()
const;
234 unsigned int getFirstImportedLineIndex()
const;
239 void clearPropertiesTypeList();
243 void addPropertyToPropertyList(
const std::string &propertyName,
bool isEditable,
244 const std::string &propertyType = std::string(
""));
256 virtual PropertyConfigurationWidget *
257 createPropertyConfigurationWidget(
unsigned int propertyNumber,
const QString &propertyName,
258 bool propertyNameIsEditable,
const std::string &propertyType,
265 QString generateColumnName(
unsigned int col)
const;
270 std::string getColumnType(
unsigned int col)
const;
272 std::vector<PropertyConfigurationWidget *> propertyWidgets;
276 void filterPreviewLineNumber(
bool filter);
277 void previewLineNumberChanged(
int value);
279 void toLineValueChanged(
int value);
281 void updateTableHeaders();
283 void useFirstLineAsHeaderUpdated();
284 void propertyStateChanged(
bool activated);
291 const std::string &guessPropertyDataType(
const std::string &data,
292 const std::string &previousType)
const;
297 const std::string &combinePropertyDataType(
const std::string &previousType,
298 const std::string &newType)
const;
304 const std::string &guessDataType(
const std::string &data)
const;
307 std::vector<std::string> columnHeaderType;
309 std::vector<std::string> columnType;
311 Ui::CSVImportConfigurationWidget *ui;
312 PropertyNameValidator *validator;
313 unsigned int maxLineNumber;
314 unsigned int headerColumnCount;
315 tlp::CSVParser *parser;
316 unsigned int firstLine;
317 bool guessFirstLineIsHeader;
320 #endif // CSVIMPORTCONFIGURATIONWIDGET_H