예제 #1
0
			void PackagesDelegate::handleRowActionFinished (int row)
			{
				// Front — deepest proxy, back — outermost.
				QList<QAbstractProxyModel*> proxyChain;
				QAbstractItemModel *realModel = Model_;
				QAbstractProxyModel *proxy = 0;
				while ((proxy = qobject_cast<QAbstractProxyModel*> (realModel)))
				{
					proxyChain.push_front (proxy);
					realModel = proxy->sourceModel ();
				}

				QModelIndex index = realModel->index (row, 0);

				Q_FOREACH (QAbstractProxyModel *pm, proxyChain)
					index = pm->mapFromSource (index);

				row = index.row ();

				if (Row2InstallRemove_.contains (row))
				{
					Row2InstallRemove_ [row]->setChecked (false);
					Row2InstallRemove_ [row]->defaultAction ()->setChecked (false);
					Row2InstallRemove_ [row]->setChecked (false);
				}
				if (Row2Update_.contains (row))
				{
					Row2Update_ [row]->defaultAction ()->setChecked (false);
				}
			}
예제 #2
0
void QmlConsoleView::contextMenuEvent(QContextMenuEvent *event)
{
    QModelIndex itemIndex = indexAt(event->pos());
    QMenu menu;

    QAction *copy = new QAction(tr("&Copy"), this);
    copy->setEnabled(itemIndex.isValid());
    menu.addAction(copy);
    QAction *show = new QAction(tr("&Show in Editor"), this);
    show->setEnabled(canShowItemInTextEditor(itemIndex));
    menu.addAction(show);
    menu.addSeparator();
    QAction *clear = new QAction(tr("C&lear"), this);
    menu.addAction(clear);

    QAction *a = menu.exec(event->globalPos());
    if (a == 0)
        return;

    if (a == copy) {
        copyToClipboard(itemIndex);
    } else if (a == show) {
        onRowActivated(itemIndex);
    } else if (a == clear) {
        QAbstractProxyModel *proxyModel = qobject_cast<QAbstractProxyModel *>(model());
        QmlConsoleItemModel *handler = qobject_cast<QmlConsoleItemModel *>(
                    proxyModel->sourceModel());
        handler->clear();
    }
}
예제 #3
0
QModelIndex ModelModel::parent(const QModelIndex &child) const
{
    QAbstractItemModel *model = static_cast<QAbstractItemModel *>(child.internalPointer());
    Q_ASSERT(model);
    if (m_models.contains(model))
        return QModelIndex();

    QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(model);
    Q_ASSERT(proxy);
    return indexForModel(proxy->sourceModel());
}
예제 #4
0
static QAbstractItemModel* sourceModelForProxy(QAbstractItemModel* model)
{
  // stop once we found a registered model, this is what network communication is based on
  if (s_objectBroker()->models.values().contains(model))
    return model;

  QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel*>(model);
  if (!proxy)
    return model;
  return sourceModelForProxy(proxy->sourceModel());
}
예제 #5
0
void ModelModel::objectAdded(QObject *obj)
{
    QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(obj);
    if (proxy) {
        beginResetModel(); // FIXME
        if (proxy->sourceModel())
            m_proxies.push_back(proxy);
        else
            m_models.push_back(proxy);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        connect(proxy, &QAbstractProxyModel::sourceModelChanged, this, [this, proxy]() {
            beginResetModel(); // FIXME
            if (proxy->sourceModel()) {
                const auto i = m_models.indexOf(proxy);
                if (i >= 0)
                    m_models.remove(i);
                m_proxies.push_back(proxy);
            } else {
                const auto i = m_proxies.indexOf(proxy);
                if (i >= 0)
                    m_proxies.remove(i);
                m_models.push_back(proxy);
            }
            endResetModel();
        });
#endif
        endResetModel();
        return;
    }

    QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(obj);
    if (model) {
        beginInsertRows(QModelIndex(), m_models.size(), m_models.size());
        m_models.push_back(model);
        endInsertRows();
    }
}
예제 #6
0
void RequieredResourceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                const QModelIndex &index) const
{
    TreeComboBox *box = static_cast<TreeComboBox*>(editor);

    QAbstractProxyModel *pm = static_cast<QAbstractProxyModel*>( box->model() );
    ResourceItemModel *rm = qobject_cast<ResourceItemModel*>( pm->sourceModel() );
    QList<Resource*> lst;
    foreach ( const QModelIndex &i, box->currentIndexes() ) {
        lst << rm->resource( pm->mapToSource( i ) );
    }
    ResourceAllocationItemModel *mdl = qobject_cast<ResourceAllocationItemModel*>( model );
    Q_ASSERT( mdl );
    mdl->setRequired( index, lst );
}
예제 #7
0
QModelIndex ModelModel::indexForModel(QAbstractItemModel *model) const
{
    if (!model)
        return QModelIndex();
    QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(model);
    if (!proxy) {
        Q_ASSERT(m_models.contains(model));
        return index(m_models.indexOf(model), 0, QModelIndex());
    }

    QAbstractItemModel *sourceModel = proxy->sourceModel();
    const QModelIndex parentIndex = indexForModel(sourceModel);
    const QVector<QAbstractProxyModel *> proxies = proxiesForModel(sourceModel);
    Q_ASSERT(proxies.contains(proxy));
    return index(proxies.indexOf(proxy), 0, parentIndex);
}