예제 #1
0
    QVariant ExplorerTreeModel::data(const QModelIndex& index, int role) const
    {
        if (!index.isValid()){
            return QVariant();
        }

        IExplorerTreeItem* node = common::utils_qt::item<IExplorerTreeItem*>(index);

        if (!node){
            return QVariant();
        }

        int col = index.column();

        IExplorerTreeItem::eType t = node->type();

        if(role == Qt::ToolTipRole){
            IServerSPtr serv = node->server();
            if(t == IExplorerTreeItem::eServer && serv){
                ServerDiscoveryInfoSPtr disc = serv->discoveryInfo();
                if(disc){
                    QString dname = common::convertFromString<QString>(disc->name());
                    QString dtype = common::convertFromString<QString>(common::convertToString(disc->type()));
                    QString dhost = common::convertFromString<QString>(common::convertToString(disc->host()));
                    return QString("<b>Name:</b> %1<br/>"
                                   "<b>Type:</b> %2<br/>"
                                   "<b>Host:</b> %3<br/>").arg(dname).arg(dtype).arg(dhost);
                }
            }
            else if(t == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem* db = dynamic_cast<ExplorerDatabaseItem*>(node);
                if(db && db->isDefault()){
                    return QString("<b>Db size:</b> %1 keys<br/>").arg(db->size());
                }
            }
        }

        if(role == Qt::DecorationRole && col == ExplorerServerItem::eName ){
            if(t == IExplorerTreeItem::eCluster){
                return GuiFactory::instance().clusterIcon();
            }
            else if(t == IExplorerTreeItem::eServer){
                return GuiFactory::instance().icon(node->server()->type());
            }
            else if(t == IExplorerTreeItem::eKey){
                return GuiFactory::instance().keyIcon();
            }
            else if(t == IExplorerTreeItem::eDatabase){
                return GuiFactory::instance().databaseIcon();
            }
            else{
                NOTREACHED();
            }
        }

        if (role == Qt::DisplayRole) {
            if (col == IExplorerTreeItem::eName) {
                if(t == IExplorerTreeItem::eKey){
                    return node->name();
                }
                else{
                    return QString("%1 (%2)").arg(node->name()).arg(node->childrenCount());
                }
            }
        }

        if(role == Qt::ForegroundRole){
            if(t == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem* db = dynamic_cast<ExplorerDatabaseItem*>(node);
                if(db && db->isDefault()){
                    return QVariant( QColor( Qt::red ) );
                }
            }
        }

        return QVariant();
    }
예제 #2
0
    void ExplorerTreeView::showContextMenu(const QPoint& point)
    {
        QPoint menuPoint = mapToGlobal(point);
        menuPoint.setY(menuPoint.y() + header()->height());

        QModelIndex sel = selectedIndex();
        if(sel.isValid()){            
            IExplorerTreeItem *node = common::utils_qt::item<IExplorerTreeItem*>(sel);
            DCHECK(node);
            if(!node){
                return;
            }

            if(node->type() == IExplorerTreeItem::eCluster){
                QMenu menu(this);
                closeClusterAction_->setEnabled(true);
                menu.addAction(closeClusterAction_);
                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eServer){
                QMenu menu(this);                
                menu.addAction(connectAction_);
                menu.addAction(openConsoleAction_);

                IServerSPtr server = node->server();
                bool isCon = server->isConnected();
                bool isAuth = server->isAuthenticated();

                bool isClusterMember = dynamic_cast<ExplorerClusterItem*>(node->parent()) != NULL;

                loadDatabaseAction_->setEnabled(isAuth);
                menu.addAction(loadDatabaseAction_);
                infoServerAction_->setEnabled(isAuth);
                menu.addAction(infoServerAction_);
                propertyServerAction_->setEnabled(isAuth);
                menu.addAction(propertyServerAction_);

                setServerPassword_->setEnabled(isAuth);
                menu.addAction(setServerPassword_);

                setMaxClientConnection_->setEnabled(isAuth);
                menu.addAction(setMaxClientConnection_);

                menu.addAction(historyServerAction_);
                closeServerAction_->setEnabled(!isClusterMember);
                menu.addAction(closeServerAction_);

                bool isLocal = server->isLocalHost();

                importAction_->setEnabled(!isCon && isLocal);
                menu.addAction(importAction_);                
                backupAction_->setEnabled(isCon && isLocal);
                menu.addAction(backupAction_);
                shutdownAction_->setEnabled(isAuth);
                menu.addAction(shutdownAction_);

                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem *db = dynamic_cast<ExplorerDatabaseItem*>(node);
                QMenu menu(this);
                menu.addAction(loadContentAction_);
                bool isDefault = db && db->isDefault();
                loadContentAction_->setEnabled(isDefault);

                menu.addAction(createKeyAction_);
                createKeyAction_->setEnabled(isDefault);

                if(isDefault){
                    menu.addAction(viewKeysAction_);
                }

                menu.addAction(setDefaultDbAction_);
                setDefaultDbAction_->setEnabled(!isDefault);
                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eKey){
                QMenu menu(this);
                menu.addAction(getValueAction_);
                menu.addAction(deleteKeyAction_);
                menu.exec(menuPoint);
            }
        }
    }