WSL/SLF GitLab Repository

SectionTab.h 3.2 KB
Newer Older
Michael Reisecker's avatar
Michael Reisecker committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*****************************************************************************/
/*  Copyright 2021 WSL Institute for Snow and Avalanche Research  SLF-DAVOS  */
/*****************************************************************************/
/* This file is part of INIshell.
   INIshell is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   INIshell is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with INIshell.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * This is the high level tab bar widget which the GUI building recursion can be
 * started on.
 * Hence, an instance of it is used in the MainPanel, the Help and Settings
 * windows, and potentially others to display INIshell XML content.
 * 2021-01
 */

27
28
29
#ifndef SECTIONTAB_H
#define SECTIONTAB_H

30
31
32
#include "src/gui_elements/Group.h"
#include "src/main/INIParser.h"

33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <QList>
#include <QScrollArea>
#include <QString>
#include <QStringList>
#include <QTabWidget>
#include <QWidget>
#include <QtXml>

class ScrollPanel : public QWidget {
	Q_OBJECT

	public:
		explicit ScrollPanel(const QString &tab_color, QWidget *parent = nullptr);
		Group * getGroup() const;
47
		void ensureWidgetVisible(QWidget *wid) { main_area_->ensureWidgetVisible(wid); }
48
49
50
51
52
53
54
55
56
57

	private:
		QScrollArea *main_area_ = nullptr;
		Group *main_group_ = nullptr;
};

class SectionTab : public QTabWidget {
	Q_OBJECT

	public:
58
		explicit SectionTab(QWidget *parent = nullptr);
59
		ScrollPanel * getSectionScrollArea(const QString &section, const QString &background_color = QString(),
60
			const QString &color = "normal", const bool &no_create = false, const int &insert_idx = -1);
61
		ScrollPanel * getSectionScrollArea(const int &index);
62
		QString setIniValuesFromGui(INIParser *ini);
63
		void setSectionDynamic(const QString &section, const QDomNode &node); //register section as dynamic
64
65
		bool isDynamicParent(const QString &section) const;
		int isDynamicChild(const QString &section) const;
66
67
68
		bool isDynamicChildOf(const QString &section, const QString &parent_section) const;
		int countChildren(const QString &parent_section) const;
		QString getParentOf(const QString &section);
69
70
		void spawnDynamicSection(const QString &section, const QString &new_name = QString()); //clone a section registered as dynamic
		ScrollPanel * tryDynamicSection(const QString &section);
71
72
73
		void removeDynamicSection(const QString &section);
		QStringList * getDynamicSectionList() { return &dynamic_sections_; }
		bool showTab(const QString &tab_name);
Michael Reisecker's avatar
Michael Reisecker committed
74
		bool showPanel(const QString &section, const QString &element_key);
75
		int getIndex(const QString &section, const Qt::CaseSensitivity &sensitivity = Qt::CaseInsensitive);
76
		void clear();
77
		void clearDynamicTabs();
78
79
80
81
82
83
84
85

	private:
		QStringList dynamic_sections_;
		QList<QDomNode> dynamic_nodes_;
		QList<int> dynamic_running_indices_;
};

#endif //SECTIONTAB_H