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(); }
void DiscoveryDiagnosticDialog::connectionResult(bool suc, qint64 mstimeExecute, const QString& resultText, std::vector<ServerDiscoveryInfoSPtr> infos) { glassWidget_->stop(); executeTimeLabel_->setText(timeTemplate.arg(mstimeExecute)); listWidget_->setEnabled(suc); listWidget_->clear(); if(suc){ QIcon icon = GuiFactory::instance().successIcon(); const QPixmap pm = icon.pixmap(stateIconSize); iconLabel_->setPixmap(pm); for(int i = 0; i < infos.size(); ++i){ ServerDiscoveryInfoSPtr inf = infos[i]; common::net::hostAndPort host = inf->host(); IConnectionSettingsBaseSPtr con(IConnectionSettingsRemote::createFromType(inf->connectionType(), inf->name(), host)); ConnectionListWidgetItemEx* item = new ConnectionListWidgetItemEx(con, inf->type()); item->setDisabled(inf->self() || cluster_->findSettingsByHost(host)); listWidget_->addTopLevelItem(item); } } statusLabel_->setText(connectionStatusTemplate.arg(resultText)); }