78 return mHelpModel; |
79 return mHelpModel; |
79 } |
80 } |
80 |
81 |
81 QAbstractItemModel* HelpDataProvider::getSearchData(const QString& key) |
82 QAbstractItemModel* HelpDataProvider::getSearchData(const QString& key) |
82 { |
83 { |
83 delete mSearhResultModel; |
84 /* if(key.isEmpty()) |
84 mSearhResultModel = NULL; |
85 { |
85 |
86 return mKeywordModel; |
86 mSearhResultModel = new HelpProxyModel();; |
87 }*/ |
87 mSearhResultModel->setSourceModel(mKeywordModel); |
88 |
88 mSearhResultModel->setFilterRole(KeywordRole); |
89 if(key == mLastSrhKey) |
|
90 { |
|
91 return mSearhResultModel; |
|
92 } |
|
93 /* |
|
94 if(!mLastSrhKey.isEmpty() && HelpUtils::findStr(key, mLastSrhKey) != -1) |
|
95 { |
|
96 searchInResult(key); |
|
97 } |
|
98 else |
|
99 { |
|
100 mSearhResultModel->removeRows(0, mSearhResultModel->rowCount()); |
|
101 searchInAllData((HelpStandardItem*)mKeywordModel->invisibleRootItem(), key); |
|
102 }*/ |
|
103 |
|
104 mLastSrhKey = key; |
89 mSearhResultModel->setFilterRegExp(key); |
105 mSearhResultModel->setFilterRegExp(key); |
90 |
106 |
|
107 |
91 return mSearhResultModel; |
108 return mSearhResultModel; |
92 } |
109 } |
93 |
110 |
94 void HelpDataProvider::setHelpContentUrl(const QString& uid, const QString& href) |
111 void HelpDataProvider::setHelpContentUrl(const QString& uid, const QString& href) |
95 { |
112 { |
247 QStringList temp; |
265 QStringList temp; |
248 temp = str.split(SPECIALCHAR); |
266 temp = str.split(SPECIALCHAR); |
249 HelpStandardItem* item = new HelpStandardItem(temp[1]); |
267 HelpStandardItem* item = new HelpStandardItem(temp[1]); |
250 item->setData(temp[0], HrefRole); |
268 item->setData(temp[0], HrefRole); |
251 itemParent->appendRow(item); |
269 itemParent->appendRow(item); |
|
270 constructKeywordModel(temp[1], uid, temp[0]); |
252 } |
271 } |
253 |
272 |
254 file.close(); |
273 file.close(); |
255 itemParent->sortChildren(0, HelpUtils::sortOrder()); |
274 itemParent->sortChildren(0, HelpUtils::sortOrder()); |
256 return itemParent; |
275 return itemParent; |
316 itemApp->sortChildren(0, HelpUtils::sortOrder()); |
335 itemApp->sortChildren(0, HelpUtils::sortOrder()); |
317 mHelpModel->appendRow(itemApp); |
336 mHelpModel->appendRow(itemApp); |
318 } |
337 } |
319 } |
338 } |
320 |
339 |
321 void HelpDataProvider::constructKeywordModel(const QString& path) |
340 /* |
322 { |
341 void HelpDataProvider::searchInAllData(HelpStandardItem* item, const QString& key) |
323 QString pathKeyword(path); |
342 { |
324 pathKeyword.append(BACKSLASH); |
343 if(item->rowCount() > 0) |
325 pathKeyword.append(KEYWORDXML); |
344 { |
326 |
345 for(int i = 0; i < item->rowCount(); i++) |
327 QFile file(pathKeyword); |
346 { |
328 if (!file.open(QIODevice::ReadOnly)) { |
347 searchInAllData((HelpStandardItem*)item->child(i),key); |
329 return; |
348 } |
330 } |
349 } |
331 |
350 else |
332 //construct keyword model, title and keyword is one to more |
351 { |
333 QXmlStreamReader reader(&file); |
352 if(HelpUtils::findStr(item->text(), key) != -1) |
334 QString keyword; |
353 { |
335 QString title; |
354 HelpStandardItem* itemSearch = new HelpStandardItem(item->text()); |
336 |
355 itemSearch->setData(item->data(UidRole), UidRole); |
337 while (!reader.atEnd()) { |
356 itemSearch->setData(item->data(HrefRole), HrefRole); |
338 if (!reader.readNextStartElement()) |
357 mSearhResultModel->appendRow(itemSearch); |
339 { |
358 } |
340 continue; |
359 } |
341 } |
360 } |
342 if (reader.name() == "text") |
361 |
343 { |
362 void HelpDataProvider::searchInResult(const QString& key) |
344 keyword = reader.readElementText(); |
363 { |
345 } |
364 for(int i = 0; i < mSearhResultModel->rowCount();) |
346 else if (reader.name() == "target") |
365 { |
347 { |
366 QStandardItem* item = mSearhResultModel->item(i); |
348 QString href = reader.attributes().value("href").toString(); |
367 if(HelpUtils::findStr(item->text(), key) == -1) |
349 HelpStandardItem* item = findItemWithHref((HelpStandardItem *)(mKeywordModel->invisibleRootItem()), href); |
368 { |
350 QStringList keywordLst; |
369 mSearhResultModel->removeRow(i); |
351 if(item) |
370 } |
352 { |
371 else |
353 keywordLst = item->data(KeywordRole).toStringList(); |
372 { |
354 keywordLst.append(keyword); |
373 i++; |
355 item->setData(keywordLst,KeywordRole); |
374 } |
356 } |
375 } |
357 else |
376 } |
358 { |
377 */ |
359 item = new HelpStandardItem(reader.readElementText()); |
378 void HelpDataProvider::constructKeywordModel(const QString& title, const QString& uid, const QString& href) |
360 item->setData(path, UidRole); |
379 { |
361 item->setData(href, HrefRole); |
380 HelpStandardItem* itemTemp = new HelpStandardItem(title); |
362 |
381 itemTemp->setData(uid, UidRole); |
363 keywordLst.append(keyword); |
382 itemTemp->setData(href, HrefRole); |
364 item->setData(keywordLst,KeywordRole); |
383 mKeywordModel->appendRow(itemTemp); |
365 mKeywordModel->appendRow(item); |
|
366 } |
|
367 } |
|
368 } |
|
369 file.close(); |
|
370 mKeywordModel->sort(0, HelpUtils::sortOrder()); |
|
371 } |
384 } |
372 |
385 |
373 HelpStandardItem* HelpDataProvider::findItemWithHref(HelpStandardItem* itemParent, const QString& href) |
386 HelpStandardItem* HelpDataProvider::findItemWithHref(HelpStandardItem* itemParent, const QString& href) |
374 { |
387 { |
375 for(int i = 0; i < itemParent->rowCount(); i++) |
388 for(int i = 0; i < itemParent->rowCount(); i++) |