14bbbdcb |
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 | |
0cb512c0 |
16 | #include <inspector/DFBrowser_AttributePaneStack.hxx> |
14bbbdcb |
17 | |
0cb512c0 |
18 | #include <inspector/DFBrowserPane_AttributePaneAPI.hxx> |
19 | #include <inspector/DFBrowserPane_AttributePaneSelector.hxx> |
20 | #include <inspector/DFBrowser_Item.hxx> |
21 | #include <inspector/DFBrowser_Module.hxx> |
22 | #include <inspector/DFBrowser_Tools.hxx> |
23 | #include <inspector/DFBrowser_TreeLevelView.hxx> |
24 | #include <inspector/DFBrowser_TreeModel.hxx> |
25 | #include <inspector/DFBrowser_SearchView.hxx> |
26 | #include <inspector/DFBrowser_Window.hxx> |
14bbbdcb |
27 | |
6822a3be |
28 | #include <inspector/ViewControl_Tools.hxx> |
29 | |
14bbbdcb |
30 | #include <TDF_Attribute.hxx> |
31 | |
130eb114 |
32 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
33 | #include <QItemSelectionModel> |
34 | #include <QMap> |
35 | #include <QStackedWidget> |
130eb114 |
36 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
37 | |
38 | // ======================================================================= |
39 | // function : Constructor |
40 | // purpose : |
41 | // ======================================================================= |
42 | DFBrowser_AttributePaneStack::DFBrowser_AttributePaneStack (QObject* theParent) |
43 | : QObject (theParent), myCurrentPane (0), myAttributesStack (0), myModule (0), myTreeLevelView (0), |
44 | mySearchView (0), myEmptyWidget (0), myPaneMode (DFBrowser_AttributePaneType_ItemView) |
45 | { |
46 | myPaneSelector = new DFBrowserPane_AttributePaneSelector (theParent); |
47 | } |
48 | |
49 | // ======================================================================= |
50 | // function : CreateWidget |
51 | // purpose : |
52 | // ======================================================================= |
53 | void DFBrowser_AttributePaneStack::CreateWidget (QWidget* theParent) |
54 | { |
55 | myAttributesStack = new QStackedWidget (theParent); |
6822a3be |
56 | ViewControl_Tools::SetWhiteBackground (myAttributesStack); |
14bbbdcb |
57 | myEmptyWidget = new QWidget (theParent); |
6822a3be |
58 | ViewControl_Tools::SetWhiteBackground (myEmptyWidget); |
14bbbdcb |
59 | |
60 | myAttributesStack->addWidget (myEmptyWidget); |
61 | |
62 | myTreeLevelView = new DFBrowser_TreeLevelView (theParent); |
63 | myAttributesStack->addWidget (myTreeLevelView->GetControl()); |
64 | |
65 | mySearchView = new DFBrowser_SearchView (theParent); |
66 | myAttributesStack->addWidget (mySearchView->GetControl()); |
67 | |
68 | myAttributesStack->setCurrentWidget (myEmptyWidget); |
69 | } |
70 | |
71 | // ======================================================================= |
72 | // function : SetPaneMode |
73 | // purpose : |
74 | // ======================================================================= |
75 | void DFBrowser_AttributePaneStack::SetPaneMode (const DFBrowser_AttributePaneType& theMode) |
76 | { |
77 | if (myPaneMode == theMode) |
78 | return; |
79 | |
80 | myPaneMode = theMode; |
81 | if (myPaneMode == DFBrowser_AttributePaneType_SearchView) |
82 | { |
7e1c1e48 |
83 | // clear highlight in tree model |
14bbbdcb |
84 | DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel()); |
85 | if (aModel && aModel->HasHighlighted()) |
86 | aModel->SetHighlighted (QModelIndexList()); |
87 | myAttributesStack->setCurrentWidget (mySearchView->GetControl()); |
88 | } |
89 | else |
90 | { |
91 | QItemSelectionModel* aSelectionModel = myModule->GetOCAFViewSelectionModel(); |
6822a3be |
92 | QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aSelectionModel->selectedIndexes(), 0); |
14bbbdcb |
93 | SetCurrentItem (anIndex); |
94 | } |
95 | } |
96 | |
97 | // ======================================================================= |
98 | // function : SetCurrentItem |
99 | // purpose : |
100 | // ======================================================================= |
101 | void DFBrowser_AttributePaneStack::SetCurrentItem (const QModelIndex& theIndex) |
102 | { |
103 | if (myPaneMode != DFBrowser_AttributePaneType_ItemView) |
104 | return; |
105 | |
7e1c1e48 |
106 | // clear highlight in tree model |
14bbbdcb |
107 | DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel()); |
108 | if (aModel && aModel->HasHighlighted()) |
109 | aModel->SetHighlighted (QModelIndexList()); |
110 | |
111 | myCurrentPane = 0; |
112 | QWidget* aWidget = 0; |
113 | TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex); |
114 | if (!anItemBase) |
115 | return; |
116 | |
117 | if (DFBrowser_TreeLevelView::ProcessItem (theIndex)) |
118 | aWidget = myTreeLevelView->GetControl(); |
119 | else |
120 | { |
121 | DFBrowser_ItemPtr anItem = itemDynamicCast<DFBrowser_Item> (anItemBase); |
122 | if (!anItem) |
123 | return; |
124 | |
125 | if (myAttributesStack->currentWidget() == myTreeLevelView->GetControl()) |
126 | myTreeLevelView->ClearSelection(); |
127 | Handle(TDF_Attribute) anAttribute = anItem->GetAttribute(); |
128 | myCurrentPane = myModule->GetAttributePane (anAttribute); |
129 | |
130 | if (myCurrentPane) |
131 | { |
132 | aWidget = myCurrentPane->GetWidget (myAttributesStack, true); |
133 | if (aWidget) |
134 | { |
135 | int aWidgetIndex = myAttributesStack->indexOf (aWidget); |
136 | if (aWidgetIndex < 0) |
137 | myAttributesStack->addWidget (aWidget); |
138 | } |
139 | myCurrentPane->Init (anAttribute); |
140 | |
141 | std::list<QItemSelectionModel*> aSelectionModels = myCurrentPane->GetSelectionModels(); |
142 | myPaneSelector->SetCurrentSelectionModels (aSelectionModels); |
143 | } |
144 | } |
145 | myAttributesStack->setCurrentWidget (aWidget != NULL ? aWidget : myEmptyWidget); |
146 | } |