Menu

[c54480]: / findresultmodel.cpp  Maximize  Restore  History

Download this file

280 lines (217 with data), 6.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#include <QtGui>
#include "findresultitem.h"
#include "findresultmodel.h"
#include "settings.h"
#include "treeitem.h"
extern Settings settings;
FindResultModel::FindResultModel( QObject *parent)
: QAbstractItemModel(parent)
{
QVector<QVariant> rootData;
rootData << "Heading";
rootItem = new FindResultItem(rootData);
showParentsLevel = settings.value("/satellite/findResults/showParentsLevel", 1).toInt();
}
FindResultModel::~FindResultModel()
{
delete rootItem;
}
void FindResultModel::clear()
{
if (rootItem->childCount()>0)
removeRows (0,rowCount (QModelIndex ()));
}
int FindResultModel::columnCount(const QModelIndex & /* parent */) const
{
return rootItem->columnCount();
}
QVariant FindResultModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
FindResultItem *item = getItem(index);
return item->data(index.column());
}
Qt::ItemFlags FindResultModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant FindResultModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
return QVariant();
}
QModelIndex FindResultModel::index (FindResultItem *fri)
{
if (!fri->parent())
return QModelIndex();
else
return createIndex (fri->row(),0,fri);
}
QModelIndex FindResultModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
FindResultItem *parentItem = getItem(parent);
FindResultItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
bool FindResultModel::insertColumns(int position, int columns, const QModelIndex &parent)
{
bool success;
beginInsertColumns(parent, position, position + columns - 1);
success = rootItem->insertColumns(position, columns);
endInsertColumns();
return success;
}
bool FindResultModel::insertRows(int position, int rows, const QModelIndex &parent)
{
FindResultItem *parentItem = getItem(parent);
bool success;
beginInsertRows(parent, position, position + rows - 1);
success = parentItem->insertChildren(position, rows, rootItem->columnCount());
endInsertRows();
return success;
}
QModelIndex FindResultModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
FindResultItem *childItem = getItem(index);
FindResultItem *parentItem = childItem->parent();
if (parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
bool FindResultModel::removeColumns(int position, int columns, const QModelIndex &parent)
{
bool success;
beginRemoveColumns(parent, position, position + columns - 1);
success = rootItem->removeColumns(position, columns);
endRemoveColumns();
if (rootItem->columnCount() == 0)
removeRows(0, rowCount());
return success;
}
bool FindResultModel::removeRows(int position, int rows, const QModelIndex &parent)
{
FindResultItem *parentItem = getItem(parent);
bool success = true;
beginRemoveRows(parent, position, position + rows - 1);
success = parentItem->removeChildren(position, rows);
endRemoveRows();
return success;
}
int FindResultModel::rowCount(const QModelIndex &parent) const
{
FindResultItem *parentItem = getItem(parent);
return parentItem->childCount();
}
bool FindResultModel::setData(const QModelIndex &index, const QVariant &value,
int role)
{
if (role != Qt::EditRole)
return false;
FindResultItem *item = getItem(index);
bool result = item->setData(index.column(), value);
if (result)
emit dataChanged(index, index);
return result;
}
bool FindResultModel::setHeaderData(int section, Qt::Orientation orientation,
const QVariant &value, int role)
{
if (role != Qt::EditRole || orientation != Qt::Horizontal)
return false;
bool result = rootItem->setData(section, value);
if (result)
emit headerDataChanged(orientation, section, section);
return result;
}
FindResultItem* FindResultModel::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
FindResultItem *item = static_cast<FindResultItem*>(index.internalPointer());
if (item) return item;
}
return rootItem;
}
FindResultItem* FindResultModel::addItem (TreeItem *ti)
{
FindResultItem *ni=NULL;
if (ti)
{
QModelIndex parix (index (rootItem));
emit (layoutAboutToBeChanged() );
int n=rowCount (parix);
beginInsertRows (parix,n,n);
if (rootItem->insertChildren (n,1,0) )
{
QString h=ti->getHeadingPlainWithParents( showParentsLevel );
QModelIndex ix=index(n,0,QModelIndex());
setData (ix,QVariant(h),Qt::EditRole);
ni=getItem(ix);
ni->setOriginal (ti);
}
endInsertRows ();
emit (layoutChanged() );
}
return ni;
}
FindResultItem* FindResultModel::addSubItem (FindResultItem *parent,const QString &s, TreeItem *pi, int i)
{
FindResultItem *ni=NULL;
if (pi && parent)
{
QModelIndex parix ( index (parent));
emit (layoutAboutToBeChanged() );
int n=rowCount (parix);
beginInsertRows (parix,n,n);
QModelIndex ix;
if (parent->insertChildren (n,1,0))
{
ix=index(n,0,parix);
setData (ix,QVariant(s),Qt::EditRole);
ni=getItem(ix);
ni->setOriginal (pi);
ni->setOriginalIndex (i);
}
endInsertRows ();
emit (layoutChanged() );
}
return ni;
}
void FindResultModel::setSearchString( const QString &s)
{
searchString=s;
}
QString FindResultModel::getSearchString()
{
return searchString;
}
void FindResultModel::setSearchFlags( QTextDocument::FindFlags f)
{
searchFlags=f;
}
QTextDocument::FindFlags FindResultModel::getSearchFlags()
{
return searchFlags;
}
void FindResultModel::setShowParentsLevel(uint i)
{
showParentsLevel = i;
settings.setValue("/findResults/showParentsLevel", showParentsLevel);
}
uint FindResultModel::getShowParentsLevel()
{
return showParentsLevel;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.