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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
// Created on: 2020-01-25
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/ViewControl_Table.hxx>
#include <inspector/ViewControl_TableItemDelegate.hxx>
#include <inspector/ViewControl_TableModel.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <inspector/TreeModel_ItemProperties.hxx>
#include <inspector/TreeModel_ItemStream.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_Dump.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QGridLayout>
#include <QHeaderView>
#include <QLabel>
#include <QTableView>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ViewControl_Table::ViewControl_Table(QWidget* theParent)
: QObject(theParent),
myIsUseProperty(false)
{
myMainWidget = new QWidget(theParent);
QGridLayout* aLayout = new QGridLayout(myMainWidget);
aLayout->setContentsMargins(0, 0, 0, 0);
myTableView = new QTableView(myMainWidget);
myTableView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
myTableView->setItemDelegate(new ViewControl_TableItemDelegate(theParent));
QHeaderView* aVHeader = myTableView->verticalHeader();
int aDefCellSize = aVHeader->minimumSectionSize();
aVHeader->setDefaultSectionSize(aDefCellSize);
connect(myTableView->horizontalHeader(),
SIGNAL(sectionResized(int, int, int)),
this,
SLOT(onHeaderResized(int, int, int)));
aLayout->addWidget(myTableView);
}
// =======================================================================
// function : SetModel
// purpose :
// =======================================================================
void ViewControl_Table::SetModel(QAbstractTableModel* theModel)
{
myTableView->setModel(theModel);
myTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel(theModel);
myTableView->setSelectionModel(aSelectionModel);
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void ViewControl_Table::Init(ViewControl_TableModelValues* theModelValues)
{
myTableView->selectionModel()->clearSelection();
ViewControl_TableModel* aModel = dynamic_cast<ViewControl_TableModel*>(myTableView->model());
aModel->SetModelValues(theModelValues);
myTableView->horizontalHeader()->setVisible(theModelValues->IsHeaderVisible(Qt::Horizontal));
ViewControl_TableItemDelegate* anItemDelegate =
dynamic_cast<ViewControl_TableItemDelegate*>(myTableView->itemDelegate());
anItemDelegate->SetModelValues(theModelValues);
myTableView->verticalHeader()->setVisible(theModelValues->IsHeaderVisible(Qt::Vertical));
int aSectionSize;
if (theModelValues->DefaultSectionSize(Qt::Vertical, aSectionSize))
{
myTableView->verticalHeader()->setDefaultSectionSize(aSectionSize);
}
else
myTableView->verticalHeader()->setDefaultSectionSize(
myTableView->verticalHeader()->minimumSectionSize());
aModel->EmitLayoutChanged();
}
// =======================================================================
// function : SelectedIndices
// purpose :
// =======================================================================
void ViewControl_Table::SelectedIndices(QMap<int, QList<int>>& theSelectedIndices) const
{
QModelIndexList aSelected = myTableView->selectionModel()->selectedIndexes();
int aRow, aColumn;
for (QModelIndexList::const_iterator anIt = aSelected.begin(); anIt != aSelected.end(); anIt++)
{
QModelIndex anIndex = *anIt;
aRow = anIndex.row();
aColumn = anIndex.column();
if (!theSelectedIndices.contains(aRow))
theSelectedIndices.insert(aRow, QList<int>());
theSelectedIndices[aRow].append(aColumn);
}
}
// =======================================================================
// function : SeparatorData
// purpose :
// =======================================================================
QString ViewControl_Table::SeparatorData()
{
return ViewControl_Tools::TableSeparator();
}
// =======================================================================
// function : SelectedPointers
// purpose :
// =======================================================================
void ViewControl_Table::SelectedPointers(QStringList& thePointers) const
{
QMap<int, QList<int>> aSelectedIndices;
SelectedIndices(aSelectedIndices);
ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*>(TableView()->model());
ViewControl_TableModelValues* aTableValues = aTableModel->ModelValues();
for (QMap<int, QList<int>>::const_iterator aSelIt = aSelectedIndices.begin();
aSelIt != aSelectedIndices.end();
aSelIt++)
{
int aRowId = aSelIt.key();
QList<int> aColIds = aSelIt.value();
for (int aColId = 0; aColId < aColIds.size(); aColId++)
{
int aSelectedColId = aColIds[aColId];
if (aSelectedColId != 1)
continue;
QString aData = aTableValues->Data(aRowId, aSelectedColId, Qt::DisplayRole).toString();
if (aData.contains(Standard_Dump::GetPointerPrefix().ToCString()))
thePointers.append(aData);
}
}
}
// =======================================================================
// function : onHeaderResized
// purpose :
// =======================================================================
void ViewControl_Table::onHeaderResized(int theSectionId, int, int)
{
if (theSectionId != 0)
return;
myTableView->horizontalHeader()->setDefaultSectionSize(myTableView->columnWidth(theSectionId));
}
|