Tulip  5.7.4
Large graphs analysis and drawing
CSVGraphMappingConfigurationWidget.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 CSVGRAPHMAPPINGCONFIGURATIONWIDGET_H
22 #define CSVGRAPHMAPPINGCONFIGURATIONWIDGET_H
23 
24 #include <QComboBox>
25 #include <QPushButton>
26 #include <QString>
27 
28 #include <tulip/tulipconf.h>
29 
30 namespace Ui {
31 class CSVGraphMappingConfigurationWidget;
32 }
33 
34 namespace tlp {
35 
36 class Graph;
37 class CSVGraphImport;
38 class CSVImportParameters;
39 class CSVToGraphDataMapping;
40 
41 /**
42  * @brief Widget generating the CSVToGraphDataMapping object.
43  *
44  * This widget allow user to configure a CSVToGraphDataMapping object. This object is used during
45  *the CSV import process to map CSV columns to graph elements like nodes or edges.
46  **/
47 class TLP_QT_SCOPE CSVGraphMappingConfigurationWidget : public QWidget {
48  Q_OBJECT
49 public:
50  CSVGraphMappingConfigurationWidget(QWidget *parent = nullptr);
51  ~CSVGraphMappingConfigurationWidget() override;
52 
53  /**
54  * @brief Configure the widget with the CSV import parameters.
55  **/
56  void updateWidget(tlp::Graph *graph, const CSVImportParameters &importParameters);
57  /**
58  * @brief Build the mapping object between the CSV columns and the graph elements.
59  **/
60  CSVToGraphDataMapping *buildMappingObject() const;
61 
62  /**
63  * @brief Check if the values entered by user are valid.
64  *
65  * If return true you are sure that buildMappingObject never return a nullptr object.
66  **/
67  bool isValid() const;
68 
69 protected:
70  tlp::Graph *graph;
71  std::vector<std::string> columns;
72  std::vector<unsigned int> nodeColumnIds;
73  std::vector<std::string> nodeProperties;
74  std::vector<unsigned int> edgeColumnIds;
75  std::vector<std::string> edgeProperties;
76  std::vector<unsigned int> srcColumnIds;
77  std::vector<unsigned int> tgtColumnIds;
78  std::vector<std::string> srcProperties;
79  std::vector<std::string> tgtProperties;
80 
81 private:
82  Ui::CSVGraphMappingConfigurationWidget *ui;
83  void selectColumns(const QString &title, std::vector<unsigned int> &columnIds,
84  QPushButton *button);
85  void selectProperties(const QString &title, std::vector<std::string> &selProperties,
86  QPushButton *button);
87 
88 private slots:
89  void createNewProperty();
90  void selectNodeColumns();
91  void selectEdgeColumns();
92  void selectSrcColumns();
93  void selectTgtColumns();
94  void selectSrcProperties();
95  void selectTgtProperties();
96  void selectNodeProperties();
97  void selectEdgeProperties();
98 
99 signals:
100  void mappingChanged();
101 };
102 } // namespace tlp
103 #endif // CSVGRAPHMAPPINGCONFIGURATIONWIDGET_H
104 ///@endcond