void QTreeWidgetItemProto::insertChildren(int index, const QList<QTreeWidgetItem *> &children) { QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject()); if (item) item->insertChildren(index, children); }
void CBookmarkIndex::dropEvent( QDropEvent* event ) { qDebug() << "CBookmarkIndex::dropEvent"; //setState(QAbstractItemView::NoState); // Try to prevent annoying timed autocollapsing. Remember to disconnect before return. QObject::connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); QTreeWidgetItem* item = itemAt(event->pos()); QTreeWidgetItem* parentItem = 0; int indexUnderParent = 0; // Find the place where the drag is dropped if (item) { qDebug() << "there was item"; QRect rect = visualItemRect(item); bool isFolder = dynamic_cast<BtBookmarkFolder*>(item); bool isBookmark = dynamic_cast<BtBookmarkItem*>(item); if (isFolder) { // item is a folder qDebug() << "item was folder"; if (event->pos().y() > rect.bottom() - (2* rect.height() / 3) ) { parentItem = item; } else { parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } qDebug() << "item:" << item << "parent:" << parentItem; indexUnderParent = parentItem->indexOfChild(item); // before the current folder } } else { if (isBookmark) { // item is a bookmark qDebug() << "item was bookmark"; parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark if (event->pos().y() > rect.bottom() - rect.height() / 2) { indexUnderParent++; // after the current bookmark } } else { // item is the extra item parentItem = item->parent(); if (!parentItem) { parentItem = invisibleRootItem(); } indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark } } } else { // no item under event point: drop to the end qDebug() << "there was no item"; parentItem = invisibleRootItem(); indexUnderParent = parentItem->childCount() - 1; } if ( event->source() == this ) { qDebug() << "dropping internal drag"; event->accept(); bool bookmarksOnly = true; bool targetIncluded = false; bool moreThanOneFolder = false; QList<QTreeWidgetItem*> newItems = addItemsToDropTree(parentItem, bookmarksOnly, targetIncluded, moreThanOneFolder); if (moreThanOneFolder) { QToolTip::showText(QCursor::pos(), tr("Can drop only bookmarks or one folder")); QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; } if (targetIncluded) { QToolTip::showText(QCursor::pos(), tr("Can't drop folder into the folder itself or into its subfolder")); QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; } // Ask whether to copy or move with a popup menu QMenu* dropPopupMenu = new QMenu(this); QAction* copy = dropPopupMenu->addAction(tr("Copy")); QAction* move = dropPopupMenu->addAction(tr("Move")); QAction* dropAction = dropPopupMenu->exec(QCursor::pos()); if (dropAction == copy) { qDebug() << "copy"; parentItem->insertChildren(indexUnderParent, newItems); // Need this here because the "move" case goes through // "deleteEntries" which has a save call. needToSaveBookmarks(); } else { if (dropAction == move) { qDebug() << "move"; parentItem->insertChildren(indexUnderParent, newItems); deleteEntries(false); } else { QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*))); return; // user canceled } } }
bool MyMainWindow::GetBaseFileMapinfo(QString filename) { //to get image infomation. flag 1 is base image and 2 warp image treeBaseItem->setText(0,filename); int n=pBaseFileDataset->GetRasterCount(); //to construct n treewidgetiterm QList<QTreeWidgetItem *> items; QTreeWidgetItem *p; for (int i = 0; i < n; ++i) { p=new QTreeWidgetItem(); //get raster band information£» GDALRasterBand *poBand=pBaseFileDataset->GetRasterBand(i+1); char *poBandDescription=new char[100]; const char* ptemp=poBand->GetDescription(); strcpy(poBandDescription,ptemp); QString poDes=QString(QLatin1String(poBandDescription)); p->setText(0,poDes); if (sizeof(*ptemp)<2) p->setText(0,QString("layer %0").arg(i+1)); items.append(p); treeBaseLayerItem.append(p); delete[] poBandDescription; } p=new QTreeWidgetItem(); QString str="Map Info"; p->setText(0,str); items.append(p); treeBaseItem->insertChildren(0,items); items.clear(); //to get projection const char* strchr=pBaseFileDataset->GetProjectionRef(); char* strchr1=new char[100]; memcpy(strchr1,strchr,100); QTreeWidgetItem *q=new QTreeWidgetItem(); QString poDes2=QString(QLatin1String(strchr1)); q->setText(0,poDes2); items.append(q); treeBaseMapinfoItem=q; delete[] strchr1; double adfGeoTransform[6]; pBaseFileDataset->GetGeoTransform( adfGeoTransform ); strchr1=new char[100]; sprintf(strchr1,"Pixel: %f",adfGeoTransform[1]); QString poDes3=QString(QLatin1String(strchr1)); q=new QTreeWidgetItem(); q->setText(0,poDes3); items.append(q); delete[] strchr1; strchr1=new char[100]; sprintf(strchr1,"UL X: %.2f",adfGeoTransform[0]); QString poDes4=QString(QLatin1String(strchr1)); q=new QTreeWidgetItem(); q->setText(0,poDes4); items.append(q); delete[] strchr1; strchr1=new char[100]; sprintf(strchr1,"UL Y: %.2f",adfGeoTransform[3]); QString poDes5=QString(QLatin1String(strchr1)); q=new QTreeWidgetItem(); q->setText(0,poDes5); items.append(q); delete[] strchr1; p->insertChildren(0,items); return true; }