FreeCAD

Форк
0
/
TreeView.cpp 
91 строка · 3.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25
#ifndef _PreComp_
26
# include <QMouseEvent>
27
#endif
28

29
#include "TreeView.h"
30
#include "Application.h"
31
#include "Document.h"
32
#include "DocumentModel.h"
33
#include "MainWindow.h"
34
#include "MDIView.h"
35
#include "ViewProvider.h"
36

37
using namespace Gui;
38

39
TreeView::TreeView(QWidget* parent)
40
  : QTreeView(parent)
41
{
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
51
}
52

53
TreeView::~TreeView() = default;
54

55
void TreeView::mouseDoubleClickEvent (QMouseEvent * event)
56
{
57
    QModelIndex index = indexAt(event->pos());
58
    if (!index.isValid() || index.internalPointer() == Application::Instance)
59
        return;
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();
66
        if (!view)
67
            return;
68
        getMainWindow()->setActiveWindow(view);
69
    }
70
    else if (item->isDerivedFrom<ViewProvider>()) {
71
        if (!static_cast<ViewProvider*>(item)->doubleClicked())
72
            QTreeView::mouseDoubleClickEvent(event);
73
    }
74
}
75

76
void TreeView::rowsInserted (const QModelIndex & parent, int start, int end)
77
{
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);
86
            }
87
        }
88
    }
89
}
90

91
#include "moc_TreeView.cpp"
92

93

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.