itemlibraryview.cpp 3.25 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
18 19 20 21 22
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25

26 27
#include "itemlibraryview.h"
#include "itemlibrarywidget.h"
28
#include <import.h>
29
#include <importmanagerview.h>
30
#include <rewriterview.h>
31 32 33

namespace QmlDesigner {

34 35 36 37
ItemLibraryView::ItemLibraryView(QObject* parent)
    : AbstractView(parent),
      m_importManagerView(new ImportManagerView(this))

38 39 40 41 42 43 44 45 46
{

}

ItemLibraryView::~ItemLibraryView()
{

}

47 48 49 50 51 52 53
bool ItemLibraryView::hasWidget() const
{
    return true;
}

WidgetInfo ItemLibraryView::widgetInfo()
{
54 55 56 57
    if (m_widget.isNull()) {
        m_widget = new ItemLibraryWidget;
        m_widget->setImportsWidget(m_importManagerView->widgetInfo().widget);
    }
58

59 60
    return createWidgetInfo(m_widget.data(),
                            new WidgetInfo::ToolBarWidgetDefaultFactory<ItemLibraryWidget>(m_widget.data()),
61
                            QStringLiteral("Library"),
62 63
                            WidgetInfo::LeftPane,
                            0);
64 65
}

66 67 68
void ItemLibraryView::modelAttached(Model *model)
{
    AbstractView::modelAttached(model);
69
    m_widget->clearSearchFilter();
70 71
    m_widget->setModel(model);
    updateImports();
72
    model->attachView(m_importManagerView);
73
    m_hasErrors = !rewriterView()->errors().isEmpty();
74 75 76 77
}

void ItemLibraryView::modelAboutToBeDetached(Model *model)
{
78 79
    model->detachView(m_importManagerView);

80
    AbstractView::modelAboutToBeDetached(model);
81

82
    m_widget->setModel(0);
83 84
}

85
void ItemLibraryView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
86
{
87
    updateImports();
88 89
}

Marco Bubke's avatar
Marco Bubke committed
90 91 92 93 94 95 96 97
void ItemLibraryView::setResourcePath(const QString &resourcePath)
{
    if (m_widget.isNull())
        m_widget = new ItemLibraryWidget;

    m_widget->setResourcePath(resourcePath);
}

98 99 100 101 102 103 104 105 106
void ItemLibraryView::documentMessagesChanged(const QList<DocumentMessage> &errors, const QList<DocumentMessage> &)
{
    if (m_hasErrors && errors.isEmpty())
        /* For some reason we have to call update from the event loop */
        QTimer::singleShot(0, m_widget, &ItemLibraryWidget::updateModel);

     m_hasErrors = !errors.isEmpty();
}

107 108 109 110 111
void ItemLibraryView::updateImports()
{
    m_widget->updateModel();
}

112
} //QmlDesigner