1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <DFBrowser_DumpView.hxx>
18 #include <DFBrowser_Item.hxx>
19 #include <DFBrowser_Window.hxx>
20 #include <DFBrowser_TreeLevelView.hxx>
21 #include <OSD_OpenFile.hxx>
22 #include <TreeModel_ModelBase.hxx>
24 #include <QAbstractItemModel>
27 #include <QPlainTextEdit>
28 #include <QTextStream>
31 // =======================================================================
32 // function : onSelectionChanged
34 // =======================================================================
35 void DFBrowser_DumpView::OnTreeViewSelectionChanged (const QItemSelection& theSelected,
36 const QItemSelection&)
38 myTextEdit->setVisible (false);
41 QModelIndexList aSelectedIndices = theSelected.indexes();
42 QModelIndexList aFirstColumnSelectedIndices;
43 for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
45 QModelIndex anIndex = *aSelIt;
46 if (anIndex.column() == 0)
47 aFirstColumnSelectedIndices.append (anIndex);
49 if (aFirstColumnSelectedIndices.size() != 1)
53 const QModelIndex& anIndex = aFirstColumnSelectedIndices.first();
54 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
55 //#define REQUIRE_OCAF_REVIEW:18 : start
56 DFBrowser_ItemPtr anItem;
58 anItem = itemDynamicCast<DFBrowser_Item> (anItemBase);
63 TCollection_AsciiString aFileName = DFBrowser_Window::TmpDirectory();
64 aFileName += "/dfbrowser.txt";
65 // print dump to file(not in a string stream because result might be too long)
66 std::ofstream aFileStream;
67 OSD_OpenStream(aFileStream, aFileName, ios::out);
68 if (anItem->HasAttribute())
70 Handle(TDF_Attribute) anAttribute = anItem->GetAttribute();
71 if (!anAttribute.IsNull())
72 anAttribute->Dump(aFileStream);
74 else if (anItem->HasLabel())
75 anItem->GetLabel().Dump(aFileStream);
78 // read dumped file to fill view
79 QFile aFile (aFileName.ToCString());
80 if (!aFile.open (QIODevice::ReadOnly | QIODevice::Text))
82 QTextStream aStream (&aFile);
83 while (!aStream.atEnd())
85 aDumpInfo.append (QString ("%1\n").arg (aStream.readLine()));
89 aDir.remove (aFileName.ToCString());
90 //#define REQUIRE_OCAF_REVIEW:18 : end
91 if (!aDumpInfo.isEmpty())
93 myTextEdit->setVisible (true);
94 myTextEdit->setPlainText (aDumpInfo);