本文整理汇总了C++中MongoDatabase类的典型用法代码示例。如果您正苦于以下问题:C++ MongoDatabase类的具体用法?C++ MongoDatabase怎么用?C++ MongoDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectedCollectionItem
void ExplorerTreeWidget::ui_dropCollection()
{
ExplorerCollectionTreeItem *collectionItem = selectedCollectionItem();
if (!collectionItem)
return;
MongoCollection *collection = collectionItem->collection();
MongoDatabase *database = collection->database();
MongoServer *server = database->server();
ConnectionSettings *settings = server->connectionRecord();
// Ask user
int answer = QMessageBox::question(this,
"Drop Collection",
QString("Drop <b>%1</b> collection?").arg(collection->name()),
QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);
if (answer != QMessageBox::Yes)
return;
database->dropCollection(collection->name());
database->loadCollections();
//openCurrentCollectionShell("db.%1.drop()", false);
}
示例2: selectedUserItem
void ExplorerTreeWidget::ui_editUser()
{
ExplorerUserTreeItem *userItem = selectedUserItem();
if (!userItem)
return;
MongoUser user = userItem->user();
MongoDatabase *database = userItem->database();
MongoServer *server = database->server();
CreateUserDialog dlg(server->connectionRecord()->getFullAddress(),
database->name(),
user);
dlg.setWindowTitle("Edit User");
dlg.setUserPasswordLabelText("New Password:");
int result = dlg.exec();
if (result == QDialog::Accepted) {
MongoUser user = dlg.user();
database->createUser(user, true);
// refresh list of users
database->loadUsers();
}
}
示例3: setText
void ExplorerServerTreeItem::databaseRefreshed(const QList<MongoDatabase *> &dbs)
{
int count = dbs.count();
setText(0, buildServerName(&count));
// Remove child items
QtUtils::clearChildItems(this);
// Add 'System' folder
QIcon folderIcon = GuiRegistry::instance().folderIcon();
ExplorerTreeItem *systemFolder = new ExplorerTreeItem(this);
systemFolder->setIcon(0, folderIcon);
systemFolder->setText(0, "System");
addChild(systemFolder);
for (int i = 0; i < dbs.size(); i++)
{
MongoDatabase *database = dbs.at(i);
if (database->isSystem()) {
ExplorerDatabaseTreeItem *dbItem = new ExplorerDatabaseTreeItem(systemFolder,database);
systemFolder->addChild(dbItem);
continue;
}
ExplorerDatabaseTreeItem *dbItem = new ExplorerDatabaseTreeItem(this,database);
addChild(dbItem);
}
// Show 'System' folder only if it has items
systemFolder->setHidden(systemFolder->childCount() == 0);
}
示例4: selectedFunctionItem
void ExplorerTreeWidget::ui_editFunction()
{
ExplorerFunctionTreeItem *functionItem = selectedFunctionItem();
if (!functionItem)
return;
MongoFunction function= functionItem->function();
MongoDatabase *database = functionItem->database();
MongoServer *server = database->server();
QString name = function.name();
FunctionTextEditor dlg(server->connectionRecord()->getFullAddress(),
database->name(),
function);
dlg.setWindowTitle("Edit Function");
int result = dlg.exec();
if (result == QDialog::Accepted) {
MongoFunction editedFunction = dlg.function();
database->updateFunction(name, editedFunction);
// refresh list of functions
database->loadFunctions();
}
}
示例5: getDatabasesNames
QStringList MongoServer::getDatabasesNames() const {
QStringList result;
for (QList<MongoDatabase *>::const_iterator it = _databases.begin(); it != _databases.end(); ++it) {
MongoDatabase *datab = *it;
result.append(QtUtils::toQString(datab->name()));
}
return result;
}
示例6:
MongoDatabase *MongoServer::findDatabaseByName(const std::string &dbName) const {
for (QList<MongoDatabase *>::const_iterator it = _databases.begin(); it != _databases.end(); ++it) {
MongoDatabase *datab = *it;
if (datab->name() == dbName) {
return datab;
}
}
return NULL;
}
示例7: ui_dropCollection
void ExplorerCollectionTreeItem::ui_dropCollection()
{
// Ask user
int answer = utils::questionDialog(treeWidget(), "Drop", "collection", QtUtils::toQString(_collection->name()));
if (answer == QMessageBox::Yes) {
MongoDatabase *database = _collection->database();
database->dropCollection(_collection->name());
}
}
示例8: exportMolecule
void ExportMoleculeHandler::exportMolecule()
{
if (m_molecule.isValid()) {
// Retrieve the molecule from the database.
MongoDatabase *db = MongoDatabase::instance();
mongo::BSONObj moleculeObj = db->fetchMolecule(m_molecule);
Avogadro::Core::Molecule mol;
// Check for atoms in the molecule.
if (moleculeObj.hasField("atoms")) {
// Generate chemical json string.
std::string cjson = CjsonExporter::toCjson(moleculeObj);
// Create a molecule object for export.
FileFormatManager::instance().readString(mol, cjson, "cjson");
}
else if (moleculeObj.hasField("inchi")) {
// Attempt to load from InChI otherwise.
FileFormatManager::instance().readString(mol,
moleculeObj.getStringField("inchi"),
"inchi");
}
// get molecule name to set default file name
QString moleculeName = moleculeObj.getStringField("name");
if (moleculeName.isEmpty())
moleculeName = "molecule";
// Pop-up dialog and get file name
QString fileName = QFileDialog::getSaveFileName(0,
tr("Save File"),
QDir::currentPath() +
QDir::separator() +
moleculeName + ".cml");
if (fileName.isEmpty())
return;
bool ok = FileFormatManager::instance().writeFile(mol,
fileName.toStdString());
if(!ok) {
// writing failed, display an error dialog
QString errorMessage =
QString("Failed to write molecule to file (%1).").arg(fileName);
QMessageBox::critical(0, "Molecule Export Failed", errorMessage);
}
}
}
示例9: toCjson
std::string CjsonExporter::toCjson(const mongo::BSONObj &mongoChemObj)
{
// Follow the database link and convert to CJSON.
MongoDatabase *db = MongoDatabase::instance();
if (!db)
return "";
mongo::BSONObj structure = mongoChemObj.getObjectField("3dStructure");
if (!structure.hasField("$ref") || !structure.hasField("$id")
|| !structure.getField("$id").isSimpleType()) {
return "";
}
std::auto_ptr<mongo::DBClientCursor> cursor =
db->query(db->databaseName() + "." + structure.getStringField("$ref"),
QUERY("_id" << structure.getField("$id").OID()), 1);
mongo::BSONObj object;
if (cursor->more())
object = cursor->next();
else
return "";
std::vector<std::string> toCopy;
toCopy.push_back("name");
toCopy.push_back("inchi");
toCopy.push_back("formula");
toCopy.push_back("properties");
mongo::BSONObjBuilder builder;
for (size_t i = 0; i < toCopy.size(); i++) {
mongo::BSONElement field = mongoChemObj.getField(toCopy[i]);
if (!field.eoo())
builder.append(field);
}
toCopy.clear();
toCopy.push_back("atoms");
toCopy.push_back("bonds");
for (size_t i = 0; i < toCopy.size(); i++) {
mongo::BSONElement field = object.getField(toCopy[i]);
if (!field.eoo())
builder.append(field);
}
// Add the chemical JSON version field.
builder.append("chemical json", 0);
mongo::BSONObj obj = builder.obj();
return obj.jsonString(mongo::Strict);
}
示例10: ui_removeAllDocuments
void ExplorerCollectionTreeItem::ui_removeAllDocuments()
{
MongoDatabase *database = _collection->database();
// Ask user
int answer = QMessageBox::question(treeWidget(),
"Remove All Documents",
QString("Remove all documents from <b>%1</b> collection?").arg(QtUtils::toQString(_collection->name())),
QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);
if (answer == QMessageBox::Yes) {
MongoServer *server = database->server();
mongo::BSONObjBuilder builder;
mongo::BSONObj bsonQuery = builder.obj();
mongo::Query query(bsonQuery);
server->removeDocuments(query, MongoNamespace(database->name(), _collection->name()), false);
}
}
示例11: ui_addDocument
void ExplorerCollectionTreeItem::ui_addDocument()
{
MongoDatabase *database = _collection->database();
MongoServer *server = database->server();
ConnectionSettings *settings = server->connectionRecord();
DocumentTextEditor editor(CollectionInfo(settings->getFullAddress(), database->name(), _collection->name()), "{\n \n}");
editor.setCursorPosition(1, 4);
editor.setWindowTitle("Insert Document");
int result = editor.exec();
treeWidget()->activateWindow();
if (result == QDialog::Accepted) {
server->insertDocuments(editor.bsonObj(), MongoNamespace(database->name(), _collection->name()) );
}
}
示例12: contextMenuEvent
void ComputationalResultsTableView::contextMenuEvent(QContextMenuEvent *e)
{
MongoDatabase *db = MongoDatabase::instance();
QModelIndex index = indexAt(e->pos());
if (index.isValid()) {
mongo::BSONObj *obj =
static_cast<mongo::BSONObj *>(index.internalPointer());
QMenu *menu = new QMenu(this);
QAction *action;
// add view and save log file actions
if (obj && obj->hasField("log_file")) {
action = menu->addAction("&View Log File",
this,
SLOT(showLogFile()));
action = menu->addAction("&Save Log File",
this,
SLOT(showLogFile()));
}
// add open in editor action
action = menu->addAction("&Open in Editor");
MoleculeRef ref = db->findMoleculeFromBSONObj(obj);
m_openInEditorHandler->setMolecule(ref);
connect(action, SIGNAL(triggered()),
m_openInEditorHandler, SLOT(openInEditor()));
// add details action
if (m_enableShowDetailsAction) {
action = menu->addAction("Show Molecule &Details",
this,
SLOT(showMoleculeDetailsDialog()));
}
m_row = index.row();
menu->exec(QCursor::pos());
}
}
示例13: showMoleculeDetailsDialog
void ComputationalResultsTableView::showMoleculeDetailsDialog()
{
MongoDatabase *db = MongoDatabase::instance();
mongo::BSONObj *obj =
static_cast<mongo::BSONObj *>(currentIndex().internalPointer());
std::string inchikey = obj->getStringField("inchikey");
MoleculeRef ref = db->findMoleculeFromInChIKey(inchikey);
if (ref.isValid()) {
MoleculeDetailDialog *dialog = new MoleculeDetailDialog(this);
dialog->setMolecule(ref);
dialog->show();
}
else {
QMessageBox::critical(this,
"Error",
"Failed to find molecule in collection.");
}
}
示例14: ui_renameCollection
void ExplorerCollectionTreeItem::ui_renameCollection()
{
MongoDatabase *database = _collection->database();
MongoServer *server = database->server();
ConnectionSettings *connSettings = server->connectionRecord();
CreateDatabaseDialog dlg(QtUtils::toQString(connSettings->getFullAddress()),
QtUtils::toQString(database->name()),
QtUtils::toQString(_collection->name()), treeWidget());
dlg.setWindowTitle("Rename Collection");
dlg.setOkButtonText("&Rename");
dlg.setInputLabelText("New Collection Name:");
dlg.setInputText(QtUtils::toQString(_collection->name()));
int result = dlg.exec();
if (result == QDialog::Accepted) {
database->renameCollection(_collection->name(), QtUtils::toStdString(dlg.databaseName()));
}
}
示例15: showLogFile
void ComputationalResultsTableView::showLogFile()
{
MongoDatabase *db = MongoDatabase::instance();
mongo::GridFS fs(*db->connection(), "chem", "fs");
mongo::BSONObj *obj =
static_cast<mongo::BSONObj *>(currentIndex().internalPointer());
if (obj) {
const char *file_name = obj->getStringField("log_file");
mongo::GridFile file = fs.findFile(file_name);
if (!file.exists()) {
QMessageBox::critical(this,
"Error",
"Failed to load output file.");
return;
}
// load file into a buffer
std::stringstream stream;
file.write(stream);
QTextEdit *viewer = new QTextEdit(this);
viewer->resize(500, 600);
viewer->setWindowFlags(Qt::Dialog);
viewer->setWindowTitle(file_name);
viewer->setReadOnly(true);
std::string file_data_string = stream.str();
viewer->setText(file_data_string.c_str());
viewer->show();
}
else {
QMessageBox::critical(this,
"Error",
"Failed to load output file.");
}
}