"Fossies" - the Fresh Open Source Software Archive

Member "qt-creator-opensource-src-4.15.1/src/plugins/qmldesigner/components/propertyeditor/itemfiltermodel.cpp" (8 Jun 2021, 3250 Bytes) of package /linux/misc/qt-creator-opensource-src-4.15.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "itemfiltermodel.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: opensource-src-4.15.0_vs_opensource-src-4.15.1.

    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2019 The Qt Company Ltd.
    4 ** Contact: https://www.qt.io/licensing/
    5 **
    6 ** This file is part of Qt Creator.
    7 **
    8 ** Commercial License Usage
    9 ** Licensees holding valid commercial Qt licenses may use this file in
   10 ** accordance with the commercial license agreement provided with the
   11 ** Software or, alternatively, in accordance with the terms contained in
   12 ** a written agreement between you and The Qt Company. For licensing terms
   13 ** and conditions see https://www.qt.io/terms-conditions. For further
   14 ** information use the contact form at https://www.qt.io/contact-us.
   15 **
   16 ** GNU General Public License Usage
   17 ** Alternatively, this file may be used under the terms of the GNU
   18 ** General Public License version 3 as published by the Free Software
   19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
   20 ** included in the packaging of this file. Please review the following
   21 ** information to ensure the GNU General Public License requirements will
   22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
   23 **
   24 ****************************************************************************/
   25 
   26 #include "itemfiltermodel.h"
   27 
   28 #include <abstractview.h>
   29 #include <model.h>
   30 #include <nodemetainfo.h>
   31 
   32 #include <QFileDialog>
   33 #include <QDirIterator>
   34 #include <qmlmodelnodeproxy.h>
   35 
   36 ItemFilterModel::ItemFilterModel(QObject *parent) :
   37     QObject(parent), m_typeFilter("QtQuick.Item"), m_lock(false), m_selectionOnly(false)
   38 {
   39 }
   40 
   41 void ItemFilterModel::setModelNodeBackend(const QVariant &modelNodeBackend)
   42 {
   43 
   44     auto modelNodeBackendObject = modelNodeBackend.value<QObject*>();
   45 
   46     const auto backendObjectCasted =
   47             qobject_cast<const QmlDesigner::QmlModelNodeProxy *>(modelNodeBackendObject);
   48 
   49     if (backendObjectCasted)
   50         m_modelNode = backendObjectCasted->qmlObjectNode().modelNode();
   51 
   52     setupModel();
   53     emit modelNodeBackendChanged();
   54 }
   55 
   56 void ItemFilterModel::setTypeFilter(const QString &filter)
   57 {
   58     if (m_typeFilter != filter) {
   59         m_typeFilter = filter;
   60         setupModel();
   61     }
   62 }
   63 
   64 void ItemFilterModel::setSelectionOnly(bool value)
   65 {
   66     if (m_selectionOnly != value) {
   67         m_selectionOnly = value;
   68         setupModel();
   69     }
   70 }
   71 
   72 QString ItemFilterModel::typeFilter() const
   73 {
   74     return m_typeFilter;
   75 }
   76 
   77 bool ItemFilterModel::selectionOnly() const
   78 {
   79     return m_selectionOnly;
   80 }
   81 
   82 void ItemFilterModel::registerDeclarativeType()
   83 {
   84     qmlRegisterType<ItemFilterModel>("HelperWidgets",2,0,"ItemFilterModel");
   85 }
   86 
   87 QVariant ItemFilterModel::modelNodeBackend() const
   88 {
   89     return QVariant();
   90 }
   91 
   92 
   93 void ItemFilterModel::setupModel()
   94 {
   95     if (!m_modelNode.isValid() || !m_modelNode.view()->isAttached())
   96         return;
   97 
   98     m_lock = true;
   99     m_model.clear();
  100 
  101     const auto nodes = m_selectionOnly ? m_modelNode.view()->selectedModelNodes() : m_modelNode.view()->allModelNodes();
  102 
  103     for (const QmlDesigner::ModelNode &node : nodes) {
  104         if (node.hasId() && node.metaInfo().isValid() && node.metaInfo().isSubclassOf(m_typeFilter.toUtf8()))
  105             m_model.append(node.id());
  106     }
  107 
  108     m_lock = false;
  109 
  110     emit itemModelChanged();
  111 }
  112 
  113 QStringList ItemFilterModel::itemModel() const
  114 {
  115     return m_model;
  116 }