Beispiel #1
0
void ColorDialog::initList()
{
  QTreeWidgetItem *rootItem;
  QList<QTreeWidgetItem *> elist;
  
  /* initialize color list */
  rootItem = ui_->listColors->invisibleRootItem();
  
  elist = rootItem->takeChildren();
  foreach (QTreeWidgetItem *i, elist)
      delete i;
  
  colorMap_.clear();
  
  for (int i = 0; i < ldraw::color::color_chart_count; ++i) {
    const ldraw::color_entity *ce = &ldraw::color::color_chart[i];
    
    newItem(rootItem, ce);
    colorMap_[ce->id] = i;
  }
  
  /* initialize favorites list */
  rootItem = ui_->listFavorites->invisibleRootItem();
  
  elist = rootItem->takeChildren();
  foreach (QTreeWidgetItem *i, elist)
      delete i;
  
  foreach (const ldraw::color &c, manager_->colorList())
      newItem(rootItem, c.get_entity());
  
  resetFavoritesMap();
}
void OutputWindow::modelNameChanged(const QString &title)
{
    QTreeWidget* tree;
    QTreeWidgetItem* item;

    modelFolder = title;

    tree = ui->treeWidget;

    item = tree->topLevelItem(0);
    item->takeChildren();
    item->setText(0, title);

    tree = ui->treeDataStruct;
    item = tree->topLevelItem(0);
    item->takeChildren();
    item->setText(0, title);

    tree = ui->treeModelDsc;
    item = tree->topLevelItem(0);
    item->takeChildren();
    item->setText(0, title);

    tree = ui->treeProject;
    item = tree->topLevelItem(0);
    item->takeChildren();
    item->setText(0, title);


}
Beispiel #3
0
void RegEdit::OnSocItemDelete()
{
    QTreeWidgetItem *current = m_soc_tree->currentItem();
    if(current == 0)
        return;
    QMessageBox msgbox(QMessageBox::Question, "Delete item ?",
        "Are you sure you want to delete this item ?",
        QMessageBox::Yes | QMessageBox::No, this);
    msgbox.setDefaultButton(QMessageBox::No);
    int ret = msgbox.exec();
    if(ret != QMessageBox::Yes)
        return;
    if(current->type() == SocTreeSocType)
    {
        SocTreeItem *item = dynamic_cast< SocTreeItem * >(current);
        item->GetRef().GetSoc().dev.clear();
        item->takeChildren();
        FillSocTreeItem(item);
        m_soc_tree->expandItem(item);
    }
    else if(current->type() == SocTreeDevType)
    {
        DevTreeItem *item = dynamic_cast< DevTreeItem * >(current);
        my_remove_at(item->GetRef().GetSoc().dev, item->GetRef().GetDevIndex());
        QTreeWidgetItem *parent = item->parent();
        parent->takeChildren();
        FillSocTreeItem(parent);
        m_soc_tree->expandItem(parent);
    }
    else if(current->type() == SocTreeRegType)
    {
        RegTreeItem *item = dynamic_cast< RegTreeItem * >(current);
        my_remove_at(item->GetRef().GetDev().reg, item->GetRef().GetRegIndex());
        QTreeWidgetItem *parent = item->parent();
        parent->takeChildren();
        FillDevTreeItem(parent);
        m_soc_tree->expandItem(parent);
    }
    else if(current->type() == SocTreeFieldType)
    {
        FieldTreeItem *item = dynamic_cast< FieldTreeItem * >(current);
        my_remove_at(item->GetRef().GetReg().field, item->GetRef().GetFieldIndex());
        QTreeWidgetItem *parent = item->parent();
        parent->takeChildren();
        FillRegTreeItem(parent);
        m_soc_tree->expandItem(parent);
    }
}
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_tree_item_take_children (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   JsModuleUiV8QtBasic *self = _to_self (Args);
   if (self) {

      QTreeWidgetItem *item = self->_to_qtreewidgetitem (Args.This ());
      if (item) {

         QList<QTreeWidgetItem *> items = item->takeChildren ();
         const int Length = items.count ();
         V8Array array = v8::Array::New (Length);
         for (int ix = 0; ix < Length; ++ix) {

            V8Value value = self->create_v8_qtreewidgetitem (items.at (ix));
            array->Set (v8::Integer::New (ix), value);
         }
         result = array;
      }
   }

   return scope.Close (result);
}
Beispiel #5
0
void VSCDeviceList::DiskTreeUpdated()
{
	/* Delete all the disk */
	QTreeWidgetItem *qtreewidgetitem = ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_DSIK);

	qDeleteAll(qtreewidgetitem->takeChildren());

	VDBDiskStatus pStatus;
	gFactory->GetDiskStatus(pStatus);


	VDBDiskStatus::iterator it = pStatus.begin();

	for(; it!=pStatus.end(); ++it)
	{
		astring strName = (*it).first;
		VdbDiskStatus diskStatus = (*it).second;
		s8 DiskTitle[1024];
		memset(DiskTitle, 0, sizeof(DiskTitle));
		sprintf(DiskTitle, "  %lld%%",   
				((diskStatus.totalSize  - diskStatus.freeSize)* 100)/diskStatus.totalSize);
		strName = diskStatus.path + DiskTitle;
		AddDisk(strName);
	}

	ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_DSIK)->setExpanded(true);

	
}
Beispiel #6
0
QList<QTreeWidgetItem *> QTreeWidgetItemProto::takeChildren()
{
  QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject());
  if (item)
    return item->takeChildren();
  return QList<QTreeWidgetItem*>();
}
Beispiel #7
0
void VSCDeviceList::VmsTreeUpdated()
{
	/* Delete all the site */
	{
		QTreeWidgetItem *qtreewidgetitem = ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_SITE);

		qDeleteAll(qtreewidgetitem->takeChildren());
	}

	VSCVmsData pData;
	gFactory->GetVms(pData);
	for (s32 i = 1; i < CONF_VMS_NUM_MAX; i ++)
	{
	    	if (pData.data.conf.vms[i].Used == 1)
	    	{
		        switch (pData.data.conf.vms[i].nType)
		        {
		            case VSC_VMS_SITE:
		            {
		                AddSite(pData.data.conf.vms[i]);
		                break;
		            }
		            default:
		            {

		                break;
		            }
		        }
	    	}else
	    	{
	    		continue;
	    	}
	}	
}
void OutputWindow::modelModelCodeFiles(const QStringList &sl)
{
    QTreeWidget * tree = ui->treeProject;
    QTreeWidgetItem* root = tree->topLevelItem(0);
    //Remove and return children list
    root->takeChildren();

    for(int i=0; i<sl.size(); ++i) {
        //        QString flabspath = sl.at(i);
        //        QString xlpath = flabspath.left(flabspath.lastIndexOf("/")).replace(modelFolder, tr(""));
        //        QString xlfile = flabspath.right(flabspath.length() -1 - flabspath.lastIndexOf("/") );
        QFileInfo info(sl.at(i));
        QString xlpath = info.absolutePath().replace(modelFolder, tr(""));
        QString xlfile = info.fileName();
        QString flabspath = info.absoluteFilePath();
        if(xlpath.compare("")!=0) {
            bool inserted = false;
            for(int j = 0; j<root->childCount(); ++j) {
                if(root->child(j)->text(0).compare(xlpath, Qt::CaseInsensitive) == 0) {
                    QTreeWidgetItem* item = new QTreeWidgetItem(
                                root->child(j),
                                QStringList(xlfile));
                    item->setIcon(0, GetIcon(xlfile) );
                    item->setData(0, Qt::UserRole, flabspath);
                    //                    item->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon) );
                    inserted= true;
                    break;//for-j
                }
            }
            if(!inserted) {
                QTreeWidgetItem* path = new QTreeWidgetItem(
                            root,
                            QStringList(xlpath) );
                path->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
                //path->setIcon(0, QIcon(px.copy(4*px_width,4*px_height,  px_width,px_height)));
                QTreeWidgetItem* item = new QTreeWidgetItem(
                            path,
                            QStringList(xlfile));
                //                item->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon) );
                item->setIcon(0, GetIcon(xlfile) );
                item->setData(0, Qt::UserRole, flabspath );
                //                root->addChild(path);
            }
        } else { //path is empty


            QTreeWidgetItem* item = new QTreeWidgetItem(
                        root,
                        QStringList(xlfile));
            item->setIcon(0, GetIcon(xlfile) );
            item->setData(0, Qt::UserRole, flabspath );
        }
    }
    tree->expandAll();
}
void TreeWidgetController::removeAllChildren(QTreeWidgetItem *parent)
{
    queue<QTreeWidgetItem *> q;
    for (q.push(parent); !q.empty(); q.pop()) {
        QTreeWidgetItem *item = q.front();
        foreach (QTreeWidgetItem *child, item->takeChildren())
            q.push(child);
        if (item != parent)
            delete item;
    }
}
Beispiel #10
0
 void DTTreeWidget::removeItem(const QString name)
 {
     QList<QTreeWidgetItem *> list = mCallTree.findItems(name, Qt::MatchContains | Qt::MatchRecursive);
     if (!list.empty())
     {         
         QTreeWidgetItem *item = list.at(0);
         QList<QTreeWidgetItem *> childs = item->takeChildren();
         foreach(QTreeWidgetItem *child, childs)
         {             
             mWidgetMap.remove(child->text(0));
             delete child;
         }
Beispiel #11
0
void OutputWindow::modelExcelListChanged(const QStringList &sl)
{
    QTreeWidget* tree = ui->treeWidget;
    QTreeWidgetItem* root = tree->topLevelItem(0);

    //Remove and return children list
    root->takeChildren();

    for(int i=0; i<sl.size(); ++i) {
        modelExcelAddFile(sl.at(i));
    }
    tree->expandAll();
}
Beispiel #12
0
void LibraryTreeWidget::sort()
{
	QTreeWidgetItem* root = invisibleRootItem();

	if (selectedItems().empty() == false)
		root = selectedItems()[0];

	QList<QTreeWidgetItem*> children = root->takeChildren();

	std::sort(children.begin(), children.end(), LessQTreeWidgetItem());

	root->addChildren(children);
}
Beispiel #13
0
/*
When this method is called, the socket has already
removed the network from its tree.  Trying to access
it will result in a segmentation fault.  This is why
we have to set the current item to NULL to prevent
the session tree from autoselecting the next item
which doesn't exist.
*/
void IrcMainWindow::removeNetwork(const QString& network)
{
    ircSessionTreeView->setCurrentItem(NULL);
    ircTextView->setDocument(NULL);
    ircTextView->clear();
    ircUserListView->clear();

    QTreeWidgetItem *item = ircSessionTreeView->findItems(network,
				Qt::MatchExactly).at(0);
    item->takeChildren();
    for(int i=0; i<ircSessionTreeView->topLevelItemCount(); i++)
    {
	if(ircSessionTreeView->topLevelItem(i)->text(0) == network)
	    ircSessionTreeView->takeTopLevelItem(i);
    }
}
Beispiel #14
0
//file->open
void NandWindow::on_actionOpen_Nand_triggered()
{
    QString path = QFileDialog::getOpenFileName( this, tr( "Select a Nand to open" ) );
    if( path.isEmpty() )
        return;

    blocks.clear();
    if( !nThread.SetPath( path ) )
    {
        qDebug() << " error in nandBin.SetPath";
        ui->statusBar->showMessage( "Error setting path to " + path );
        return;
    }
    ui->statusBar->showMessage( "Loading " + path );
    QIcon groupIcon;
    QIcon keyIcon;
    groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirClosedIcon ), QIcon::Normal, QIcon::Off );
    groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirOpenIcon ), QIcon::Normal, QIcon::On );
    keyIcon.addPixmap( style()->standardPixmap( QStyle::SP_FileIcon ) );

    if( !nThread.InitNand( groupIcon, keyIcon ) )
    {
        qDebug() << " error in nandBin.InitNand()";
        ui->statusBar->showMessage( "Error reading " + path );
        return;
    }

    ui->treeWidget->clear();
    GetBlocksfromNand();
    DrawBlockMap();

    //get an item holding a tree with all the items of the nand
    //QTreeWidgetItem* tree = nandBin.GetTree();
    QTreeWidgetItem* tree = nThread.GetTree();

    //take the actual contents of the nand from the made up root and add them to the gui widget
    ui->treeWidget->addTopLevelItems( tree->takeChildren() );

    //delete the made up root item
    delete tree;

    //expand the root item
    if( ui->treeWidget->topLevelItemCount() )
        ui->treeWidget->topLevelItem( 0 )->setExpanded( true );

    ui->statusBar->showMessage( "Loaded " + path, 5000 );
}
Beispiel #15
0
void OutputWindow::modelDataStructFiles(const QStringList &sl)
{
    QTreeWidget * tree = ui->treeDataStruct;
    QTreeWidgetItem* root = tree->topLevelItem(0);
    //Remove and return children list
    root->takeChildren();

    for(int i=0; i<sl.size(); ++i) {
        QFileInfo info(sl.at(i));
        QString xmlfile = info.fileName();
        QTreeWidgetItem* item = new QTreeWidgetItem(root, QStringList( xmlfile ));
        //        item->setIcon(0, style()->standardIcon(QStyle::SP_DriveNetIcon));
        item->setIcon(0, *xmlIcon);
        item->setData(0, Qt::UserRole, info.absoluteFilePath() );
    }
    tree->expandAll();

}
Beispiel #16
0
void VSCDeviceList::VGroupTreeUpdated()
{
	QTreeWidgetItem *qtreewidgetitem = ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_IPC);

	qDeleteAll(qtreewidgetitem->takeChildren());
	VSCVGroupData pData;
	gFactory->GetVGroup(pData);
	for (s32 i = 1; i < CONF_VGROUP_NUM_MAX; i ++)
	{
	    	if (pData.data.conf.group[i].Used == 1)
	    	{
	    		AddVGroup(pData.data.conf.group[i]);
	    	}else
	    	{
	    		continue;
	    	}
	}	
}
void MainWindow::buildBoundaryList() {
  QTreeWidgetItem *item = ui.BoundaryTree->topLevelItem(0);
  item->child(0)->setText(1,sim.getBoundaryText(0));
  item->child(1)->setText(1,sim.getBoundaryText(1));
  item->child(2)->setText(1,sim.getBoundaryText(2));
  item->child(3)->setText(1,sim.getBoundaryText(3));
  item->child(4)->setText(1,sim.getBoundaryText(4));
  item->child(5)->setText(1,sim.getBoundaryText(5));

  QTreeWidgetItem *new_item;
  long int extent_a[2];
  long int extent_b[2];
  QString type;
  QString extents;
  double value;
  double turbulence;
  int n;
  for(int i=0; i<6; i++) {
    item = ui.BoundaryTree->topLevelItem(1)->child(i);

    qDeleteAll(item->takeChildren());

    sim.resetSpecialBoundary(i);
    while(sim.getNextSpecialBoundary(type, extent_a, extent_b, value, turbulence)) {
      new_item = new QTreeWidgetItem(QTreeWidgetItem::Type);
      
      extents = QString::number(extent_a[0]) + 
                "," + QString::number(extent_a[1]) +
                " to " + QString::number(extent_b[0]) +
                "," + QString::number(extent_b[1]);
      n = item->childCount();

      item->insertChild(n, new_item);
      new_item->setText(0, QString::number(n+1));
      new_item->setText(1, type);
      new_item->setText(2, extents);
      new_item->setText(3, QString::number(value));
      new_item->setText(4, QString::number(turbulence));
    }
  }  


}
Beispiel #18
0
void EffectsListWidget::createTopLevelItems(QList <QTreeWidgetItem *>list, int effectType)
{
    // Favorites is a pseudo-folder used to store items, not visible to end user, so don't i18n its name
    QTreeWidgetItem *misc = findFolder(QStringLiteral("TemporaryFolder"));
    if (misc == NULL) {
        misc = new QTreeWidgetItem(this, QStringList(QStringLiteral("TemporaryFolder")));
        misc->setData(0, TypeRole, QString::number((int) EffectsList::EFFECT_FOLDER));
        misc->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    }
    else qDeleteAll(misc->takeChildren());
    setIndentation(0);
    misc->addChildren(list);
    for (int j = 0; j < misc->childCount(); ++j) {
        QTreeWidgetItem *child = misc->child(j);
        child->setHidden(false);
        child->setData(0, Qt::UserRole, effectType);
    }
    setRootIndex(indexFromItem(misc));
}
void ObserverStateMachine::showLayerLegend()
{
    int layer = treeLayers->topLevelItemCount();

    QTreeWidgetItem *parent = 0, *child = 0;
    Attributes *attrib = 0;
    QVector<ObsLegend> *leg = 0;
    for(int i = 0; i < layer; i++)
    {
        parent = treeLayers->topLevelItem(i);
        treeLayers->setItemExpanded(parent, true);
        attrib = mapAttributes->value(parent->text(0));

        leg = attrib->getLegend();

        if (parent->childCount() > 0)
            parent->takeChildren();

        for(int j = 0; j < leg->size(); j++)
        {
            if (states->contains(leg->at(j).getLabel()) )
            {
                child = new QTreeWidgetItem( parent);
                child->setSizeHint(0, ICON_SIZE);
                child->setText(0, leg->at(j).getLabel());
                QColor color = leg->at(j).getColor();

                if (! leg->at(j).getLabel().contains("mean"))
                    child->setData(0, Qt::DecorationRole,
                    legendWindow->color2Pixmap(color, ICON_SIZE));
                else
                    child->setData(0, Qt::DecorationRole, QString(""));

                // Define as cores dos estados
                Node *node = states->value(leg->at(j).getLabel());
                node->setColor(color);
                node->update(node->boundingRect());
            }
        }

    }
    treeLayers->resizeColumnToContents(0);
}
Beispiel #20
0
void VSCDeviceList::VIPCTreeUpdated()
{
    QTreeWidgetItem *qtreewidgetitem = ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_V_IPC);

    qDeleteAll(qtreewidgetitem->takeChildren());
    VIPCDeviceParamMap pMap;
    gFactory->GetVIPCDeviceParamMap(pMap);


    VIPCDeviceParamMap::iterator it = pMap.begin();

    for(; it!=pMap.end(); ++it)
    {
        u32 nId = (*it).first;
        VIPCDeviceParam pParam = (*it).second;
	 AddVIPC(pParam);
    }

    ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_IPC)->setExpanded(true);
}
Beispiel #21
0
void ObserverMap::showLayerLegend()
{
    int layer = treeLayers->topLevelItemCount();

    QTreeWidgetItem *parent = 0, *child = 0;
    Attributes *attrib = 0;
    QVector<ObsLegend> *leg = 0;
    for (int i = 0; i < layer; i++)
    {
        parent = treeLayers->topLevelItem(i);
        treeLayers->setItemExpanded(parent, true);
        attrib = mapAttributes->value(parent->text(0));

        leg = attrib->getLegend();

        if (parent->childCount() > 0)
            parent->takeChildren();

        for (int j = 0; j < leg->size(); j++)
        {
            child = new QTreeWidgetItem(parent);
            child->setSizeHint(0, ICON_SIZE);
            child->setText(0, leg->at(j).getLabel());
            QColor color = leg->at(j).getColor();

            if (attrib->getType() == TObsNeighborhood)
			{
				child->setData(0, Qt::DecorationRole, legendWindow->color2PixmapLine(color, attrib->getWidth()));
			}
			else
			{
				if (!leg->at(j).getLabel().contains("mean"))
					child->setData(0, Qt::DecorationRole,
					legendWindow->color2Pixmap(color, ICON_SIZE));
				else
					child->setData(0, Qt::DecorationRole, QString(""));
			}
        }
    }
    treeLayers->resizeColumnToContents(0);
}
Beispiel #22
0
void Iso::exploreIso()
{
	stopTreeWidget = true;
	mTreeWidget.lock();    //Wait till other thread is done exiting there request
	stopTreeWidget = false;

	QTreeWidgetItem *parent = new QTreeWidgetItem(NULL);
	parent->setText(0, getShortIso());
	uint64 totalSize = addTreeToWidget(parent, getRootNode());
	if(!stopTreeWidget)
	{
		parent->setText(2, getHumenSize(totalSize));
		emit doSetTree(parent); //Send the data to Main outside this thread
	}
	else
	{
		//Delete everything we created so far when we had to quit! as else we have major a major memory leak!
		 qDeleteAll(parent->takeChildren());
		 delete parent;
	}
	mTreeWidget.unlock();	
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
FilterLibraryTreeWidget* FilterLibraryTreeWidget::FromJsonObject(QJsonObject treeObject)
{
    QTreeWidgetItem* root = FilterLibraryTreeWidget::UnwrapTreeItem(treeObject);

    QList<QTreeWidgetItem*> list = root->takeChildren();

    FilterLibraryTreeWidget* tree = new FilterLibraryTreeWidget();
    tree->addTopLevelItems(list);

    QTreeWidgetItemIterator iter(tree);

    while (*iter)
    {
        QTreeWidgetItem* item = *iter;
        bool expanded = item->data(2, Qt::UserRole).toBool();
        item->setExpanded(expanded);

        ++iter;
    }

    tree->sortItems(0, Qt::AscendingOrder);
    return tree;
}
Beispiel #24
0
void VSCDeviceList::RemoveAllCamera()
{
    QTreeWidgetItem *qtreewidgetitem = ui.treeWidget->topLevelItem(VSC_DEVICE_INDEX_IPC);

    qDeleteAll(qtreewidgetitem->takeChildren());
}
void FileDescriptorWidget::updateBandFiles()
{
   QTreeWidgetItem* pFilenameItem = getDescriptorItem("Filename");
   if (pFilenameItem == NULL)
   {
      return;
   }

   // Store the current band filenames
   QStringList bandFilenames;
   for (int i = 0; i < pFilenameItem->childCount(); ++i)
   {
      QTreeWidgetItem* pBandFileItem = pFilenameItem->child(i);
      if (pBandFileItem != NULL)
      {
         bandFilenames.append(pBandFileItem->text(1));
      }
   }

   // Clear the existing band file items
   QList<QTreeWidgetItem*> bandFileItems = pFilenameItem->takeChildren();
   for (int i = 0; i < bandFileItems.count(); ++i)
   {
      QTreeWidgetItem* pBandFileItem = bandFileItems[i];
      if (pBandFileItem != NULL)
      {
         delete pBandFileItem;
      }
   }

   // Ensure that the interleave format is BSQ - multiple files
   bool bBsqMulti(false);

   QTreeWidgetItem* pInterleaveItem = getDescriptorItem("Interleave Format");
   if (pInterleaveItem != NULL)
   {
      if (pInterleaveItem->text(1).toStdString() == (StringUtilities::toDisplayString(BSQ) + BSQ_MULTI_SUFFIX))
      {
         bBsqMulti = true;
      }
   }

   if (bBsqMulti == false)
   {
      return;
   }

   // Get the number of bands
   int numBands = 0;

   QTreeWidgetItem* pBandsItem = getDescriptorItem("Bands");
   if (pBandsItem != NULL)
   {
      QString strNumBands = pBandsItem->text(1);
      numBands = strNumBands.toInt();
   }

   // Create the new band file items
   for (int i = 0; i < numBands; ++i)
   {
      QTreeWidgetItem* pBandItem = new QTreeWidgetItem(pFilenameItem);
      if (pBandItem != NULL)
      {
         // Set the initial filename to the previous value
         QString strBandFilename;
         if (i < bandFilenames.count())
         {
            strBandFilename = bandFilenames[i];
         }

         pBandItem->setText(0, QString::number(i + 1));
         pBandItem->setText(1, strBandFilename);

         if (mReadOnly == false)
         {
            mpTreeWidget->setCellWidgetType(pBandItem, 1, CustomTreeWidget::BROWSE_FILE_EDIT);
            mpTreeWidget->setFileBrowser(pBandItem, 1, mpFileBrowser);
         }
      }
   }
}
bool ProtobufTree::addTreeData(QTreeWidgetItem* parent,
                               const google::protobuf::Message& msg) {
    const Reflection* ref = msg.GetReflection();

    // Get fields in the message
    vector<const FieldDescriptor*> fields;
    ref->ListFields(msg, &fields);

    // Get map of field numbers to child items
    FieldMap fieldMap =
        parent->data(Column_Tag, FieldMapRole).value<FieldMap>();

    bool newFields = false;

    // Clear data for missing fields
    const Descriptor* desc = msg.GetDescriptor();
    for (FieldMap::const_iterator i = fieldMap.begin(); i != fieldMap.end();
         ++i) {
        const FieldDescriptor* field = desc->FindFieldByNumber(i.key());
        if (!field) {
            // Field has left the descriptor - should never happen
            printf("Lost field %s.%d\n", desc->name().c_str(), i.key());
            continue;
        }

        QTreeWidgetItem* item = i.value();

        bool hasData;
        if (field->is_repeated()) {
            hasData = ref->FieldSize(msg, field);

            if (!hasData && item->childCount()) {
                // Remove and delete children
                for (QTreeWidgetItem* child : item->takeChildren()) {
                    delete child;
                }
            }
        } else {
            hasData = ref->HasField(msg, field);
        }

        if (!hasData) {
            item->setText(Column_Value, QString());
            item->setData(Column_Value, Qt::CheckStateRole, QVariant());
        }
    }

    for (const FieldDescriptor* field : fields) {
        // Get the item for this field if the field has been seen before
        QTreeWidgetItem* item;
        FieldMap::iterator fieldIter = fieldMap.find(field->number());
        if (fieldIter != fieldMap.end()) {
            // Field is already in parent
            item = *fieldIter;
        } else {
            // New field
            item = new QTreeWidgetItem(parent);
            fieldMap.insert(field->number(), item);

            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            parent->setData(Column_Tag, FieldMapRole,
                            QVariant::fromValue<FieldMap>(fieldMap));
            item->setData(Column_Tag, Qt::DisplayRole, field->number());
            item->setData(Column_Tag, FieldDescriptorRole,
                          QVariant::fromValue(field));
            item->setText(Column_Field, QString::fromStdString(field->name()));

            if (field->type() == FieldDescriptor::TYPE_MESSAGE &&
                !field->is_repeated()) {
                // Singular messages are expanded by default
                expandItem(item);
            }

            newFields = true;
        }

        if (field->is_repeated()) {
            // Repeated field
            int n = ref->FieldSize(msg, field);

            // Show the number of elements as the value for the field itself
            item->setData(Column_Value, Qt::DisplayRole, n);

            // Make sure we have enough children
            int children = item->childCount();
            if (children < n) {
                // Add children
                for (int i = children; i < n; ++i) {
                    QTreeWidgetItem* child = new QTreeWidgetItem(item);
                    child->setText(Column_Field, QString("[%1]").arg(i));

                    child->setData(Column_Tag, FieldDescriptorRole, field);

                    // For repeated items, the tag column holds the index in the
                    // field
                    child->setData(Column_Tag, Qt::DisplayRole, i);

                    // A FieldMap is not used here because the items don't
                    // actually have tags. The item's position in its parent is
                    // its position in the repeated field.
                }

                newFields = true;
            } else if (children > n) {
                // Remove excess children
                // Internally, QTreeWidgetItem stores a QList of children.
                // Hopefully this is efficient.
                QList<QTreeWidgetItem*> kids = item->takeChildren();
                for (int i = 0; i < (children - n); ++i) {
                    delete kids.back();
                    kids.pop_back();
                }
                item->addChildren(kids);
            }

            // Set data for children
            for (int i = 0; i < n; ++i) {
                QTreeWidgetItem* child = item->child(i);

                switch (field->type()) {
                    case FieldDescriptor::TYPE_INT32:
                    case FieldDescriptor::TYPE_SINT32:
                    case FieldDescriptor::TYPE_FIXED32:
                    case FieldDescriptor::TYPE_SFIXED32:
                        child->setData(Column_Value, Qt::DisplayRole,
                                       ref->GetRepeatedInt32(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_INT64:
                    case FieldDescriptor::TYPE_SINT64:
                    case FieldDescriptor::TYPE_FIXED64:
                    case FieldDescriptor::TYPE_SFIXED64:
                        child->setData(
                            Column_Value, Qt::DisplayRole,
                            (qlonglong)ref->GetRepeatedInt64(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_UINT32:
                        child->setData(Column_Value, Qt::DisplayRole,
                                       ref->GetRepeatedUInt32(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_UINT64:
                        child->setData(
                            Column_Value, Qt::DisplayRole,
                            (qulonglong)ref->GetRepeatedUInt64(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_FLOAT:
                        child->setData(Column_Value, Qt::DisplayRole,
                                       ref->GetRepeatedFloat(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_DOUBLE:
                        child->setData(Column_Value, Qt::DisplayRole,
                                       ref->GetRepeatedDouble(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_BOOL:
                        child->setCheckState(Column_Value,
                                             ref->GetRepeatedBool(msg, field, i)
                                                 ? Qt::Checked
                                                 : Qt::Unchecked);
                        break;

                    case FieldDescriptor::TYPE_ENUM: {
                        const EnumValueDescriptor* ev =
                            ref->GetRepeatedEnum(msg, field, i);
                        child->setText(Column_Value,
                                       QString::fromStdString(ev->name()));
                        break;
                    }

                    case FieldDescriptor::TYPE_STRING:
                        child->setText(Column_Value, QString::fromStdString(
                                                         ref->GetRepeatedString(
                                                             msg, field, i)));
                        break;

                    case FieldDescriptor::TYPE_MESSAGE:
                        child->setData(Column_Tag, IsMessageRole, true);
                        newFields |= addTreeData(
                            child, ref->GetRepeatedMessage(msg, field, i));
                        break;

                    case FieldDescriptor::TYPE_BYTES:
                        addBytes(child, ref->GetRepeatedString(msg, field, i));
                        break;

                    default:
                        child->setText(Column_Value,
                                       QString("??? %1").arg(field->type()));
                        break;
                }
            }
        } else
            switch (field->type()) {
                case FieldDescriptor::TYPE_INT32:
                case FieldDescriptor::TYPE_SINT32:
                case FieldDescriptor::TYPE_FIXED32:
                case FieldDescriptor::TYPE_SFIXED32:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  ref->GetInt32(msg, field));
                    break;

                case FieldDescriptor::TYPE_INT64:
                case FieldDescriptor::TYPE_SINT64:
                case FieldDescriptor::TYPE_FIXED64:
                case FieldDescriptor::TYPE_SFIXED64:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  (qlonglong)ref->GetInt64(msg, field));
                    break;

                case FieldDescriptor::TYPE_UINT32:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  ref->GetUInt32(msg, field));
                    break;

                case FieldDescriptor::TYPE_UINT64:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  (qulonglong)ref->GetUInt64(msg, field));
                    break;

                case FieldDescriptor::TYPE_FLOAT:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  ref->GetFloat(msg, field));
                    break;

                case FieldDescriptor::TYPE_DOUBLE:
                    item->setData(Column_Value, Qt::DisplayRole,
                                  ref->GetDouble(msg, field));
                    break;

                case FieldDescriptor::TYPE_BOOL:
                    item->setCheckState(Column_Value, ref->GetBool(msg, field)
                                                          ? Qt::Checked
                                                          : Qt::Unchecked);
                    break;

                case FieldDescriptor::TYPE_ENUM: {
                    const EnumValueDescriptor* ev = ref->GetEnum(msg, field);
                    item->setText(Column_Value,
                                  QString::fromStdString(ev->name()));
                    break;
                }

                case FieldDescriptor::TYPE_STRING:
                    item->setText(
                        Column_Value,
                        QString::fromStdString(ref->GetString(msg, field)));
                    break;

                case FieldDescriptor::TYPE_MESSAGE:
                    item->setData(Column_Tag, IsMessageRole, true);
                    newFields |= addTreeData(item, ref->GetMessage(msg, field));
                    break;

                case FieldDescriptor::TYPE_BYTES:
                    addBytes(item, ref->GetString(msg, field));
                    break;

                default:
                    item->setText(Column_Value,
                                  QString("??? %1").arg(field->type()));
                    break;
            }
    }

    return newFields;
}
Beispiel #27
0
void VDirectoryTree::reloadFromDisk()
{
    if (!m_notebook) {
        return;
    }

    QString msg;
    QString info;
    VDirectory *curDir = NULL;
    QTreeWidgetItem *curItem = currentItem();
    if (curItem) {
        // Reload current directory.
        curDir = getVDirectory(curItem);
        info = tr("Are you sure to reload folder <span style=\"%1\">%2</span>?")
                 .arg(g_config->c_dataTextStyle).arg(curDir->getName());
        msg = tr("Folder %1 reloaded from disk").arg(curDir->getName());
    } else {
        // Reload notebook.
        info = tr("Are you sure to reload notebook <span style=\"%1\">%2</span>?")
                 .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
        msg = tr("Notebook %1 reloaded from disk").arg(m_notebook->getName());
    }

    if (g_config->getConfirmReloadFolder()) {
        int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
                                      info,
                                      tr("VNote will close all the related notes before reload."),
                                      QMessageBox::Ok | QMessageBox::YesToAll | QMessageBox::Cancel,
                                      QMessageBox::Ok,
                                      this);
        switch (ret) {
        case QMessageBox::YesToAll:
            g_config->setConfirmReloadFolder(false);
            // Fall through.

        case QMessageBox::Ok:
            break;

        case QMessageBox::Cancel:
            return;

        default:
            return;
        }
    }

    m_notebookCurrentDirMap.remove(m_notebook);

    if (curItem) {
        if (!m_editArea->closeFile(curDir, false)) {
            return;
        }

        setCurrentItem(NULL);

        curItem->setExpanded(false);
        curDir->setExpanded(false);

        curDir->close();

        // Remove all its children.
        QList<QTreeWidgetItem *> children = curItem->takeChildren();
        for (int i = 0; i < children.size(); ++i) {
            delete children[i];
        }

        buildSubTree(curItem, 1);

        setCurrentItem(curItem);
    } else {
        if (!m_editArea->closeFile(m_notebook, false)) {
            return;
        }

        m_notebook->close();

        if (!m_notebook->open()) {
            VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
                                tr("Fail to open notebook <span style=\"%1\">%2</span>.")
                                  .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()),
                                tr("Please check if path <span style=\"%1\">%2</span> exists.")
                                  .arg(g_config->c_dataTextStyle).arg(m_notebook->getPath()),
                                QMessageBox::Ok, QMessageBox::Ok, this);
            clear();
            return;
        }

        updateDirectoryTree();
    }

    if (!msg.isEmpty()) {
        g_mainWin->showStatusMessage(msg);
    }
}