Tulip  5.7.4
Large graphs analysis and drawing
CSVImportWizard.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef CSVIMPORTWIZARD_H
22 #define CSVIMPORTWIZARD_H
23 
24 #include <QWizard>
25 #include <QWizardPage>
26 
27 #include <tulip/tulipconf.h>
28 #include <tulip/CSVContentHandler.h>
29 
30 namespace Ui {
31 class CSVImportWizard;
32 }
33 namespace tlp {
34 
35 class Graph;
36 class CSVParser;
37 class CSVParserConfigurationWidget;
38 class CSVTableWidget;
39 class CSVImportConfigurationWidget;
40 class CSVToGraphDataMapping;
41 class CSVGraphMappingConfigurationWidget;
42 class CSVImportParameters;
43 
44 /**
45  * @brief QWIzardPage encapsulating a CSVParserConfigurationWidget and a preview.
46  **/
47 class CSVParsingConfigurationQWizardPage : public QWizardPage, public CSVContentHandler {
48  Q_OBJECT
49 public:
50  CSVParsingConfigurationQWizardPage(QWidget *parent = nullptr);
51  bool begin() override;
52  bool line(unsigned int row, const std::vector<CSVToken> &lineTokens) override;
53  bool end(unsigned int rowNumber, unsigned int columnNumber) override;
54  bool isComplete() const override;
55  bool validatePage() override;
56  CSVParser *buildParser(int firstLine = 0) const;
57  int getFirstLineIndex() const;
58 
59 private:
60  void updatePreview();
61  CSVParserConfigurationWidget *parserConfigurationWidget;
62  CSVTableWidget *previewTableWidget;
63  unsigned int previewLineNumber, columnCount;
64  bool validColumnCount;
65 
66 private slots:
67  void parserChanged();
68 };
69 
70 class CSVImportConfigurationQWizardPage : public QWizardPage {
71  Q_OBJECT
72 public:
73  CSVImportConfigurationQWizardPage(QWidget *parent = nullptr);
74  void initializePage() override;
75  CSVImportParameters getImportParameters() const;
76 
77 private:
78  CSVImportConfigurationWidget *importConfigurationWidget;
79 };
80 
81 class CSVGraphMappingConfigurationQWizardPage : public QWizardPage {
82  Q_OBJECT
83 public:
84  CSVGraphMappingConfigurationQWizardPage(QWidget *parent = nullptr);
85  void initializePage() override;
86  bool isComplete() const override;
87  CSVToGraphDataMapping *buildMappingObject() const;
88 
89 private:
90  CSVGraphMappingConfigurationWidget *graphMappingConfigurationWidget;
91 };
92 
93 class TLP_QT_SCOPE CSVImportWizard : public QWizard {
94  Q_OBJECT
95 
96 public:
97  explicit CSVImportWizard(QWidget *parent = nullptr);
98  ~CSVImportWizard() override;
99 
100  CSVParsingConfigurationQWizardPage *getParsingConfigurationPage() const;
101  CSVImportConfigurationQWizardPage *getImportConfigurationPage() const;
102  CSVGraphMappingConfigurationQWizardPage *getMappingConfigurationPage() const;
103 
104  static void setGraph(Graph *g) {
105  graph = g;
106  }
107 
108  static Graph *getGraph() {
109  return graph;
110  }
111 
112 public slots:
113  void accept() override;
114 
115 private:
116  Ui::CSVImportWizard *ui;
117  static tlp::Graph *graph;
118 };
119 } // namespace tlp
120 #endif // CSVIMPORTWIZARD_H
121 ///@endcond