userguide/src/HelpDataProvider.cpp
changeset 15 c0dfc135a46c
parent 13 1eb8015a8491
child 18 375271912456
child 24 bce8d4d2cc72
equal deleted inserted replaced
13:1eb8015a8491 15:c0dfc135a46c
    32 
    32 
    33 HelpDataProvider::HelpDataProvider()
    33 HelpDataProvider::HelpDataProvider()
    34 {
    34 {
    35 	mHelpModel = new QStandardItemModel();
    35 	mHelpModel = new QStandardItemModel();
    36 	mKeywordModel = new QStandardItemModel();
    36 	mKeywordModel = new QStandardItemModel();
    37 	mSearhResultModel = NULL;
    37 	mSearhResultModel = new HelpProxyModel();
       
    38 	mSearhResultModel->setSourceModel(mKeywordModel);
    38 }
    39 }
    39 
    40 
    40 HelpDataProvider::~HelpDataProvider()
    41 HelpDataProvider::~HelpDataProvider()
    41 {
    42 {
    42 	delete mHelpModel;
    43 	delete mHelpModel;
    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 {
   155 				continue;
   172 				continue;
   156 			}
   173 			}
   157 			constructAppHelp(path);
   174 			constructAppHelp(path);
   158 		}
   175 		}
   159 	}
   176 	}
       
   177 	mKeywordModel->sort(0, HelpUtils::sortOrder());
   160 }
   178 }
   161 
   179 
   162 void HelpDataProvider::createBuiltInCategory(const QString& path)
   180 void HelpDataProvider::createBuiltInCategory(const QString& path)
   163 {
   181 {
   164 	QString pathIndex(path);
   182 	QString pathIndex(path);
   197 		uid.append(temp[0]);
   215 		uid.append(temp[0]);
   198 		HelpStandardItem* item = constructCategory2(temp[1], uid);
   216 		HelpStandardItem* item = constructCategory2(temp[1], uid);
   199 		if(item)
   217 		if(item)
   200 		{
   218 		{
   201 			mHelpModel->appendRow(item);
   219 			mHelpModel->appendRow(item);
   202 			constructKeywordModel(uid);
   220 //			constructKeywordModel(uid);
   203 		}
   221 		}
   204 	}
   222 	}
   205 	file.close();
   223 	file.close();
   206 	mHelpModel->sort(0, HelpUtils::sortOrder());
   224 	mHelpModel->sort(0, HelpUtils::sortOrder());
   207 }
   225 }
   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;
   304 			if(!itemApp)
   323 			if(!itemApp)
   305 			{
   324 			{
   306 				itemApp = new HelpStandardItem("Applications");
   325 				itemApp = new HelpStandardItem("Applications");
   307 			}
   326 			}
   308 			itemApp->appendRow(item);
   327 			itemApp->appendRow(item);
   309 			constructKeywordModel(pathTemp);
   328 //			constructKeywordModel(pathTemp);
   310 		}
   329 		}
   311 		file.close();
   330 		file.close();
   312 	}
   331 	}
   313 
   332 
   314 	if(itemApp)
   333 	if(itemApp)
   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++)