Пример #1
0
/**
 * Moves all the group's entries (recursively) to Backup group; subgroups are deleted.
 * Returns true if successful.
 */
bool PwGroupV3::moveToBackup() {
    PwGroup* parentGroup = this->getParentGroup();
    if (!parentGroup) {
        LOG("PwGroupV3::moveToBackup fail - no parent group");
        return false;
    }

    PwGroup* backupGroup = getDatabase()->getBackupGroup(true);
    // For v3, backupGroup is guaranteed to be not NULL

    parentGroup->removeSubGroup(this);
    // detach this branch from the parent group; memory will be released later.

    // flag the group and all its children deleted
    setDeleted(true);
    QList<PwGroup*> childGroups;
    QList<PwEntry*> childEntries;
    getAllChildren(childGroups, childEntries);
    // V3 does not backup subgroups, so move only entries
    for (int i = 0; i < childEntries.size(); i++) {
        if (!childEntries.at(i)->moveToBackup()) {
            LOG("PwGroupV3::moveToBackup fail on child entry");
            return false;
        }
    }
    childGroups.clear();
    childEntries.clear();
    LOG("PwGroupV3::moveToBackup OK");
    return true;
}
Пример #2
0
void MythGenericTree::sortByString()
{
    m_ordered_subnodes->Sort(SortableMythGenericTreeList::SORT_STRING);

    QList<MythGenericTree*> *children = getAllChildren();
    if (children && children->count() > 0)
    {
        SortableMythGenericTreeList::Iterator it;
        MythGenericTree *child = NULL;

        for (it = children->begin(); it != children->end(); ++it)
        {
            child = *it;
            if (!child)
                continue;
            child->sortByString();
        }
    }
}
Пример #3
0
MythGenericTree* MythGenericTree::getChildById(int an_int) const
{
    QList<MythGenericTree*> *children = getAllChildren();
    if (children && children->count() > 0)
    {
        SortableMythGenericTreeList::Iterator it;
        MythGenericTree *child = NULL;

        for (it = children->begin(); it != children->end(); ++it)
        {
            child = *it;
            if (!child)
                continue;
            if (child->getInt() == an_int)
                return child;
        }
    }

    return NULL;
}
Пример #4
0
MythGenericTree* MythGenericTree::getChildByName(const QString &a_name) const
{
    QList<MythGenericTree*> *children = getAllChildren();
    if (children && children->count() > 0)
    {
        SortableMythGenericTreeList::Iterator it;
        MythGenericTree *child = nullptr;

        for (it = children->begin(); it != children->end(); ++it)
        {
            child = *it;
            if (!child)
                continue;
            if (child->GetText() == a_name)
                return child;
        }
    }

    return nullptr;
}
Пример #5
0
void TTreeWidget::mouseReleaseEvent( QMouseEvent *event )
{
    QModelIndex indexClicked = indexAt(event->pos());
    if( mIsVarTree && indexClicked.isValid() && mClickedItem == indexClicked )
    {
        QRect vrect = visualRect(indexClicked);
        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,
                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
        if(rect.contains(event->pos()))
        {
            QTreeWidgetItem * clicked = itemFromIndex( indexClicked );
            if ( ! ( clicked->flags()&Qt::ItemIsUserCheckable ) )
                return;
            if ( clicked->checkState( 0 ) == Qt::Unchecked )
            {
                clicked->setCheckState( 0, Qt::Checked );
                //get all children and see what ones we can save
                QList< QTreeWidgetItem * > list;
                getAllChildren( clicked, list );
                QListIterator< QTreeWidgetItem * > it(list);
                LuaInterface * lI = mpHost->getLuaInterface();
                VarUnit * vu = lI->getVarUnit();
                while( it.hasNext() )
                {
                    QTreeWidgetItem * item = it.next();
                    if ( ! vu->shouldSave( item ) )
                        item->setCheckState( 0, Qt::Unchecked );
                }
            }
            else
            {
                clicked->setCheckState( 0, Qt::Unchecked );
            }
            return;
        }
    }
    QTreeWidget::mouseReleaseEvent(event);
}
Пример #6
0
ccHObject::Container vombat::getAllObjectsInTree()
{
    //    ccHObject::Container cont;

    ccHObject* dbroot = this->getMainAppInterface()->dbRootObject();
    ccHObject::Container tovisit;
    tovisit.push_back(dbroot);

    ccHObject::Container out;

    while (!tovisit.empty()) {
        ccHObject* last = tovisit.back();
        tovisit.pop_back();

        out.push_back(last);

        ccHObject::Container sons = getAllChildren(last);

        for (ccHObject* obj : sons) {
            tovisit.push_back(obj);
        }
    }
    return out;
}
Пример #7
0
  void getContractNames(const XmimClientHandle& handle, T cont, const char* relname, const XmimUnits units) {
    std::vector<std::string> tickers;
    std::vector<bool> has_rows;
    std::vector<XmimRelType> relTypes;

    // read in all children
    getAllChildren(handle, std::back_inserter(tickers), relname);
    // find rel types
    getRelationTypes(handle, std::back_inserter(relTypes), tickers.begin(), tickers.end());
    // see if there is actual data in the relation
    hasRows(handle, std::back_inserter(has_rows), tickers.begin(), tickers.end(), units);

    // drop out continuous contracts and such
    // only accept actual futures contracts
    std::vector<XmimRelType>::iterator relTypes_iter = relTypes.begin();
    std::vector<bool>::iterator has_rows_iter = has_rows.begin();

    for(std::vector<std::string>::iterator it = tickers.begin(); it != tickers.end(); it++) {
      if(*relTypes_iter == XMIM_REL_FUTURES_CONTRACT && *has_rows_iter) {
	*cont = *it;
      }
      ++cont; ++relTypes_iter; ++has_rows_iter;
    }
  }
Пример #8
0
void TTreeWidget::getAllChildren( QTreeWidgetItem *pItem, QList< QTreeWidgetItem * > & list)
{
    list.append( pItem );
    for(int i=0;i<pItem->childCount();++i)
        getAllChildren( pItem->child(i), list );
}
Пример #9
0
bool CollectionHandler::read(Variant& v, const NodePtr& node, const char* typeName)
{
	// Check that we've been given a valid Variant
	if (v.isVoid() || v.type() == nullptr)
	{
		return false;
	}

	// Container, key, and value types
	TypeId containerType;
	TypeId keyVariantType;
	TypeId valueVariantType;
	std::string keyInternalType;
	std::string valueInternalType;

	// Container
	const char* containerName = this->getReservedNames().collectionContainerType;
	std::string containerTypeName = node->getChildNode(containerName, strlen(containerName))->getType();
	containerType = TypeId(containerTypeName.c_str());
	// Key variant type
	const char* keyVName = this->getReservedNames().collectionKeyVariantType;
	std::string keyVTypeName = node->getChildNode(keyVName, strlen(keyVName))->getType();
	keyVariantType = TypeId(keyVTypeName.c_str());
	// Value variant type
	const char* valueVName = this->getReservedNames().collectionValueVariantType;
	std::string valueVTypeName = node->getChildNode(valueVName, strlen(valueVName))->getType();
	valueVariantType = TypeId(valueVTypeName.c_str());
	// Key internal type
	const char* keyIName = this->getReservedNames().collectionKeyInternalType;
	keyInternalType = node->getChildNode(keyIName, strlen(keyIName))->getType();
	// Value internal type
	const char* valueIName = this->getReservedNames().collectionValueInternalType;
	valueInternalType = node->getChildNode(valueIName, strlen(valueIName))->getType();

	// Cast to a collection
	Collection c;
	if (!v.tryCast<Collection>(c))
	{
		return false;
	}

	// Check that the types match
	if (strcmp(c.impl()->containerType().getName(), containerType.getName()) != 0)
	{
		return false;
	}

	// Get handlers
	std::shared_ptr<SerializationHandler> keyHandler = nullptr;
	std::shared_ptr<SerializationHandler> valueHandler = nullptr;
	if (MetaType::find(keyVariantType.getName()) != MetaType::get<Variant>())
	{
		const char* keyHandlerName = this->getReservedNames().collectionKeyHandler;
		auto keyHandlerNode = node->getChildNode(keyHandlerName, strlen(keyHandlerName));
		std::string keyHandlerString = keyHandlerNode->getValueString();
		keyHandler = handlerManager_.findHandlerRead(node, keyHandlerString.c_str(), keyInternalType.c_str());
	}
	if (MetaType::find(valueVariantType.getName()) != MetaType::get<Variant>())
	{
		const char* valueHandlerName = this->getReservedNames().collectionValueHandler;
		auto valueHandlerNode = node->getChildNode(valueHandlerName, strlen(valueHandlerName));
		std::string valueHandlerString = valueHandlerNode->getValueString();
		valueHandler = handlerManager_.findHandlerRead(node, valueHandlerString.c_str(), valueInternalType.c_str());
	}

	// Get the base node of the collection
	auto baseNode = node->getChildNode(collectionBaseNodeName_, strlen(collectionBaseNodeName_));

	auto nodeChildren = baseNode->getAllChildren();

	auto collectionIter = c.begin();

	// Iterate through all the children until we reach the nodes for storing type data
	for (auto nodeIter = nodeChildren.begin(); nodeIter != nodeChildren.end(); ++nodeIter)
	{
		std::unique_ptr<SerializationNode>& currentNode = *nodeIter;
		Variant key = Variant(keyVariantType);

		// Assign key/value
		if (currentNode->getName() != keyName_)
		{
			return false;
		}

		// Read the key node
		if (keyHandler.get() == nullptr)
		{
			// Read as a Variant
			if (!currentNode->getValueVariant(key, keyVariantType.getName()))
			{
				return false;
			}
		}
		else
		{
			// Read with a handler, using the type supplied
			if (!keyHandler->read(key, currentNode, keyVariantType.getName()))
			{
				return false;
			}
		}

		// Insert/get the key, which creates the value for us.
		Collection::Iterator insertIter;
		if (c.canResize())
		{
			insertIter = c.insert(key);
		}
		else
		{
			if (key != collectionIter.key())
			{
				return false;
			}
			insertIter = collectionIter;
			++collectionIter;
		}
		if (insertIter == c.end())
		{
			return false;
		}

		Variant value = insertIter.value();

		auto childNode = currentNode->getChildNode(valueName_, strlen(valueName_));
		if (childNode == nullptr)
		{
			return false;
		}

		// Read the value node
		if (valueHandler.get() == nullptr)
		{
			// Read as a Variant
			if (!childNode->getValueVariant(value, valueVariantType.getName()))
			{
				return false;
			}
		}
		else
		{
			// Read with a handler, using the type supplied
			if (!valueHandler->read(value, childNode, valueVariantType.getName()))
			{
				return false;
			}
		}

		// If this collection doesn't support setting values, then it's invalid.
		if (!insertIter.setValue(value))
		{
			return false;
		}
	}

	return true;
}