QCodeEditor: Update to current cpeditor/QCodeEditor fork, commit ed1196a
[smuview.git] / src / ui / tabs / basetab.hpp
blob3386a2e59a0b7c90a6c3507a2f092ed44002da3c
1 /*
2 * This file is part of the SmuView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
6 * Copyright (C) 2017-2021 Frank Stettner <frank-stettner@gmx.net>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program 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. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef UI_TABS_BASETAB_HPP
23 #define UI_TABS_BASETAB_HPP
25 #include <string>
27 #include <QDockWidget>
28 #include <QMainWindow>
29 #include <QSettings>
30 #include <QString>
31 #include <QWidget>
33 #include "src/ui/views/baseview.hpp"
35 using std::map;
36 using std::string;
38 namespace sv {
40 class Session;
42 namespace ui {
43 namespace tabs {
45 class TabDockWidget;
47 enum class TabType {
48 MeasurementTab,
49 SourceSinkTab,
50 UserTab,
51 WelcomeTab
54 /**
55 * Use a QMainWindow (as tab widget) to allow for a tool bar.
57 class BaseTab : public QMainWindow
59 Q_OBJECT
61 public:
62 explicit BaseTab(Session &session, QWidget *parent = nullptr);
64 Session &session();
65 const Session &session() const;
67 string id() const;
68 virtual QString title() = 0;
69 views::BaseView *get_view_from_view_id(const string &id);
70 virtual bool request_close() = 0;
72 private:
73 TabDockWidget *create_dock_widget(views::BaseView *view,
74 QDockWidget::DockWidgetFeatures features);
76 /** This event is handling the saving of the settings. */
77 void closeEvent(QCloseEvent *event) override;
79 protected:
80 Session &session_;
81 /**
82 * id_ is used for accessing the tab (e.g. for the python bindings UiProxy).
84 string id_;
85 /**
86 * settings_id_ is used for the objectNames of the tab and its views for
87 * identification in the settings (e.g. geometry and status).
89 QString settings_id_;
90 map<views::BaseView *, TabDockWidget *> view_docks_map_;
91 map<string, views::BaseView *> view_id_map_;
93 virtual void save_settings() const = 0;
94 virtual void restore_settings() = 0;
96 public Q_SLOTS:
98 * When using QDockWidget::DockWidgetFeatures instead of int for features,
99 * the given flags are or'ed to the default flags instead of replacing
100 * the default falgs.
102 void add_view(views::BaseView *view, Qt::DockWidgetArea area,
103 int features = QDockWidget::DockWidgetMovable |
104 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
106 * When using QDockWidget::DockWidgetFeatures instead of int for features,
107 * the given flags are or'ed to the default flags instead of replacing
108 * the default falgs.
110 void add_view_ontop(views::BaseView *view, views::BaseView *existing_view,
111 int features = QDockWidget::DockWidgetMovable |
112 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
114 private Q_SLOTS:
115 void remove_view(const std::string &view_id);
119 } // namespace tabs
120 } // namespace ui
121 } // namespace sv
123 #endif // UI_TABS_BASETAB_HPP