void FavoriteHubs::slotChangeButtonClicked(){ FavoriteHubItem *item = getItem(); if (!item) return; QString address = item->data(COLUMN_HUB_ADDRESS).toString(); FavoriteHubEntry *entry = FavoriteManager::getInstance()->getFavoriteHubEntry(address.toStdString()); FavoriteHubEditor editor; if (entry){ StrMap map; getParams(entry, map); initHubEditor(editor, map); if (editor.exec() == QDialog::Accepted){ getParams(editor, map); updateItem(item, map); updateEntry(*entry, map); FavoriteManager::getInstance()->save(); } } }
void FavoriteHubs::slotRemoveButtonClicked(){ FavoriteHubItem *item = getItem(); if (!item) return; QString address = item->data(COLUMN_HUB_ADDRESS).toString(); FavoriteHubEntry *entry = FavoriteManager::getInstance()->getFavoriteHubEntry(address.toStdString()); if (entry) FavoriteManager::getInstance()->removeFavorite(entry); }
void FavoriteHubs::slotDblClicked(){ FavoriteHubItem *item = getItem(); if (!item) return; QString address = item->data(COLUMN_HUB_ADDRESS).toString(); FavoriteHubEntry *entry = FavoriteManager::getInstance()->getFavoriteHubEntry(address.toStdString()); QString encoding = WulforUtil::getInstance()->dcEnc2QtEnc(_q(entry->getEncoding())); MainWindow::getInstance()->newHubFrame(address, encoding); }
int FavoriteHubModel::rowCount(const QModelIndex &parent) const { FavoriteHubItem *parentItem; if (parent.column() > 0) return 0; if (!parent.isValid()) parentItem = rootItem; else parentItem = static_cast<FavoriteHubItem*>(parent.internalPointer()); return parentItem->childCount(); }
QModelIndex FavoriteHubModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); FavoriteHubItem *childItem = static_cast<FavoriteHubItem*>(index.internalPointer()); FavoriteHubItem *parentItem = childItem->parent(); if (parentItem == rootItem) return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); }
void FavoriteHubs::slotClicked(const QModelIndex &index){ if (!index.isValid() || index.column() != COLUMN_HUB_AUTOCONNECT || !index.internalPointer()) return; FavoriteHubItem *item = reinterpret_cast<FavoriteHubItem*>(index.internalPointer()); QString address = item->data(COLUMN_HUB_ADDRESS).toString(); FavoriteHubEntry *entry = FavoriteManager::getInstance()->getFavoriteHubEntry(address.toStdString()); if (entry){ bool autoconnect = !item->data(COLUMN_HUB_AUTOCONNECT).toBool(); entry->setConnect(autoconnect); item->updateColumn(COLUMN_HUB_AUTOCONNECT, autoconnect); model->repaint(); FavoriteManager::getInstance()->save(); } }
QModelIndex FavoriteHubModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) return QModelIndex(); FavoriteHubItem *parentItem; if (!parent.isValid()) parentItem = rootItem; else parentItem = static_cast<FavoriteHubItem*>(parent.internalPointer()); FavoriteHubItem *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); }
QVariant FavoriteHubModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() > columnCount(QModelIndex())) return QVariant(); FavoriteHubItem *item = static_cast<FavoriteHubItem*>(index.internalPointer()); switch(role) { case Qt::DecorationRole: // icon break; case Qt::DisplayRole: if (index.column() == COLUMN_HUB_AUTOCONNECT) break; else if (index.column() != COLUMN_HUB_PASSWORD) return item->data(index.column()); else return QString("******"); break; case Qt::TextAlignmentRole: break; case Qt::ForegroundRole: break; case Qt::ToolTipRole: break; case Qt::CheckStateRole: if (index.column() == COLUMN_HUB_AUTOCONNECT) return item->data(COLUMN_HUB_AUTOCONNECT); break; } return QVariant(); }