0029018: Documentation - Provide user guide for Qt browser
[occt.git] / tools / DFBrowserPane / DFBrowserPane_TDocStdOwner.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/DFBrowserPane_TDocStdOwner.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19#include <inspector/DFBrowserPane_TableView.hxx>
20#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 21
22#include <TDocStd_Document.hxx>
23#include <TDocStd_Owner.hxx>
24#include <TDF_Delta.hxx>
25#include <TDF_ListIteratorOfDeltaList.hxx>
d2c90917 26#include <Standard_Version.hxx>
14bbbdcb 27
28#include <QVariant>
29#include <QWidget>
30
31#include <QGridLayout>
32#include <QGroupBox>
33#include <QTableView>
34
14bbbdcb 35// =======================================================================
36// function : Constructor
37// purpose :
38// =======================================================================
39DFBrowserPane_TDocStdOwner::DFBrowserPane_TDocStdOwner()
40 : DFBrowserPane_AttributePane()
41{
14bbbdcb 42}
43
44// =======================================================================
45// function : GetValues
46// purpose :
47// =======================================================================
48void DFBrowserPane_TDocStdOwner::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
49{
50 Handle(TDocStd_Owner) anAttribute = Handle(TDocStd_Owner)::DownCast (theAttribute);
51 if (anAttribute.IsNull())
52 return;
53
54 Handle(TDocStd_Document) aDocument = anAttribute->GetDocument();
55 if (aDocument.IsNull())
56 return;
57
d2c90917 58 TCollection_AsciiString aDocumentInfo = DFBrowserPane_Tools::GetPointerInfo (aDocument).ToCString();
14bbbdcb 59 TColStd_SequenceOfExtendedString anExtensions;
60 aDocument->Extensions(anExtensions);
d2c90917 61 TCollection_AsciiString aSeparationStr = "---------------------------";
62 theValues << aSeparationStr.ToCString() << aSeparationStr.ToCString()
63 << STANDARD_TYPE (CDM_Document)->Name() << aDocumentInfo.ToCString()
64 << aSeparationStr.ToCString() << aSeparationStr.ToCString()
65 << "StorageFormat" << DFBrowserPane_Tools::ToString (aDocument->StorageFormat())
66 << "Extensions" << convertToString (anExtensions)
14bbbdcb 67 << "FromReferencesNumber" << QString::number (aDocument->FromReferencesNumber())
68 << "ToReferencesNumber" << QString::number (aDocument->ToReferencesNumber())
69 << "IsReadOnly" << DFBrowserPane_Tools::BoolToStr (aDocument->IsReadOnly())
70 << "Modifications" << QString::number (aDocument->Modifications());
d2c90917 71
14bbbdcb 72 TColStd_SequenceOfExtendedString aComments;
73 aDocument->Extensions(aComments);
d2c90917 74 // if the document application is empty, Application() sents an exception, it is called in LoadResources() of:
75 // FindFileExtension, FindDescription and others, so we need the check for it
76 bool isDocumentOpened = aDocument->IsOpened();
14bbbdcb 77
d2c90917 78 // CDM_Document methods
14bbbdcb 79 theValues << "Comments" << convertToString (aComments)
d2c90917 80 << "Presentation" << DFBrowserPane_Tools::ToString (aDocument->Presentation())
14bbbdcb 81 << "IsStored" << DFBrowserPane_Tools::BoolToStr (aDocument->IsStored())
82 << "StorageVersion" << QString::number (aDocument->StorageVersion())
83 << "Folder" << (aDocument->IsStored() ? DFBrowserPane_Tools::ToString (aDocument->Folder()) : "")
84 << "HasRequestedFolder" << DFBrowserPane_Tools::BoolToStr (aDocument->HasRequestedFolder())
85 << "RequestedFolder" << (aDocument->HasRequestedFolder() ? DFBrowserPane_Tools::ToString (aDocument->RequestedFolder()) : "")
86 << "RequestedName" << DFBrowserPane_Tools::ToString (aDocument->RequestedName())
87 << "HasRequestedPreviousVersion" << DFBrowserPane_Tools::BoolToStr (aDocument->HasRequestedPreviousVersion())
88 << "RequestedPreviousVersion" << (aDocument->HasRequestedPreviousVersion() ?
89 DFBrowserPane_Tools::ToString (aDocument->RequestedPreviousVersion()) : "")
90 << "RequestedComment" << DFBrowserPane_Tools::ToString (aDocument->RequestedComment())
d2c90917 91 << "FindFileExtension" << (isDocumentOpened ? DFBrowserPane_Tools::BoolToStr (aDocument->FindFileExtension()) : "")
92 << "FileExtension" << (isDocumentOpened ? DFBrowserPane_Tools::ToString (aDocument->FileExtension()) : "")
93 << "FindDescription" << (isDocumentOpened ? DFBrowserPane_Tools::BoolToStr (aDocument->FindDescription()) : "")
94 << "Description" << (isDocumentOpened ? DFBrowserPane_Tools::ToString (aDocument->Description()) : "")
14bbbdcb 95 << "IsModified" << DFBrowserPane_Tools::BoolToStr (aDocument->IsModified())
96 << "IsOpened" << DFBrowserPane_Tools::BoolToStr (aDocument->IsOpened())
d2c90917 97 << "CanClose" << DFBrowserPane_Tools::ToName(DB_CDM_CAN_CLOSE_STATUS, aDocument->CanClose()).ToCString()
14bbbdcb 98 << "ReferenceCounter" << QString::number (aDocument->ReferenceCounter());
99
d2c90917 100 // TDocStd_Document methods
101 TCollection_AsciiString aDocumentDataInfo = !aDocument->GetData().IsNull()
102 ? DFBrowserPane_Tools::GetPointerInfo (aDocument->GetData()).ToCString() : "";
103 theValues << aSeparationStr.ToCString() << aSeparationStr.ToCString()
104 << STANDARD_TYPE (TDocStd_Document)->Name() << ""
105 << aSeparationStr.ToCString() << aSeparationStr.ToCString()
106 << "IsSaved" << DFBrowserPane_Tools::BoolToStr (aDocument->IsSaved())
107 << "IsChanged" << DFBrowserPane_Tools::BoolToStr (aDocument->IsChanged())
108 << "GetSavedTime" << DFBrowserPane_Tools::BoolToStr (aDocument->GetSavedTime())
109 << "GetName" << (aDocument->IsSaved() ? DFBrowserPane_Tools::ToString (aDocument->GetName()) : "")
110 << "GetPath" << (aDocument->IsSaved() ? DFBrowserPane_Tools::ToString (aDocument->GetPath()) : "")
111 << "GetData" << aDocumentDataInfo.ToCString()
112 << "Main" << DFBrowserPane_Tools::GetEntry (aDocument->Main()).ToCString()
113 << "IsEmpty" << DFBrowserPane_Tools::BoolToStr (aDocument->IsEmpty())
114 << "IsValid" << DFBrowserPane_Tools::BoolToStr (aDocument->IsValid())
115 << "HasOpenCommand" << DFBrowserPane_Tools::BoolToStr (aDocument->HasOpenCommand())
116 << "GetUndoLimit" << QString::number (aDocument->GetUndoLimit())
117 << "GetAvailableUndos" << QString::number (aDocument->GetAvailableUndos())
118 << "GetUndos" << convertToString (aDocument->GetUndos())
119 << "GetAvailableRedos" << QString::number (aDocument->GetAvailableRedos())
120 << "GetRedos" << convertToString (aDocument->GetRedos())
121#if OCC_VERSION_HEX > 0x070100
122 << "EmptyLabelsSavingMode" << DFBrowserPane_Tools::BoolToStr (aDocument->EmptyLabelsSavingMode())
123#endif
124 << "IsNestedTransactionMode" << DFBrowserPane_Tools::BoolToStr (aDocument->IsNestedTransactionMode())
125 << "ModificationMode" << DFBrowserPane_Tools::BoolToStr (aDocument->ModificationMode());
14bbbdcb 126}
127
128// =======================================================================
129// function : GetShortAttributeInfo
130// purpose :
131// =======================================================================
132void DFBrowserPane_TDocStdOwner::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
133 QList<QVariant>& theValues)
134{
135 Handle(TDocStd_Owner) anAttribute = Handle(TDocStd_Owner)::DownCast (theAttribute);
136 if (anAttribute.IsNull())
137 return;
138
139 Handle(TDocStd_Document) aDocument = anAttribute->GetDocument();
140 if (aDocument.IsNull())
141 return;
142
143 theValues.append (DFBrowserPane_Tools::ToString (aDocument->StorageFormat()));
144}
145
146// =======================================================================
147// function : convertToString
148// purpose :
149// =======================================================================
150QString DFBrowserPane_TDocStdOwner::convertToString (const TDF_DeltaList& theDeltaList)
151{
152 QStringList aNames;
153
154 for (TDF_ListIteratorOfDeltaList aDeltaIt (theDeltaList); aDeltaIt.More(); aDeltaIt.Next())
155 {
156 QString aName = DFBrowserPane_Tools::ToString (aDeltaIt.Value()->Name());
157 aNames.append (aName.isEmpty() ? "-" : aName);
158 }
159 return QString ("[%1]").arg (aNames.join (";"));
160}
161
162// =======================================================================
163// function : convertToString
164// purpose :
165// =======================================================================
166QString DFBrowserPane_TDocStdOwner::convertToString (const TColStd_SequenceOfExtendedString& theExtensions)
167{
168 QStringList aNames;
169 for (Standard_Integer anExtensionId = 1, aNumber = theExtensions.Length(); anExtensionId <= aNumber; anExtensionId++)
170 aNames.append (DFBrowserPane_Tools::ToString (theExtensions(anExtensionId)));
171
172 return QString ("[%1]").arg (aNames.join (";"));
173}