当前位置: 首页>>代码示例>>C++>>正文


C++ QAbstractItemModel::insertColumns方法代码示例

本文整理汇总了C++中QAbstractItemModel::insertColumns方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::insertColumns方法的具体用法?C++ QAbstractItemModel::insertColumns怎么用?C++ QAbstractItemModel::insertColumns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QAbstractItemModel的用法示例。


在下文中一共展示了QAbstractItemModel::insertColumns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mapToSource

bool Utils::ModelListModel::insertColumns(int column, int count, const QModelIndex& parent)
{
	Utils::ModelListModel::SubModelIndex smi = mapToSource(parent);
	if (smi.first == m_metaModel && smi.second.parent().isValid())
	{
		QAbstractItemModel* subModel = m_subModels.value(smi.second.row());
		if (subModel)
			return subModel->insertColumns(column, count);
	}
	return smi.first->insertColumns(column, count, smi.second);
}
开发者ID:majewsky,项目名称:majewsky-misc,代码行数:11,代码来源:modellistmodel.cpp

示例2: populateTestArea

/*!
    Fills model with some test data at least twenty rows and if possible twenty or more columns.
    Return the parent of a row/column that can be tested.

    NOTE: If readOnly is true tests will try to remove and add rows and columns.
    If you have a tree model returning not the root index will help catch more errors.
 */
QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
{
    if (QStringListModel *stringListModel = qobject_cast<QStringListModel *>(model)) {
        QString alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
        stringListModel->setStringList( alphabet.split(",") );
        return QModelIndex();
    }

    if (qobject_cast<QStandardItemModel *>(model)) {
        // Basic tree StandardItemModel
        QModelIndex parent;
        QVariant blue = QVariant(QColor(Qt::blue));
#ifndef Q_OS_WINCE
        for (int i = 0; i < 4; ++i) {
#else
        for (int i = 0; i < 2; ++i) {
#endif
            parent = model->index(0, 0, parent);
            model->insertRows(0, 26 + i, parent);
#ifndef Q_OS_WINCE
            model->insertColumns(0, 26 + i, parent);
#else
            model->insertColumns(0, 4 + i, parent);
#endif
            // Fill in some values to make it easier to debug
            /*
            for (int x = 0; x < 26 + i; ++x) {
                QString xval = QString::number(x);
                for (int y = 0; y < 26 + i; ++y) {
                    QString val = xval + QString::number(y) + QString::number(i);
                    QModelIndex index = model->index(x, y, parent);
                    model->setData(index, val);
                    model->setData(index, blue, Qt::TextColorRole);
                }
            }
            */
        }
        return model->index(0,0);
    }

    if (qobject_cast<QSortFilterProxyModel *>(model)) {
        QAbstractItemModel *realModel = (qobject_cast<QSortFilterProxyModel *>(model))->sourceModel();
        // Basic tree StandardItemModel
        QModelIndex parent;
        QVariant blue = QVariant(QColor(Qt::blue));
#ifndef Q_OS_WINCE
        for (int i = 0; i < 4; ++i) {
#else
        for (int i = 0; i < 2; ++i) {
#endif
            parent = realModel->index(0, 0, parent);
            realModel->insertRows(0, 26+i, parent);
#ifndef Q_OS_WINCE
            realModel->insertColumns(0, 26+i, parent);
#else
            realModel->insertColumns(0, 4, parent);
#endif
            // Fill in some values to make it easier to debug
            /*
            for (int x = 0; x < 26+i; ++x) {
                QString xval = QString::number(x);
                for (int y = 0; y < 26 + i; ++y) {
                    QString val = xval + QString::number(y) + QString::number(i);
                    QModelIndex index = realModel->index(x, y, parent);
                    realModel->setData(index, val);
                    realModel->setData(index, blue, Qt::TextColorRole);
                }
            }
            */
        }
        QModelIndex returnIndex = model->index(0,0);
        if (!returnIndex.isValid())
            qFatal("%s: model index to be returned is invalid", Q_FUNC_INFO);
        return returnIndex;
    }

    if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
        if (!QDir::current().mkdir("test"))
            qFatal("%s: cannot create directory %s",
                   Q_FUNC_INFO,
                   qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
        for (int i = 0; i < 26; ++i) {
            QString subdir = QString("test/foo_%1").arg(i);
            if (!QDir::current().mkdir(subdir))
                qFatal("%s: cannot create directory %s",
                       Q_FUNC_INFO,
                       qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
        }
        return dirModel->index(QDir::currentPath()+"/test");
    }

    if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
        QSqlQuery q;
//.........这里部分代码省略.........
开发者ID:RS102839,项目名称:qt,代码行数:101,代码来源:modelstotest.cpp


注:本文中的QAbstractItemModel::insertColumns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。