0032429: Coding - Warnings during compilation on macosx arm64 with option BUILD_Inspe...
[occt.git] / tools / DFBrowser / DFBrowser_TreeLevelLineModel.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <inspector/DFBrowser_TreeLevelLineModel.hxx>
17
18 #include <inspector/DFBrowser_ItemBase.hxx>
19 #include <inspector/TreeModel_ModelBase.hxx>
20
21 #include <Standard_WarningsDisable.hxx>
22 #include <QIcon>
23 #include <QWidget>
24 #include <Standard_WarningsRestore.hxx>
25
26 // =======================================================================
27 // function : Init
28 // purpose :
29 // =======================================================================
30 void DFBrowser_TreeLevelLineModel::Init (const QModelIndex& theTreeIndex)
31 {
32   myTreeIndex = theTreeIndex;
33   myLevelItems.clear();
34
35   if (theTreeIndex.isValid())
36   {
37     myLevelItems.prepend (theTreeIndex);
38     QModelIndex aParent = theTreeIndex.parent();
39     while (aParent.isValid())
40     {
41       myLevelItems.prepend (aParent);
42       aParent = aParent.parent();
43     }
44   }
45   emit layoutChanged();
46 }
47
48 // =======================================================================
49 // function : data
50 // purpose :
51 // =======================================================================
52 QVariant DFBrowser_TreeLevelLineModel::data (const QModelIndex& theIndex, int theRole) const
53 {
54   QVariant aValue;
55   int aColumns = theIndex.column();
56   if (aColumns < myLevelItems.size())
57   {
58     QModelIndex aTreeIndex = myLevelItems[aColumns];
59     if (theRole == Qt::DecorationRole) //! do not show icons presented in tree view
60       return aValue;
61     TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (aTreeIndex);
62     if (!anItemBase)
63       return aValue;
64
65     DFBrowser_ItemBasePtr aDBrowserItem = itemDynamicCast<DFBrowser_ItemBase> (anItemBase);
66     if (!aDBrowserItem)
67       return aValue;
68
69     bool aPrevValue = aDBrowserItem->SetUseAdditionalInfo (false);
70     aValue = aDBrowserItem->data (aTreeIndex, theRole);
71     aDBrowserItem->SetUseAdditionalInfo (aPrevValue);
72
73     if (theRole == Qt::DisplayRole)
74       aValue = aValue.toString() + "  "; //! TEMPORARY to leave place for the action icon
75   }
76   return aValue;
77 }
78
79 // =======================================================================
80 // function : headerData
81 // purpose :
82 // =======================================================================
83 QVariant DFBrowser_TreeLevelLineModel::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
84 {
85   QVariant aValue;
86   if (theOrientation == Qt::Horizontal && theSection < myLevelItems.size())
87   {
88     QModelIndex aTreeIndex = myLevelItems[theSection];
89     if (!aTreeIndex.isValid()) // level change action
90     {
91       if (theRole == Qt::SizeHintRole)
92         aValue = QSize (2, 2);
93       else if (theRole == Qt::DisplayRole)
94         aValue = "";
95     }
96   }
97   return aValue;
98 }