Beispiel #1
0
void DefaultProxyAction::populateMenu(QMenu *menu, QActionGroup *actionGroup, NetworkProxy defaultProxy)
{
	auto proxyModel = injectedFactory()->makeInjected<NetworkProxyModel>();
	auto proxyProxyModel = new NetworkProxyProxyModel();
	proxyProxyModel->setSourceModel(proxyModel);

	int proxCount = proxyProxyModel->rowCount();

	for (int i = 0; i < proxCount; i++)
	{
		NetworkProxy networkProxy = proxyProxyModel->data(proxyProxyModel->index(i, 0), NetworkProxyRole).value<NetworkProxy>();
		if (networkProxy)
		{
			QAction *proxyAction = menu->addAction(networkProxy.displayName());
			actionGroup->addAction(proxyAction);
			proxyAction->setData(QVariant::fromValue(networkProxy));
			proxyAction->setCheckable(true);
			if (defaultProxy == networkProxy)
				proxyAction->setChecked(true);
		}
	}

	delete proxyProxyModel;
	delete proxyModel;
}
Beispiel #2
0
QVariant NetworkProxyModel::data(const QModelIndex &index, int role) const
{
	NetworkProxy proxy = networkProxy(index);
	if (proxy.isNull())
		return QVariant();

	switch (role)
	{
		case Qt::DisplayRole:
			return proxy.displayName();

		case NetworkProxyRole:
			return QVariant::fromValue<NetworkProxy>(proxy);

		case ItemTypeRole:
			return NetworkProxyRole;

		default:
			return QVariant();
	}
}