21 #ifndef CSVIMPORTCONFIGURATIONWIDGET_H
22 #define CSVIMPORTCONFIGURATIONWIDGET_H
24 #include <QtGui/QWidget>
25 #include <QtGui/QValidator>
26 #include <QtGui/QTableWidget>
27 #include <tulip/CSVGraphImport.h>
28 #include <tulip/CSVContentHandler.h>
37 class CSVImportConifgurationWidget;
45 class TLP_QT_SCOPE PropertyConfigurationWidget:
public QWidget {
48 PropertyConfigurationWidget(
unsigned int propertyNumber,
const QString& propertyName,
bool propertyNameIsEditable,
49 const std::string& PropertyType, QWidget* parent = NULL);
53 std::string getPropertyType()
const;
57 void setPropertyType(
const std::string& propertyType);
59 QString getPropertyName()
const;
60 bool getPropertyUsed()
const;
64 void setPropertyNameValidator(QValidator* validator);
65 unsigned int getPropertyNumber()
const;
67 QLineEdit *getNameLineEdit() {
68 return propertyNameLineEdit;
70 QComboBox *getTypeComboBox() {
71 return propertyTypeComboBox;
74 QCheckBox *getCheckBox() {
79 void fillPropertyTypeComboBox();
80 QLineEdit *propertyNameLineEdit;
81 QComboBox *propertyTypeComboBox;
82 QCheckBox *usedCheckBox;
84 unsigned int propertyNumber;
87 void nameEditFinished();
88 void useStateChanged(
int state);
91 void propertyNameChange(QString newName);
92 void stateChange(
bool state);
98 class TLP_QT_SCOPE PropertyNameValidator:
public QValidator {
100 PropertyNameValidator(
const std::vector<PropertyConfigurationWidget*>& widgets,QObject*parent=NULL) :
101 QValidator(parent), widgets(widgets) {
103 virtual ~PropertyNameValidator() {
110 QValidator::State validate(QString & input,
int & pos)
const;
113 const std::vector<PropertyConfigurationWidget*>& widgets;
119 class TLP_QT_SCOPE CSVTableWidget :
public QTableWidget,
public CSVContentHandler {
121 CSVTableWidget(QWidget* parent=NULL);
123 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
124 void end(
unsigned int rowNumber,
unsigned int columnNumber);
128 void setMaxPreviewLineNumber(
unsigned int lineNumber) {
129 maxLineNumber = lineNumber;
135 unsigned int getMaxPreviewLineNumber()
const {
136 return maxLineNumber;
139 unsigned int getFirstLineIndex() {
140 return firstLineIndex;
143 void setFirstLineIndex(
unsigned int index) {
144 firstLineIndex = index;
148 unsigned int maxLineNumber;
149 unsigned int firstLineIndex;
158 class TLP_QT_SCOPE CSVImportConfigurationWidget :
public QWidget,
public CSVContentHandler {
161 CSVImportConfigurationWidget(QWidget *parent = NULL);
162 ~CSVImportConfigurationWidget();
164 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
165 void end(
unsigned int rowNumber,
unsigned int columnNumber);
170 void setNewParser(tlp::CSVParser *parser);
177 CSVImportParameters getImportParameters()
const;
179 bool eventFilter(QObject *, QEvent *);
186 std::vector<CSVColumn> getPropertiesToImport()
const;
187 void changeEvent(QEvent *e);
189 void updateLineNumbers(
bool resetValues);
191 bool useFirstLineAsPropertyName()
const;
192 void setUseFirstLineAsPropertyName(
bool useFirstLineAsHeader)
const;
193 unsigned int rowCount()
const;
194 unsigned int columnCount()
const;
201 unsigned int getFirstLineIndex()
const;
206 unsigned int getLastLineIndex()
const;
212 unsigned int getFirstImportedLineIndex()
const;
217 void clearPropertiesTypeList();
221 void addPropertyToPropertyList(
const std::string& propertyName,
bool isEditable,
const std::string& propertyType=std::string(
""));
233 virtual PropertyConfigurationWidget *createPropertyConfigurationWidget(
unsigned int propertyNumber,
234 const QString& propertyName,
bool propertyNameIsEditable,
const std::string& propertyType, QWidget* parent);
239 QString genrateColumnName(
unsigned int col)
const;
243 std::string getColumnType(
unsigned int col)
const;
245 std::vector<PropertyConfigurationWidget*> propertyWidgets;
249 void filterPreviewLineNumber(
bool filter);
250 void previewLineNumberChanged(
int value);
252 void fromLineValueChanged(
int value);
253 void toLineValueChanged(
int value);
255 void updateTableHeaders();
257 void useFirstLineAsHeaderUpdated();
258 void propertyNameChanged(QString propertyName);
259 void propertyStateChanged(
bool activated);
262 void fileInfoChanged();
269 std::string guessPropertyDataType(
const std::string data,
const std::string previousType)
const;
274 std::string combinePropertyDataType(
const std::string previousType,
const std::string newType)
const;
279 std::string guessDataType(
const std::string data)
const;
281 void columnSizeChanged(
unsigned int i);
284 std::vector<std::string> columnHeaderType;
286 std::vector<std::string> columnType;
288 Ui::CSVImportConifgurationWidget *ui;
289 PropertyNameValidator* validator;
290 unsigned int maxLineNumber;
291 tlp::CSVParser* parser;
295 #endif // CSVIMPORTCONFIGURATIONWIDGET_H