21 #ifndef CSVGRAPHIMPORT_H
22 #define CSVGRAPHIMPORT_H
24 #include <tulip/CSVContentHandler.h>
25 #include <tulip/Graph.h>
26 #include <tulip/tulipconf.h>
28 #include <QtGui/QMessageBox>
31 class PropertyInterface;
38 class TLP_QT_SCOPE CSVColumn {
40 CSVColumn(
const std::string& columnName=
"",
bool isUsed=
false,
const std::string& columnType=
""):name(columnName),used(isUsed),type(columnType) {
47 std::string columnName()
const {
60 std::string columnDataType()
const {
75 class TLP_QT_SCOPE CSVImportParameters {
77 CSVImportParameters(
unsigned int fromLine=0,
unsigned int toLine=UINT_MAX,
const std::vector<CSVColumn>& columns = std::vector<CSVColumn>());
78 virtual ~CSVImportParameters();
83 unsigned int columnNumber()
const;
88 bool importColumn(
unsigned int column)
const;
92 std::string getColumnName(
unsigned int column)
const;
96 std::string getColumnDataType(
unsigned int column)
const;
101 unsigned int getFirstLineIndex()
const;
105 unsigned int getLastLineIndex()
const;
109 bool importRow(
unsigned int row)
const;
111 unsigned int fromLine;
113 std::vector<CSVColumn> columns;
129 class TLP_QT_SCOPE CSVToGraphDataMapping {
131 virtual ~CSVToGraphDataMapping() {}
132 virtual std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens)=0;
133 virtual void init(
unsigned int rowNumber)=0;
142 class TLP_QT_SCOPE AbstractCSVToGraphDataMapping :
public CSVToGraphDataMapping {
144 AbstractCSVToGraphDataMapping(
tlp::Graph* graph,
tlp::ElementType type,
unsigned int columnIndex,
const std::string& propertyName);
145 virtual ~AbstractCSVToGraphDataMapping() {}
147 void init(
unsigned int rowNumber);
148 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
157 TLP_HASH_MAP<std::string,unsigned int> valueToId;
160 unsigned int columnIndex;
166 class TLP_QT_SCOPE CSVToNewNodeIdMapping:
public CSVToGraphDataMapping {
169 void init(
unsigned int rowNumber);
170 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
180 class TLP_QT_SCOPE CSVToGraphNodeIdMapping:
public AbstractCSVToGraphDataMapping {
190 CSVToGraphNodeIdMapping(
tlp::Graph* graph,
unsigned int columnIndex,
const std::string& propertyName,
bool createNode=
false);
191 void init(
unsigned int rowNumber);
195 bool createMissingNodes;
202 class TLP_QT_SCOPE CSVToGraphEdgeIdMapping:
public AbstractCSVToGraphDataMapping {
211 CSVToGraphEdgeIdMapping(
tlp::Graph* graph,
unsigned int columnIndex,
const std::string& propertyName);
221 class TLP_QT_SCOPE CSVToGraphEdgeSrcTgtMapping:
public CSVToGraphDataMapping {
233 CSVToGraphEdgeSrcTgtMapping(
tlp::Graph* graph,
unsigned int srcColumnIndex,
unsigned int tgtColumnIndex,
const std::string& propertyName,
bool createMissinElements=
false);
234 std::pair<tlp::ElementType,unsigned int> getElementForRow(
unsigned int row);
235 void init(
unsigned int lineNumbers);
236 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
239 TLP_HASH_MAP<std::string,unsigned int> valueToId;
240 unsigned int srcColumnIndex;
241 unsigned int tgtColumnIndex;
243 bool buildMissingElements;
250 class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMapping {
252 virtual ~CSVImportColumnToGraphPropertyMapping() {}
268 class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMappingProxy :
public CSVImportColumnToGraphPropertyMapping {
270 CSVImportColumnToGraphPropertyMappingProxy(
tlp::Graph* graph,
const CSVImportParameters& importParameters,QWidget* parent=NULL);
271 virtual ~CSVImportColumnToGraphPropertyMappingProxy() {}
277 CSVImportParameters importParameters;
278 TLP_HASH_MAP<unsigned int,tlp::PropertyInterface*>propertiesBuffer;
279 QMessageBox::StandardButton overwritePropertiesButton;
287 class TLP_QT_SCOPE CSVGraphImport :
public tlp::CSVContentHandler {
289 CSVGraphImport(CSVToGraphDataMapping* mapping,CSVImportColumnToGraphPropertyMapping* propertiesManager,
const CSVImportParameters& importParameters);
290 virtual ~CSVGraphImport();
292 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
293 void end(
unsigned int rowNumber,
unsigned int columnNumber);
296 CSVToGraphDataMapping* mapping;
297 CSVImportColumnToGraphPropertyMapping* propertiesManager;
298 CSVImportParameters importParameters;
302 #endif // CSVGRAPHIMPORT_H