0032429: Coding - Warnings during compilation on macosx arm64 with option BUILD_Inspe...
[occt.git] / tools / DFBrowser / DFBrowser_SearchView.cxx
CommitLineData
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_SearchView.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowser_HighlightDelegate.hxx>
19#include <inspector/DFBrowser_SearchLine.hxx>
20#include <inspector/DFBrowser_SearchLineModel.hxx>
21#include <inspector/DFBrowser_Window.hxx>
14bbbdcb 22
0cb512c0 23#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 24
6822a3be 25#include <inspector/TreeModel_ModelBase.hxx>
26#include <inspector/TreeModel_Tools.hxx>
27
28#include <inspector/ViewControl_Tools.hxx>
29
130eb114 30#include <Standard_WarningsDisable.hxx>
14bbbdcb 31#include <QAbstractProxyModel>
32#include <QGridLayout>
33#include <QHeaderView>
34#include <QTableView>
35#include <QWidget>
130eb114 36#include <Standard_WarningsRestore.hxx>
14bbbdcb 37
38const int DEFAULT_COLUMN_WIDTH = 500;
39const int DEFAULT_ICON_SIZE = 40;
40
41// =======================================================================
42// function : Constructor
43// purpose :
44// =======================================================================
45DFBrowser_SearchView::DFBrowser_SearchView (QWidget* theParent)
46: QObject (theParent)
47{
48 myMainWindow = new QWidget (theParent);
49 QGridLayout* aLayout = new QGridLayout (myMainWindow);
50 aLayout->setContentsMargins (0, 0, 0, 0);
51
52 myTableView = new QTableView (myMainWindow);
53 myTableView->verticalHeader()->setVisible (false);
6822a3be 54 myTableView->verticalHeader()->setDefaultSectionSize (DEFAULT_ICON_SIZE + TreeModel_Tools::HeaderSectionMargin());
14bbbdcb 55 myTableView->setIconSize (QSize (DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
56 myTableView->horizontalHeader()->setVisible (false);
57 myTableView->horizontalHeader()->setStretchLastSection (true);
58
59 myTableView->viewport()->setAttribute (Qt::WA_Hover);
60 myTableView->setItemDelegate (new DFBrowser_HighlightDelegate (myTableView));
61
62 aLayout->addWidget (myTableView);
63
6822a3be 64 ViewControl_Tools::SetWhiteBackground (myTableView);
14bbbdcb 65 myTableView->setGridStyle (Qt::NoPen);
66}
67
68// =======================================================================
69// function : InitModels
70// purpose :
71// =======================================================================
72void DFBrowser_SearchView::InitModels()
73{
74 QAbstractItemModel* aModel = mySearchLine->GetCompletionModel();
75 myTableView->setModel (aModel);
76 myTableView->setColumnWidth (0, 0); // to hide column
6822a3be 77 myTableView->setColumnWidth (1, DEFAULT_ICON_SIZE + TreeModel_Tools::HeaderSectionMargin());
14bbbdcb 78
79 QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aModel);
80 myTableView->setSelectionMode (QAbstractItemView::SingleSelection);
81 myTableView->setSelectionModel (aSelectionModel);
82 connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
83 this, SLOT (onTableSelectionChanged (const QItemSelection&, const QItemSelection&)));
84 connect (myTableView, SIGNAL (doubleClicked (const QModelIndex&)),
85 this, SLOT (onTableDoubleClicked (const QModelIndex&)));
86}
87
88// =======================================================================
89// function : onTableSelectionChanged
90// purpose :
91// =======================================================================
d2c90917 92void DFBrowser_SearchView::onTableSelectionChanged (const QItemSelection&,
14bbbdcb 93 const QItemSelection&)
94{
d2c90917 95 QItemSelectionModel* aSelectionModel = myTableView->selectionModel();
96 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
6822a3be 97 QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 2);
14bbbdcb 98 if (!aSelectedIndex.isValid())
99 return;
100 QAbstractProxyModel* aTableModel = dynamic_cast<QAbstractProxyModel*> (myTableView->model());
101 if (!aTableModel)
102 return;
103 DFBrowser_SearchLineModel* aSourceModel = dynamic_cast<DFBrowser_SearchLineModel*> (aTableModel->sourceModel());
104 if (!aSourceModel)
105 return;
106
107 QModelIndex aSourceSelectedIndex = aTableModel->mapToSource(aSelectedIndex);
108 emit pathSelected(aSourceModel->GetPath (aSourceSelectedIndex), aSourceModel->GetValue (aSourceSelectedIndex));
109}
110
111// =======================================================================
112// function : onTableDoubleClicked
113// purpose :
114// =======================================================================
115void DFBrowser_SearchView::onTableDoubleClicked (const QModelIndex& theIndex)
116{
117 QAbstractProxyModel* aTableModel = dynamic_cast<QAbstractProxyModel*> (myTableView->model());
118 if (!aTableModel)
119 return;
120 DFBrowser_SearchLineModel* aSourceModel = dynamic_cast<DFBrowser_SearchLineModel*> (aTableModel->sourceModel());
121 if (!aSourceModel)
122 return;
123
124 QModelIndex aSourceSelectedIndex = aTableModel->mapToSource(theIndex);
125 emit pathDoubleClicked (aSourceModel->GetPath (aSourceSelectedIndex), aSourceModel->GetValue (aSourceSelectedIndex));
126}