1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 //       notice, this list of conditions and the following disclaimer.
9 //
10 //     * Redistributions in binary form must reproduce the above copyright
11 //       notice, this list of conditions and the following disclaimer in the
12 //       documentation and/or other materials provided with the distribution.
13 //
14 //     * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 //       its contributors may be used to endorse or promote products derived
16 //       from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #ifndef COLMAP_SRC_UI_OPTIONS_WIDGET_H_
33 #define COLMAP_SRC_UI_OPTIONS_WIDGET_H_
34 
35 #include <unordered_map>
36 
37 #include <QtCore>
38 #include <QtWidgets>
39 
40 namespace colmap {
41 
42 class OptionsWidget : public QWidget {
43  public:
44   explicit OptionsWidget(QWidget* parent);
45 
46   void AddOptionRow(const std::string& label_text, QWidget* widget,
47                     void* option);
48   void AddWidgetRow(const std::string& label_text, QWidget* widget);
49   void AddLayoutRow(const std::string& label_text, QLayout* layout);
50 
51   QSpinBox* AddOptionInt(int* option, const std::string& label_text,
52                          const int min = 0,
53                          const int max = static_cast<int>(1e7));
54   QDoubleSpinBox* AddOptionDouble(double* option, const std::string& label_text,
55                                   const double min = 0, const double max = 1e7,
56                                   const double step = 0.01,
57                                   const int decimals = 2);
58   QDoubleSpinBox* AddOptionDoubleLog(
59       double* option, const std::string& label_text, const double min = 0,
60       const double max = 1e7, const double step = 0.01, const int decimals = 2);
61   QCheckBox* AddOptionBool(bool* option, const std::string& label_text);
62   QLineEdit* AddOptionText(std::string* option, const std::string& label_text);
63   QLineEdit* AddOptionFilePath(std::string* option,
64                                const std::string& label_text);
65   QLineEdit* AddOptionDirPath(std::string* option,
66                               const std::string& label_text);
67 
68   void AddSpacer();
69   void AddSection(const std::string& title);
70 
71   void ReadOptions();
72   void WriteOptions();
73 
74  protected:
75   void showEvent(QShowEvent* event);
76   void closeEvent(QCloseEvent* event);
77   void hideEvent(QHideEvent* event);
78 
79   void ShowOption(void* option);
80   void HideOption(void* option);
81 
82   void ShowWidget(QWidget* option);
83   void HideWidget(QWidget* option);
84 
85   void ShowLayout(QLayout* option);
86   void HideLayout(QLayout* option);
87 
88   QGridLayout* grid_layout_;
89 
90   std::unordered_map<void*, std::pair<QLabel*, QWidget*>> option_rows_;
91   std::unordered_map<QWidget*, std::pair<QLabel*, QWidget*>> widget_rows_;
92   std::unordered_map<QLayout*, std::pair<QLabel*, QWidget*>> layout_rows_;
93 
94   std::vector<std::pair<QSpinBox*, int*>> options_int_;
95   std::vector<std::pair<QDoubleSpinBox*, double*>> options_double_;
96   std::vector<std::pair<QDoubleSpinBox*, double*>> options_double_log_;
97   std::vector<std::pair<QCheckBox*, bool*>> options_bool_;
98   std::vector<std::pair<QLineEdit*, std::string*>> options_text_;
99   std::vector<std::pair<QLineEdit*, std::string*>> options_path_;
100 };
101 
102 }  // namespace colmap
103 
104 #endif  // COLMAP_SRC_UI_OPTIONS_WIDGET_H_
105