• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/project

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • project
projectproxymodel.cpp
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2008 Aleix Pol <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "projectproxymodel.h"
21 #include <project/projectmodel.h>
22 
23 ProjectProxyModel::ProjectProxyModel(QObject * parent)
24  : QSortFilterProxyModel(parent)
25  , m_showTargets(true)
26 {
27  setDynamicSortFilter(true);
28  sort(0); //initiate sorting regardless of the view
29 }
30 
31 KDevelop::ProjectModel * ProjectProxyModel::projectModel() const
32 {
33  return qobject_cast<KDevelop::ProjectModel*>( sourceModel() );
34 }
35 
36 bool ProjectProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const
37 {
38  KDevelop::ProjectBaseItem *iLeft=projectModel()->itemFromIndex(left), *iRight=projectModel()->itemFromIndex(right);
39  if(!iLeft || !iRight) return false;
40 
41  return( iLeft->lessThan( iRight ) );
42 }
43 
44 void ProjectProxyModel::showTargets(bool visible)
45 {
46  if (visible != m_showTargets) {
47  m_showTargets = visible;
48  invalidateFilter();
49  }
50 }
51 
52 bool ProjectProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
53 {
54  if (m_showTargets) {
55  return true;
56  }
57  else {
58  // Get the base item for the associated parent and row.
59  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
60  auto *item = projectModel()->itemFromIndex(index);
61  // If it's a target, return false, otherwise true.
62  return item->type() != KDevelop::ProjectBaseItem::Target
63  && item->type() != KDevelop::ProjectBaseItem::LibraryTarget
64  && item->type() != KDevelop::ProjectBaseItem::ExecutableTarget;
65  }
66 }
67 
68 QModelIndex ProjectProxyModel::proxyIndexFromItem(KDevelop::ProjectBaseItem* item) const
69 {
70  return mapFromSource(projectModel()->indexFromItem(item));
71 }
72 
73 KDevelop::ProjectBaseItem* ProjectProxyModel::itemFromProxyIndex( const QModelIndex& idx ) const
74 {
75  return projectModel()->itemFromIndex( mapToSource(idx));
76 }
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
KDevelop::ProjectBaseItem
Interface that allows a developer to implement the three basic types of items you would see in a mult...
Definition: projectmodel.h:101
KDevelop::ProjectBaseItem::type
virtual int type() const
Definition: projectmodel.cpp:298
KDevelop::ProjectBaseItem::ExecutableTarget
Definition: projectmodel.h:113
ProjectProxyModel::itemFromProxyIndex
KDevelop::ProjectBaseItem * itemFromProxyIndex(const QModelIndex &) const
Definition: projectproxymodel.cpp:73
KDevelop::ProjectModel
Class providing some convenience methods for accessing the project model.
Definition: projectmodel.h:420
QSortFilterProxyModel::sort
virtual void sort(int column, Qt::SortOrder order)
ProjectProxyModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: projectproxymodel.cpp:52
QSortFilterProxyModel::mapToSource
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
KDevelop::ProjectModel::itemFromIndex
ProjectBaseItem * itemFromIndex(const QModelIndex &) const
Definition: projectmodel.cpp:967
ProjectProxyModel::ProjectProxyModel
ProjectProxyModel(QObject *parent)
Definition: projectproxymodel.cpp:23
QSortFilterProxyModel
projectmodel.h
QObject
QSortFilterProxyModel::setDynamicSortFilter
void setDynamicSortFilter(bool enable)
ProjectProxyModel::showTargets
void showTargets(bool visible)
Definition: projectproxymodel.cpp:44
KDevelop::ProjectBaseItem::Target
Definition: projectmodel.h:115
QSortFilterProxyModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QSortFilterProxyModel::invalidateFilter
void invalidateFilter()
ProjectProxyModel::lessThan
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Definition: projectproxymodel.cpp:36
KDevelop::ProjectBaseItem::lessThan
virtual bool lessThan(const KDevelop::ProjectBaseItem *) const
Definition: projectmodel.cpp:391
QSortFilterProxyModel::mapFromSource
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
QModelIndex
ProjectProxyModel::proxyIndexFromItem
QModelIndex proxyIndexFromItem(KDevelop::ProjectBaseItem *item) const
Definition: projectproxymodel.cpp:68
projectproxymodel.h
KDevelop::ProjectBaseItem::LibraryTarget
Definition: projectmodel.h:114
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:37:59 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/project

Skip menu "kdevplatform/project"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal