void BsonTreeWidget::onCopyDocument() { BsonTreeItem *documentItem = selectedBsonTreeItem(); if (!documentItem) return; MongoElementPtr element = documentItem->element(); if (!element->isSimpleType() && !element->isUuidType()) return; QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(element->stringValue()); }
BsonTreeItem::BsonTreeItem(MongoDocumentPtr rootDocument, MongoElementPtr element, int position) : baseClass(), _element(element), _rootDocument(rootDocument), _position(position) { setText(0, buildFieldName()); setForeground(2, GuiRegistry::instance().typeBrush()); //setFlags(flags() | Qt::ItemIsEditable); switch (element->bsonElement().type()) { /** double precision floating point value */ case NumberDouble: { setIcon(0, GuiRegistry::instance().bsonIntegerIcon()); setText(1, element->stringValue()); setText(2, "Double"); } break; /** character string, stored in utf8 */ case String: { QString text = element->stringValue().left(500); setToolTip(1, text); setIcon(0, GuiRegistry::instance().bsonStringIcon()); setText(1, buildSynopsis(element->stringValue())); setText(2, "String"); } break; /** an embedded object */ case Object: { setText(0, buildObjectFieldName()); MongoDocumentPtr mongoDocument = _element->asDocument(); setupDocument(mongoDocument); } break; /** an embedded array */ case Array: { int itemsCount = _element->bsonElement().Array().size(); setText(0, buildArrayFieldName(itemsCount)); setIcon(0, GuiRegistry::instance().bsonArrayIcon()); setText(2, "Array"); setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); } break; /** binary data */ case BinData: { setIcon(0, GuiRegistry::instance().bsonBinaryIcon()); setText(1, element->stringValue()); if (element->bsonElement().binDataType() == mongo::newUUID) { setText(2, "UUID"); } else if (element->bsonElement().binDataType() == mongo::bdtUUID) { UUIDEncoding uuidEncoding = AppRegistry::instance().settingsManager()->uuidEncoding(); QString type; switch(uuidEncoding) { case DefaultEncoding: type = "Legacy UUID"; break; case JavaLegacy: type = "Java UUID (Legacy)"; break; case CSharpLegacy: type = ".NET UUID (Legacy)"; break; case PythonLegacy: type = "Python UUID (Legacy)"; break; default: type = "Legacy UUID"; break; } setText(2, type); } else { setText(2, "Binary"); } } break; /** Undefined type */ case Undefined: { setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, "<Undefined>"); setText(2, "Undefined"); } break; /** ObjectId */ case jstOID: { setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, element->stringValue()); setText(2, "ObjectId"); } break; /** boolean type */ case Bool: { setIcon(0, GuiRegistry::instance().bsonBooleanIcon()); setText(1, element->stringValue()); setText(2, "Boolean"); } break; /** date type */ case Date: { setIcon(0, GuiRegistry::instance().bsonDateTimeIcon()); setText(1, element->stringValue()); setText(2, "Date"); } break; /** null type */ case jstNULL: { setIcon(0, GuiRegistry::instance().bsonNullIcon()); setText(1, "null"); setText(2, "Null"); } break; /** regular expression, a pattern with options */ case RegEx: { setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, element->stringValue()); setText(2, "Regular Expression"); } break; /** deprecated / will be redesigned */ case DBRef: { setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, element->stringValue()); setText(2, "DBRef"); } break; /** deprecated / use CodeWScope */ case Code: { QString code = element->stringValue(); setToolTip(1, code); setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, buildSynopsis(code)); setText(2, "Code"); } break; /** a programming language (e.g., Python) symbol */ case Symbol: { setText(2, "Symbol"); } break; /** javascript code that can execute on the database server, with SavedContext */ case CodeWScope: { QString code = element->stringValue(); setToolTip(1, code); setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, buildSynopsis(code)); setText(2, "CodeWScope"); } break; /** 32 bit signed integer */ case NumberInt: { setIcon(0, GuiRegistry::instance().bsonIntegerIcon()); setText(1, element->stringValue()); setText(2, "Int32"); } break; /** Updated to a Date with value next OpTime on insert */ case Timestamp: { setIcon(0, GuiRegistry::instance().bsonDateTimeIcon()); setText(1, element->stringValue()); setText(2, "Timestamp"); } break; /** 64 bit integer */ case NumberLong: { setIcon(0, GuiRegistry::instance().bsonIntegerIcon()); setText(1, element->stringValue()); setText(2, "Int64"); } break; default: { setIcon(0, GuiRegistry::instance().circleIcon()); setText(1, element->stringValue()); setText(2, "Type is not supported"); } break; } }