1
/* This file is part of the KDE project
2
Copyright (C) 2010-2011 Adam Pigg <adam@piggz.co.uk>
3
Copyright (C) 2010-2014 Jarosław Staniek <staniek@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
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.
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.
20
#ifndef KEXIPROJECTMODEL_H
21
#define KEXIPROJECTMODEL_H
23
#include "kexiextwidgets_export.h"
26
#include <KexiSearchableModel.h>
28
#include <QModelIndex>
29
#include <QAbstractItemModel>
31
class KexiProjectModelItem;
34
class KEXIEXTWIDGETS_EXPORT KexiProjectModel : public QAbstractItemModel, public KexiSearchableModel
38
explicit KexiProjectModel(QObject* parent = 0);
39
virtual ~KexiProjectModel();
42
SearchHighlight = Qt::UserRole + 0 //!< item is highlighted when corresponding global search
43
//!< completion is highlighted
46
KexiProject* project() const;
47
void setProject(KexiProject* prj, const QString& itemsPartClass, QString* partManagerErrorMessages);
48
QString itemsPartClass() const;
49
//! @return number of objects
50
int objectsCount() const;
52
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
53
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
54
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
55
virtual QModelIndex parent(const QModelIndex& child) const;
56
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
57
virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
58
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
60
void updateItemName(KexiPart::Item& item, bool dirty);
61
QModelIndex indexFromItem(KexiProjectModelItem *item) const;
62
KexiProjectModelItem *modelItemFromItem(const KexiPart::Item &item) const;
63
KexiProjectModelItem *modelItemFromName(const QString &name) const;
67
//! @return index of first part item (looking from the top) or invalid item
68
//! if there are no part items
69
QModelIndex firstPartItem() const;
71
//! Implemented for KexiSearchableModel
72
virtual int searchableObjectCount() const;
74
//! Implemented for KexiSearchableModel
75
virtual QModelIndex sourceIndexForSearchableObject(int objectIndex) const;
77
//! Implemented for KexiSearchableModel
78
virtual QVariant searchableData(const QModelIndex &sourceIndex, int role) const;
80
//! Implemented for KexiSearchableModel
81
virtual QString pathFromIndex(const QModelIndex &sourceIndex) const;
83
//! Implemented for KexiSearchableModel
84
virtual bool highlightSearchableObject(const QModelIndex &index);
86
//! Implemented for KexiSearchableModel
87
virtual bool activateSearchableObject(const QModelIndex &index);
89
QPersistentModelIndex itemWithSearchHighlight() const;
91
bool renameItem(KexiPart::Item *item, const QString& newName);
92
bool setItemCaption(KexiPart::Item *item, const QString& newCaption);
95
void slotAddItem(KexiPart::Item *item);
96
void slotRemoveItem(const KexiPart::Item &item);
99
void renameItem(KexiPart::Item *item, const QString& newName, bool *succes);
100
void changeItemCaption(KexiPart::Item *item, const QString& newCaption, bool *succes);
101
void highlightSearchedItem(const QModelIndex &index);
102
void activateSearchedItem(const QModelIndex &index);
105
KexiProjectModelItem* addGroup(KexiPart::Info *info, KexiProjectModelItem *parent) const;
106
KexiProjectModelItem* addItem(KexiPart::Info *info, KexiPart::Item *item,
107
KexiProjectModelItem *parent) const;
109
//! @return index of first part item within children of parentIndex (recursively)
110
QModelIndex firstChildPartItem(const QModelIndex &parentIndex) const;
116
#endif // KEXIPROJECTMODEL_H