本文整理汇总了C++中QTreeWidgetItem::read方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeWidgetItem::read方法的具体用法?C++ QTreeWidgetItem::read怎么用?C++ QTreeWidgetItem::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dragMoveEvent
void TreeWidget::dragMoveEvent(QDragMoveEvent* event)
{
const QMimeData* mimeData = event->mimeData();
bool accept = false;
if (mimeData->hasUrls()) {
accept = true;
}
else if (mimeData->hasFormat(m_mimeType)) {
QTreeWidgetItem* itemUnderMouse = itemAt(event->pos());
if (!itemUnderMouse) {
return;
}
bool underMouseIsFolder = (itemUnderMouse && itemUnderMouse->text(1).isEmpty());
int top = visualItemRect(itemUnderMouse).top();
int bottom = visualItemRect(itemUnderMouse).bottom();
int y = event->pos().y();
bool overEdgeOfItem = (y >= top - 1 && y <= top + 1) || (y <= bottom + 1 && y >= bottom - 1);
QByteArray ba = mimeData->data(m_mimeType);
QDataStream stream(&ba, QIODevice::ReadOnly);
while (!stream.atEnd()) {
QTreeWidgetItem* dragItem = new QTreeWidgetItem;
dragItem->read(stream);
bool parentIsRoot = dragItem->data(0, ITEM_IS_TOPLEVEL).toBool();
QString oldParentTitle = dragItem->data(0, ITEM_PARENT_TITLE).toString();
bool itemIsFolder = dragItem->text(1).isEmpty();
if (dragItem->text(0) != _bookmarksMenu
&& dragItem->text(0) != _bookmarksToolbar) {
if (!itemUnderMouse->parent() && !parentIsRoot && overEdgeOfItem) {
accept = true;
break;
}
bool parentsAreDifferent = parentIsRoot
? itemUnderMouse->parent() != 0
: (!itemUnderMouse->parent() || itemUnderMouse->parent()->text(0) != oldParentTitle);
bool canHasSubFolder = !itemUnderMouse->parent()
|| itemUnderMouse->parent() == invisibleRootItem()
|| itemUnderMouse->parent()->text(0) == _bookmarksToolbar;
if (!underMouseIsFolder && parentsAreDifferent) {
if (!itemIsFolder) {
accept = true;
break;
}
else if (!itemUnderMouse->parent()
|| (dragItem->text(0) != itemUnderMouse->parent()->text(0)
&& canHasSubFolder)) {
accept = true;
break;
}
}
else if (underMouseIsFolder) {
if (itemIsFolder && itemUnderMouse->text(0) == _bookmarksToolbar
&& (parentIsRoot || oldParentTitle != _bookmarksToolbar)) {
accept = true;
break;
}
else if (!itemIsFolder && oldParentTitle != itemUnderMouse->text(0)) {
accept = true;
break;
}
}
}
}
}
QTreeWidget::dragMoveEvent(event);
if (accept) {
event->acceptProposedAction();
}
else {
event->ignore();
}
}
示例2: read
void QTreeWidgetItemProto::read(QDataStream &in)
{
QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject());
if (item)
item->read(in);
}
示例3: dropMimeData
bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int,
const QMimeData* data, Qt::DropAction action)
{
if (action == Qt::IgnoreAction) {
return true;
}
if (parent && !parent->text(1).isEmpty()) { // parent is a bookmark, go one level up!
parent = parent->parent();
}
if (!parent) {
parent = invisibleRootItem();
}
bool ok = false;
if (data->hasUrls()) {
QString folder = (parent == invisibleRootItem()) ? QLatin1String("unsorted") : parent->text(0);
QUrl url = data->urls().at(0);
QString title = data->text().isEmpty() ? url.host() + url.path() : data->text();
emit linkWasDroped(url, title, data->imageData(), folder, &ok);
return ok;
}
if (!data->hasFormat(m_mimeType)) {
return false;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QByteArray ba = data->data(m_mimeType);
QDataStream stream(&ba, QIODevice::ReadOnly);
if (stream.atEnd()) {
return false;
}
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
setUpdatesEnabled(false);
while (!stream.atEnd()) {
QTreeWidgetItem* item = new QTreeWidgetItem;
item->read(stream);
bool parentIsRoot = item->data(0, ITEM_IS_TOPLEVEL).toBool();
QString oldParentTitle = item->data(0, ITEM_PARENT_TITLE).toString();
bool isFolder = item->text(1).isEmpty();
if (isFolder && (item->text(0) == _bookmarksMenu ||
item->text(0) == _bookmarksToolbar)) {
continue;
}
bool parentIsOldParent = parentIsRoot ? (parent == invisibleRootItem()) : (oldParentTitle == parent->text(0));
if (parentIsOldParent || (isFolder && parent != invisibleRootItem() &&
parent->text(0) != _bookmarksToolbar)) {
// just 'Bookmarks In ToolBar' folder can have subfolders
continue;
}
if (isFolder) {
emit folderParentChanged(item->text(0), parent->text(0) == _bookmarksToolbar, &ok);
}
else {
emit bookmarkParentChanged(item->data(0, Qt::UserRole + 10).toInt(),
parent->text(0), oldParentTitle, &ok);
}
if (!ok) {
continue;
}
}
db.commit();
clearSelection();
setUpdatesEnabled(true);
QApplication::restoreOverrideCursor();
return true;
}