Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTreeStateHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
25 #ifndef __TY_TREE_STATE_HELPER__
26 #define __TY_TREE_STATE_HELPER__
27 
28 #include <QHash>
29 #include <QString>
30 #include <QTreeWidget>
31 #include <QTreeWidgetItem>
32 
34 {
35  QHash<QString, bool> expansion; // clé → expanded ?
36  int vScroll = 0; // position verticale
37  int hScroll = 0; // position horizontale
38 };
39 
41 {
42 public:
44  static void capture(QTreeWidget* tree, TYTreeViewState& outState);
45 
47  static void apply(QTreeWidget* tree, const TYTreeViewState& state);
48 
49 private:
50  // Routines récursives pour l'expansion
51  static void saveExpansionRec(QTreeWidgetItem* item, QHash<QString, bool>& map);
52  static void restoreExpansionRec(QTreeWidgetItem* item, const QHash<QString, bool>& map);
53 
54  // Génère une clé stable pour un item (ID UserRole si dispo, sinon chemin textuel)
55  static QString makeKey(QTreeWidgetItem* item);
56 };
57 
58 #endif //__TY_TREE_STATE_HELPER__
static void restoreExpansionRec(QTreeWidgetItem *item, const QHash< QString, bool > &map)
static void saveExpansionRec(QTreeWidgetItem *item, QHash< QString, bool > &map)
static QString makeKey(QTreeWidgetItem *item)
static void capture(QTreeWidget *tree, TYTreeViewState &outState)
Capture l'état complet (expansions + scroll) du QTreeWidget.
static void apply(QTreeWidget *tree, const TYTreeViewState &state)
Applique l'état complet (expansions + scroll) au QTreeWidget.
QHash< QString, bool > expansion