21 #ifndef CSVIMPORTCONFIGURATIONWIDGET_H
22 #define CSVIMPORTCONFIGURATIONWIDGET_H
24 #include <QtGui/QWidget>
25 #include <QtGui/QValidator>
26 #include <QtGui/QTableWidget>
28 #include <tulip/CSVGraphImport.h>
29 #include <tulip/CSVContentHandler.h>
30 #include <tulip/tulipconf.h>
38 class CSVImportConifgurationWidget;
47 class TLP_QT_SCOPE PropertyConfigurationWidget:
public QWidget {
50 PropertyConfigurationWidget(
unsigned int propertyNumber,
const QString& propertyName,
bool propertyNameIsEditable,
51 const std::string& PropertyType, QWidget* parent = NULL);
55 std::string getPropertyType()
const;
59 void setPropertyType(
const std::string& propertyType);
61 QString getPropertyName()
const;
62 bool getPropertyUsed()
const;
66 void setPropertyNameValidator(QValidator* validator);
67 unsigned int getPropertyNumber()
const;
69 QLineEdit *getNameLineEdit() {
70 return propertyNameLineEdit;
72 QComboBox *getTypeComboBox() {
73 return propertyTypeComboBox;
76 QCheckBox *getCheckBox() {
81 void fillPropertyTypeComboBox();
82 QLineEdit *propertyNameLineEdit;
83 QComboBox *propertyTypeComboBox;
84 QCheckBox *usedCheckBox;
86 unsigned int propertyNumber;
89 void nameEditFinished();
90 void useStateChanged(
int state);
93 void propertyNameChange(QString newName);
94 void stateChange(
bool state);
100 class TLP_QT_SCOPE PropertyNameValidator:
public QValidator {
102 PropertyNameValidator(
const std::vector<PropertyConfigurationWidget*>& widgets,QObject*parent=NULL) :
103 QValidator(parent), widgets(widgets) {
105 virtual ~PropertyNameValidator() {
112 QValidator::State validate(QString & input,
int & pos)
const;
115 const std::vector<PropertyConfigurationWidget*>& widgets;
121 class TLP_QT_SCOPE CSVTableWidget :
public QTableWidget,
public CSVContentHandler {
123 CSVTableWidget(QWidget* parent=NULL);
125 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
126 void end(
unsigned int rowNumber,
unsigned int columnNumber);
130 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
131 maxLineNumber = lineNumber;
137 unsigned int getMaxPreviewLineNumber()
const {
138 return maxLineNumber;
141 unsigned int getFirstLineIndex() {
142 return firstLineIndex;
145 void setFirstLineIndex(
unsigned int index) {
146 firstLineIndex = index;
150 unsigned int maxLineNumber;
151 unsigned int firstLineIndex;
160 class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
163 CSVImportConfigurationWidget(QWidget *parent = NULL);
164 ~CSVImportConfigurationWidget();
166 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
167 void end(
unsigned int rowNumber,
unsigned int columnNumber);
172 void setNewParser(tlp::CSVParser *parser);
179 CSVImportParameters getImportParameters()
const;
181 bool eventFilter(QObject *, QEvent *);
188 std::vector<CSVColumn> getPropertiesToImport()
const;
190 void updateLineNumbers(
bool resetValues);
192 bool useFirstLineAsPropertyName()
const;
193 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
194 unsigned int rowCount()
const;
195 unsigned int columnCount()
const;
202 unsigned int getFirstLineIndex()
const;
207 unsigned int getLastLineIndex()
const;
213 unsigned int getFirstImportedLineIndex()
const;
218 void clearPropertiesTypeList();
222 void addPropertyToPropertyList(
const std::string& propertyName,
bool isEditable,
const std::string& propertyType=std::string(
""));
234 virtual PropertyConfigurationWidget *createPropertyConfigurationWidget(
unsigned int propertyNumber,
235 const QString& propertyName,
bool propertyNameIsEditable,
const std::string& propertyType, QWidget* parent);
240 QString genrateColumnName(
unsigned int col)
const;
244 std::string getColumnType(
unsigned int col)
const;
246 std::vector<PropertyConfigurationWidget*> propertyWidgets;
250 void filterPreviewLineNumber(
bool filter);
251 void previewLineNumberChanged(
int value);
253 void fromLineValueChanged(
int value);
254 void toLineValueChanged(
int value);
256 void updateTableHeaders();
258 void useFirstLineAsHeaderUpdated();
259 void propertyNameChanged(QString propertyName);
260 void propertyStateChanged(
bool activated);
263 void fileInfoChanged();
270 std::string guessPropertyDataType(
const std::string data,
const std::string previousType)
const;
275 std::string combinePropertyDataType(
const std::string previousType,
const std::string newType)
const;
280 std::string guessDataType(
const std::string data)
const;
282 void columnSizeChanged(
unsigned int i);
285 std::vector<std::string> columnHeaderType;
287 std::vector<std::string> columnType;
289 Ui::CSVImportConifgurationWidget *ui;
290 PropertyNameValidator* validator;
291 unsigned int maxLineNumber;
292 tlp::CSVParser* parser;
296 #endif // CSVIMPORTCONFIGURATIONWIDGET_H