本文整理汇总了C++中BookmarksItem::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ BookmarksItem::setData方法的具体用法?C++ BookmarksItem::setData怎么用?C++ BookmarksItem::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookmarksItem
的用法示例。
在下文中一共展示了BookmarksItem::setData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readBookmark
void BookmarksModel::readBookmark(QXmlStreamReader *reader, BookmarksItem *parent)
{
BookmarksItem *bookmark = NULL;
if (reader->name() == QLatin1String("folder"))
{
bookmark = addBookmark(FolderBookmark, reader->attributes().value(QLatin1String("id")).toULongLong(), QUrl(), QString(), parent);
bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("added")).toString(), Qt::ISODate), TimeAddedRole);
bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("modified")).toString(), Qt::ISODate), TimeModifiedRole);
while (reader->readNext())
{
if (reader->isStartElement())
{
if (reader->name() == QLatin1String("title"))
{
bookmark->setData(reader->readElementText().trimmed(), TitleRole);
}
else if (reader->name() == QLatin1String("desc"))
{
bookmark->setData(reader->readElementText().trimmed(), DescriptionRole);
}
else if (reader->name() == QLatin1String("folder") || reader->name() == QLatin1String("bookmark") || reader->name() == QLatin1String("separator"))
{
readBookmark(reader, bookmark);
}
else if (reader->name() == QLatin1String("info"))
{
while (reader->readNext())
{
if (reader->isStartElement())
{
if (reader->name() == QLatin1String("metadata") && reader->attributes().value(QLatin1String("owner")).toString().startsWith("http://otter-browser.org/"))
{
while (reader->readNext())
{
if (reader->isStartElement())
{
if (reader->name() == QLatin1String("keyword"))
{
bookmark->setData(reader->readElementText().trimmed(), KeywordRole);
}
else
{
reader->skipCurrentElement();
}
}
else if (reader->isEndElement() && reader->name() == QLatin1String("metadata"))
{
break;
}
}
}
else
{
reader->skipCurrentElement();
}
}
else if (reader->isEndElement() && reader->name() == QLatin1String("info"))
{
break;
}
}
}
else
{
reader->skipCurrentElement();
}
}
else if (reader->isEndElement() && reader->name() == QLatin1String("folder"))
{
break;
}
else if (reader->hasError())
{
return;
}
}
}
else if (reader->name() == QLatin1String("bookmark"))
{
bookmark = addBookmark(UrlBookmark,reader->attributes().value(QLatin1String("id")).toULongLong(), reader->attributes().value(QLatin1String("href")).toString(), QString(), parent);
bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("added")).toString(), Qt::ISODate), TimeAddedRole);
bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("modified")).toString(), Qt::ISODate), TimeModifiedRole);
bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("visited")).toString(), Qt::ISODate), TimeVisitedRole);
while (reader->readNext())
{
if (reader->isStartElement())
{
if (reader->name() == QLatin1String("title"))
{
bookmark->setData(reader->readElementText().trimmed(), TitleRole);
}
else if (reader->name() == QLatin1String("desc"))
{
bookmark->setData(reader->readElementText().trimmed(), DescriptionRole);
}
else if (reader->name() == QLatin1String("info"))
{
//.........这里部分代码省略.........
示例2: processElement
void HtmlBookmarksImporter::processElement(const QWebElement &element)
{
if (element.tagName().toLower() == QLatin1String("h3"))
{
BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), element.toPlainText(), getCurrentFolder());
const QString keyword = element.attribute(QLatin1String("SHORTCUTURL"));
if (!BookmarksManager::hasKeyword(keyword))
{
bookmark->setData(keyword, BookmarksModel::KeywordRole);
}
if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty())
{
const QDateTime time = QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt());
bookmark->setData(time, BookmarksModel::TimeAddedRole);
bookmark->setData(time, BookmarksModel::TimeModifiedRole);
}
setCurrentFolder(bookmark);
}
else if (element.tagName().toLower() == QLatin1String("a"))
{
const QUrl url(element.attribute(QLatin1String("href")));
if (!allowDuplicates() && BookmarksManager::hasBookmark(url))
{
return;
}
BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, url, element.toPlainText(), getCurrentFolder());
const QString keyword = element.attribute(QLatin1String("SHORTCUTURL"));
if (!BookmarksManager::hasKeyword(keyword))
{
bookmark->setData(keyword, BookmarksModel::KeywordRole);
}
if (element.parent().nextSibling().tagName().toLower() == QLatin1String("dd"))
{
bookmark->setData(element.parent().nextSibling().toPlainText(), BookmarksModel::DescriptionRole);
}
if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty())
{
bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()), BookmarksModel::TimeAddedRole);
}
if (!element.attribute(QLatin1String("LAST_MODIFIED")).isEmpty())
{
bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_MODIFIED")).toUInt()), BookmarksModel::TimeModifiedRole);
}
if (!element.attribute(QLatin1String("LAST_VISITED")).isEmpty())
{
bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_VISITED")).toUInt()), BookmarksModel::TimeVisitedRole);
}
}
else if (element.tagName().toLower() == QLatin1String("hr"))
{
BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder());
}
const QWebElementCollection descendants = element.findAll(QLatin1String("*"));
for (int i = 0; i < descendants.count(); ++i)
{
if (descendants.at(i).parent() == element)
{
processElement(descendants.at(i));
}
}
if (element.tagName().toLower() == QLatin1String("dl"))
{
goToParent();
}
}
示例3: import
bool OperaBookmarksImporter::import()
{
QTextStream stream(m_file);
stream.setCodec("UTF-8");
QString line = stream.readLine();
if (line != QLatin1String("Opera Hotlist version 2.0"))
{
return false;
}
BookmarksItem *bookmark = NULL;
OperaBookmarkEntry type = NoEntry;
bool isHeader = true;
handleOptions();
while (!stream.atEnd())
{
line = stream.readLine();
if (isHeader && (line.isEmpty() || line.at(0) != QLatin1Char('#')))
{
continue;
}
isHeader = false;
if (line.startsWith(QLatin1String("#URL")))
{
bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, QUrl(), QString(), getCurrentFolder());
type = UrlEntry;
}
else if (line.startsWith(QLatin1String("#FOLDER")))
{
bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), QString(), getCurrentFolder());
type = FolderStartEntry;
}
else if (line.startsWith(QLatin1String("#SEPERATOR")))
{
bookmark = BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder());
type = SeparatorEntry;
}
else if (line == QLatin1String("-"))
{
type = FolderEndEntry;
}
else if (line.startsWith(QLatin1String("\tURL=")) && bookmark)
{
const QUrl url(line.section(QLatin1Char('='), 1, -1));
if (!allowDuplicates() && BookmarksManager::hasBookmark(url))
{
bookmark->remove();
bookmark = NULL;
}
else
{
bookmark->setData(url, BookmarksModel::UrlRole);
}
}
else if (line.startsWith(QLatin1String("\tNAME=")) && bookmark)
{
bookmark->setData(line.section(QLatin1Char('='), 1, -1), BookmarksModel::TitleRole);
}
else if (line.startsWith(QLatin1String("\tDESCRIPTION=")) && bookmark)
{
bookmark->setData(line.section(QLatin1Char('='), 1, -1).replace(QLatin1String("\x02\x02"), QLatin1String("\n")), BookmarksModel::DescriptionRole);
}
else if (line.startsWith(QLatin1String("\tSHORT NAME=")) && bookmark)
{
const QString keyword = line.section(QLatin1Char('='), 1, -1);
if (!BookmarksManager::hasKeyword(keyword))
{
bookmark->setData(keyword, BookmarksModel::KeywordRole);
}
}
else if (line.startsWith(QLatin1String("\tCREATED=")) && bookmark)
{
bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeAddedRole);
}
else if (line.startsWith(QLatin1String("\tVISITED=")) && bookmark)
{
bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeVisitedRole);
}
else if (line.isEmpty())
{
if (bookmark)
{
if (type == FolderStartEntry)
{
setCurrentFolder(bookmark);
}
bookmark = NULL;
}
else if (type == FolderEndEntry)
{
//.........这里部分代码省略.........