21 #ifndef CSVIMPORTCONFIGURATIONWIDGET_H
22 #define CSVIMPORTCONFIGURATIONWIDGET_H
26 #include <QTableWidget>
28 #include <tulip/CSVContentHandler.h>
29 #include <tulip/tulipconf.h>
37 class CSVImportConifgurationWidget;
42 class CSVImportParameters;
48 class TLP_QT_SCOPE PropertyConfigurationWidget:
public QWidget {
51 PropertyConfigurationWidget(
unsigned int propertyNumber,
const QString& propertyName,
bool propertyNameIsEditable,
52 const std::string& PropertyType, QWidget* parent = NULL);
56 std::string getPropertyType()
const;
60 void setPropertyType(
const std::string& propertyType);
62 QString getPropertyName()
const;
63 bool getPropertyUsed()
const;
67 void setPropertyNameValidator(QValidator* validator);
68 unsigned int getPropertyNumber()
const;
70 QLineEdit *getNameLineEdit() {
71 return propertyNameLineEdit;
73 QComboBox *getTypeComboBox() {
74 return propertyTypeComboBox;
77 QCheckBox *getCheckBox() {
82 void fillPropertyTypeComboBox();
83 QLineEdit *propertyNameLineEdit;
84 QComboBox *propertyTypeComboBox;
85 QCheckBox *usedCheckBox;
87 unsigned int propertyNumber;
90 void nameEditFinished();
91 void useStateChanged(
int state);
94 void propertyNameChange(QString newName);
95 void stateChange(
bool state);
101 class TLP_QT_SCOPE PropertyNameValidator:
public QValidator {
103 PropertyNameValidator(
const std::vector<PropertyConfigurationWidget*>& widgets,QObject*parent=NULL) :
104 QValidator(parent), widgets(widgets) {
106 virtual ~PropertyNameValidator() {
113 QValidator::State validate(QString & input,
int & pos)
const;
116 const std::vector<PropertyConfigurationWidget*>& widgets;
122 class TLP_QT_SCOPE CSVTableWidget :
public QTableWidget,
public CSVContentHandler {
124 CSVTableWidget(QWidget* parent=NULL);
126 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
127 void end(
unsigned int rowNumber,
unsigned int columnNumber);
131 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
132 maxLineNumber = lineNumber;
138 unsigned int getMaxPreviewLineNumber()
const {
139 return maxLineNumber;
142 unsigned int getFirstLineIndex() {
143 return firstLineIndex;
146 void setFirstLineIndex(
unsigned int index) {
147 firstLineIndex = index;
151 unsigned int maxLineNumber;
152 unsigned int firstLineIndex;
161 class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
164 CSVImportConfigurationWidget(QWidget *parent = NULL);
165 ~CSVImportConfigurationWidget();
167 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
168 void end(
unsigned int rowNumber,
unsigned int columnNumber);
173 void setNewParser(tlp::CSVParser *parser);
180 CSVImportParameters getImportParameters()
const;
182 bool eventFilter(QObject *, QEvent *);
189 std::vector<CSVColumn> getPropertiesToImport()
const;
191 void updateLineNumbers(
bool resetValues);
193 bool useFirstLineAsPropertyName()
const;
194 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
195 unsigned int rowCount()
const;
196 unsigned int columnCount()
const;
203 unsigned int getFirstLineIndex()
const;
208 unsigned int getLastLineIndex()
const;
214 unsigned int getFirstImportedLineIndex()
const;
219 void clearPropertiesTypeList();
223 void addPropertyToPropertyList(
const std::string& propertyName,
bool isEditable,
const std::string& propertyType=std::string(
""));
235 virtual PropertyConfigurationWidget *createPropertyConfigurationWidget(
unsigned int propertyNumber,
236 const QString& propertyName,
bool propertyNameIsEditable,
const std::string& propertyType, QWidget* parent);
241 QString genrateColumnName(
unsigned int col)
const;
245 std::string getColumnType(
unsigned int col)
const;
247 std::vector<PropertyConfigurationWidget*> propertyWidgets;
251 void filterPreviewLineNumber(
bool filter);
252 void previewLineNumberChanged(
int value);
254 void fromLineValueChanged(
int value);
255 void toLineValueChanged(
int value);
257 void updateTableHeaders();
259 void useFirstLineAsHeaderUpdated();
260 void propertyNameChanged(QString propertyName);
261 void propertyStateChanged(
bool activated);
264 void fileInfoChanged();
271 std::string guessPropertyDataType(
const std::string data,
const std::string previousType)
const;
276 std::string combinePropertyDataType(
const std::string previousType,
const std::string newType)
const;
281 std::string guessDataType(
const std::string data)
const;
283 void columnSizeChanged(
unsigned int i);
286 std::vector<std::string> columnHeaderType;
288 std::vector<std::string> columnType;
290 Ui::CSVImportConifgurationWidget *ui;
291 PropertyNameValidator* validator;
292 unsigned int maxLineNumber;
293 tlp::CSVParser* parser;
297 #endif // CSVIMPORTCONFIGURATIONWIDGET_H