1
/***************************************************************************
2
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
# include <QMouseEvent>
30
#include "Application.h"
32
#include "DocumentModel.h"
33
#include "MainWindow.h"
35
#include "ViewProvider.h"
39
TreeView::TreeView(QWidget* parent)
42
setModel(new DocumentModel(this));
43
QModelIndex root = this->model()->index(0,0,QModelIndex());
44
this->setExpanded(root, true);
45
this->setDragEnabled(true);
46
this->setAcceptDrops(true);
47
this->setDropIndicatorShown(false);
48
this->setRootIsDecorated(false);
49
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
50
this->setMouseTracking(true); // needed for itemEntered() to work
53
TreeView::~TreeView() = default;
55
void TreeView::mouseDoubleClickEvent (QMouseEvent * event)
57
QModelIndex index = indexAt(event->pos());
58
if (!index.isValid() || index.internalPointer() == Application::Instance)
60
Base::BaseClass* item = nullptr;
61
item = static_cast<Base::BaseClass*>(index.internalPointer());
62
if (item->is<Document>()) {
63
QTreeView::mouseDoubleClickEvent(event);
64
const Gui::Document* doc = static_cast<Gui::Document*>(item);
65
MDIView *view = doc->getActiveView();
68
getMainWindow()->setActiveWindow(view);
70
else if (item->isDerivedFrom<ViewProvider>()) {
71
if (!static_cast<ViewProvider*>(item)->doubleClicked())
72
QTreeView::mouseDoubleClickEvent(event);
76
void TreeView::rowsInserted (const QModelIndex & parent, int start, int end)
78
QTreeView::rowsInserted(parent, start, end);
79
if (parent.isValid()) {
80
auto ptr = static_cast<Base::BaseClass*>(parent.internalPointer());
81
// type is defined in DocumentModel.cpp
82
if (ptr->getTypeId() == Base::Type::fromName("Gui::ApplicationIndex")) {
83
for (int i=start; i<=end;i++) {
84
QModelIndex document = this->model()->index(i, 0, parent);
85
this->expand(document);
91
#include "moc_TreeView.cpp"