本文整理汇总了C++中Branch::tree方法的典型用法代码示例。如果您正苦于以下问题:C++ Branch::tree方法的具体用法?C++ Branch::tree怎么用?C++ Branch::tree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch::tree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dropEvent
void QCustomTreeWidget::dropEvent(QDropEvent *e)
{
QPoint pos = e->pos();
QModelIndex index;
// we test if we point inside an item
if (e->source() == this && viewport()->rect().contains(pos),true)
{
index = indexAt(pos);
if (!index.isValid())
{
return;
}
QTreeWidgetItem *item = itemAt(pos);
// now we have an item, we check whether we are above, below or on it
QRect rect = visualRect(index);
const int margin = 2;
if (pos.y() - rect.top() < margin)
{
// we are above it
pTree->move(pTree->indicesOf(dynamic_cast<QCustomTreeWidgetItem*>(pDragSource)->branch()),pTree->indicesOf(dynamic_cast<QCustomTreeWidgetItem*>(item)->branch()));
}
else if (rect.bottom() - pos.y() < margin)
{
// we are below it
pTree->move(pTree->indicesOf(dynamic_cast<QCustomTreeWidgetItem*>(pDragSource)->branch()),pTree->indicesOfNext(dynamic_cast<QCustomTreeWidgetItem*>(item)->branch()));
}
else if (rect.contains(pos, true))
{
// we are on it : new child
stringstream buf(stringstream::in|stringstream::out);
Branch *branch = dynamic_cast<QCustomTreeWidgetItem*>(item)->branch();
buf << pTree->indicesOf(branch);
// we want to add it as the last child
buf << "_" << branch->tree().numberOfChildren();
pTree->move(pTree->indicesOf(dynamic_cast<QCustomTreeWidgetItem*>(pDragSource)->branch()), buf.str());
}
}
QTreeWidget::dropEvent(e);
resizeColumnToContents(0);
}
示例2: addItem
void QCustomTreeWidget::addItem(QCustomTreeWidgetItem *item)
{
pItemDial->exec();
if (pItemDial->result()==QDialog::Accepted)
{
// creation of the new item
Item *newItem = NULL;
try
{
switch (pItemDial->type())
{
case Item::tSound: newItem = new SoundItem(pItemDial->text().toStdString(),pItemDial->state(),pItemDial->fileName().toStdString(),bSizeLimited);
break;
case Item::tImage: newItem = new ImageItem(pItemDial->text().toStdString(),pItemDial->state(),pItemDial->fileName().toStdString());
break;
default: newItem = new Item(pItemDial->text().toStdString(),pItemDial->state());
break;
}
}
catch (exception &e)
{
QMessageBox::critical(this,QApplication::translate("mainWindow","Error",0),e.what());
if (newItem != NULL)
{
delete newItem;
}
return;
}
if (item == NULL)
{
// There is no item in the tree
Branch *newBranch = pTree->add(newItem);
new QCustomTreeWidgetItem(this,newBranch);
}
else
{
switch (pItemDial->selectionResult())
{
case ItemDialog::rBrother: {
// we want to insert it after the given item
Branch *parent = item->branch()->parent()->parent();
if (parent==NULL)
{
Branch *newBranch = pTree->insert(pTree->indexOf(item->branch())+1,newItem);
new QCustomTreeWidgetItem(this,newBranch,item);
}
else
{
Branch *newBranch = parent->tree().insert(parent->tree().indexOf(item->branch())+1,newItem);
new QCustomTreeWidgetItem(dynamic_cast<QCustomTreeWidgetItem*>(item->parent()),newBranch,item);
}
break;
}
case ItemDialog::rChild: {
// we want to insert it inside the given item
Branch *newBranch = item->branch()->tree().add(newItem);
QCustomTreeWidgetItem *newQItem = new QCustomTreeWidgetItem(item,newBranch);
expandItem(newQItem->parent());
break;
}
}
}
resizeColumnToContents(0);
}
}