/* ------------ Class ExplorerCollectionTreeItem ------------ */ ExplorerCollectionTreeItem::ExplorerCollectionTreeItem(QTreeWidgetItem *parent, ExplorerDatabaseTreeItem *databaseItem, MongoCollection *collection) : BaseClass(parent), _collection(collection), _databaseItem(databaseItem) { QAction *addDocument = new QAction("Insert Document...", this); VERIFY(connect(addDocument, SIGNAL(triggered()), SLOT(ui_addDocument()))); QAction *updateDocument = new QAction("Update Documents...", this); VERIFY(connect(updateDocument, SIGNAL(triggered()), SLOT(ui_updateDocument()))); QAction *removeDocument = new QAction("Remove Documents...", this); VERIFY(connect(removeDocument, SIGNAL(triggered()), SLOT(ui_removeDocument()))); QAction *removeAllDocuments = new QAction("Remove All Documents...", this); VERIFY(connect(removeAllDocuments, SIGNAL(triggered()), SLOT(ui_removeAllDocuments()))); QAction *collectionStats = new QAction("Statistics", this); VERIFY(connect(collectionStats, SIGNAL(triggered()), SLOT(ui_collectionStatistics()))); QAction *storageSize = new QAction("Storage Size", this); VERIFY(connect(storageSize, SIGNAL(triggered()), SLOT(ui_storageSize()))); QAction *totalIndexSize = new QAction("Total Index Size", this); VERIFY(connect(totalIndexSize, SIGNAL(triggered()), SLOT(ui_totalIndexSize()))); QAction *totalSize = new QAction("Total Size", this); VERIFY(connect(totalSize, SIGNAL(triggered()), SLOT(ui_totalSize()))); QAction *shardVersion = new QAction("Shard Version", this); VERIFY(connect(shardVersion, SIGNAL(triggered()), SLOT(ui_shardVersion()))); QAction *shardDistribution = new QAction("Shard Distribution", this); VERIFY(connect(shardDistribution, SIGNAL(triggered()), SLOT(ui_shardDistribution()))); QAction *dropCollection = new QAction("Drop Collection...", this); VERIFY(connect(dropCollection, SIGNAL(triggered()), SLOT(ui_dropCollection()))); QAction *renameCollection = new QAction("Rename Collection...", this); VERIFY(connect(renameCollection, SIGNAL(triggered()), SLOT(ui_renameCollection()))); QAction *duplicateCollection = new QAction("Duplicate Collection...", this); VERIFY(connect(duplicateCollection, SIGNAL(triggered()), SLOT(ui_duplicateCollection()))); // Disabling for 0.8.5 release as this is currently a broken misfeature (see discussion on issue #398) // QAction *copyCollectionToDiffrentServer = new QAction("Copy Collection to Database...", this); // VERIFY(connect(copyCollectionToDiffrentServer, SIGNAL(triggered()), SLOT(ui_copyToCollectionToDiffrentServer()))); QAction *viewCollection = new QAction("View Documents", this); VERIFY(connect(viewCollection, SIGNAL(triggered()), SLOT(ui_viewCollection()))); BaseClass::_contextMenu->addAction(viewCollection); BaseClass::_contextMenu->addSeparator(); BaseClass::_contextMenu->addAction(addDocument); BaseClass::_contextMenu->addAction(updateDocument); BaseClass::_contextMenu->addAction(removeDocument); BaseClass::_contextMenu->addAction(removeAllDocuments); BaseClass::_contextMenu->addSeparator(); BaseClass::_contextMenu->addAction(renameCollection); BaseClass::_contextMenu->addAction(duplicateCollection); // Disabling for 0.8.5 release as this is currently a broken misfeature (see discussion on issue #398) // BaseClass::_contextMenu->addAction(copyCollectionToDiffrentServer); BaseClass::_contextMenu->addAction(dropCollection); BaseClass::_contextMenu->addSeparator(); BaseClass::_contextMenu->addAction(collectionStats); BaseClass::_contextMenu->addSeparator(); BaseClass::_contextMenu->addAction(shardVersion); BaseClass::_contextMenu->addAction(shardDistribution); AppRegistry::instance().bus()->subscribe(_databaseItem, LoadCollectionIndexesResponse::Type, this); AppRegistry::instance().bus()->subscribe(_databaseItem, DeleteCollectionIndexResponse::Type, this); AppRegistry::instance().bus()->subscribe(this, CollectionIndexesLoadingEvent::Type, this); setText(0, QtUtils::toQString(_collection->name())); setIcon(0, GuiRegistry::instance().collectionIcon()); _indexDir = new ExplorerCollectionDirIndexesTreeItem(this); addChild(_indexDir); setExpanded(false); setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); }
void ExplorerDatabaseTreeItem::addCollectionItem(MongoCollection *collection) { auto collectionItem = new ExplorerCollectionTreeItem(_collectionFolderItem, this, collection); collectionItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); _collectionFolderItem->addChild(collectionItem); }
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; } }