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


C++ QDirModel::index方法代码示例

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


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

示例1: selectAll

void tst_QColumnView::selectAll()
{
    ColumnView view;
    view.selectAll();

    QDirModel model;
    view.setModel(&model);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0);

    QModelIndex home = model.index(QDir::homePath());
    view.setCurrentIndex(home);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);

    QModelIndex file;
    for (int i = 0; i < model.rowCount(home); ++i)
        if (!model.hasChildren(model.index(i, 0, home))) {
            file = model.index(i, 0, home);
            break;
        }
    view.setCurrentIndex(file);
    view.selectAll();
    QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);

    view.setCurrentIndex(QModelIndex());
    QVERIFY(view.selectionModel()->selectedIndexes().count() == 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:28,代码来源:tst_qcolumnview.cpp

示例2: QCOMPARE

void tst_QDirModel::task196768_sorting()
{
    //this task showed that the persistent model indexes got corrupted when sorting
    QString path = SRCDIR;

    QDirModel model;

    /* QDirModel has a bug if we show the content of the subdirectory inside a hidden directory
       and we don't add QDir::Hidden. But as QDirModel is deprecated, we decided not to fix it. */
    model.setFilter(QDir::AllEntries | QDir::Hidden | QDir::AllDirs);

    QTreeView view;
    QPersistentModelIndex index = model.index(path);
    view.setModel(&model);
    QModelIndex index2 = model.index(path);
    QCOMPARE(index.data(), index2.data());
    view.setRootIndex(index);
    index2 = model.index(path);
    QCOMPARE(index.data(), index2.data());
    view.setCurrentIndex(index);
    index2 = model.index(path);
    QCOMPARE(index.data(), index2.data());
    view.setSortingEnabled(true);
    index2 = model.index(path);

    QCOMPARE(index.data(), index2.data());
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例3: main

//! [0] //! [1]
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QSplitter *splitter = new QSplitter;

//! [2] //! [3]
    QDirModel *model = new QDirModel;
//! [0] //! [2] //! [4] //! [5]
    QTreeView *tree = new QTreeView(splitter);
//! [3] //! [6]
    tree->setModel(model);
//! [4] //! [6] //! [7]
    tree->setRootIndex(model->index(QDir::currentPath()));
//! [7]

    QListView *list = new QListView(splitter);
    list->setModel(model);
    list->setRootIndex(model->index(QDir::currentPath()));

//! [5]
    QItemSelectionModel *selection = new QItemSelectionModel(model);
    tree->setSelectionModel(selection);
    list->setSelectionModel(selection);

//! [8]
    splitter->setWindowTitle("Two views onto the same directory model");
    splitter->show();
    return app.exec();
}
开发者ID:dfizban,项目名称:remixos-usb-tool,代码行数:30,代码来源:main.cpp

示例4: filter

void tst_QDirModel::filter()
{
    QDirModel model;
    model.setNameFilters(QStringList() << "*.nada");
    QModelIndex index = model.index(SRCDIR "test");
    QCOMPARE(model.rowCount(index), 0);
    QModelIndex index2 = model.index(SRCDIR "test/file01.tst");
    QVERIFY(!index2.isValid());
    QCOMPARE(model.rowCount(index), 0);
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例5: QDialog

DirectoryTree::DirectoryTree(const QString &dir, QWidget *parent) : QDialog(parent)
{
	QTreeView *view = new QTreeView(this);
	QDirModel *model = new QDirModel;
	view->setModel(model);
	view->setRootIndex(model->index(dir));
	view->resizeColumnToContents(0);
	setWindowTitle(dir);

	QPushButton *ok = new QPushButton(tr("&OK"));
	QSpacerItem *item = new QSpacerItem(40, 20, QSizePolicy::Expanding);
	QHBoxLayout *bottom = new QHBoxLayout;
	bottom->addItem(item);
	bottom->addWidget(ok);

	QVBoxLayout *layout = new QVBoxLayout;
	layout->addWidget(view);
	layout->addLayout(bottom);
	setLayout(layout);
	setMinimumSize(600, 400);
//	resize(sizeHint());
	ok->setFocus();

	connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
}
开发者ID:sonald,项目名称:isoft-os-installer,代码行数:25,代码来源:directorytree.cpp

示例6: clicked

void tst_QColumnView::clicked()
{
    ColumnView view;

    QDirModel model;
    view.setModel(&model);
    view.resize(800,300);
    view.show();

    QModelIndex home = model.index(QDir::homePath());
    QVERIFY(home.isValid());
    view.setCurrentIndex(home);
    QTest::qWait(ANIMATION_DELAY);

    QModelIndex parent = home.parent();
    QVERIFY(parent.isValid());

    qRegisterMetaType<QModelIndex>("QModelIndex");
    QSignalSpy clickedSpy(&view, SIGNAL(clicked(const QModelIndex &)));

    QPoint localPoint = view.visualRect(home).center();
    QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
    QCOMPARE(clickedSpy.count(), 1);
    qApp->processEvents();
    
    if (sizeof(qreal) != sizeof(double)) {
        QSKIP("Skipped due to rounding errors", SkipAll);
    }
    
    for (int i = 0; i < view.createdColumns.count(); ++i) {
        QAbstractItemView *column = view.createdColumns.at(i);
        if (column && column->selectionModel() && (column->rootIndex() == home))
                QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
    }
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:35,代码来源:tst_qcolumnview.cpp

示例7: sizes

void tst_QColumnView::sizes()
{
    QColumnView view;
    QCOMPARE(view.columnWidths().count(), 0);

    QList<int> newSizes;
    newSizes << 10 << 4 << 50 << 6;

    QList<int> visibleSizes;
    view.setColumnWidths(newSizes);
    QCOMPARE(view.columnWidths(), visibleSizes);

    QDirModel model;
    view.setModel(&model);
    QModelIndex home = model.index(QDir::homePath());
    view.setCurrentIndex(home);

    QList<int> postSizes = view.columnWidths().mid(0, newSizes.count());
    QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));

    QVERIFY(view.columnWidths().count() > 1);
    QList<int> smallerSizes;
    smallerSizes << 6;
    view.setColumnWidths(smallerSizes);
    QList<int> expectedSizes = newSizes;
    expectedSizes[0] = 6;
    postSizes = view.columnWidths().mid(0, newSizes.count());
    QCOMPARE(postSizes, expectedSizes.mid(0, postSizes.count()));
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:29,代码来源:tst_qcolumnview.cpp

示例8: rmdir

void tst_QDirModel::rmdir()
{
    QFETCH(QString, dirName);
    QFETCH(bool, rmdirSuccess);
    QFETCH(int, rowCount);

    QDirModel model;
    model.setReadOnly(false);

    QModelIndex parent = model.index(SRCDIR  "/dirtest");
    QVERIFY(parent.isValid());
    QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot

    QModelIndex index;
    if (rmdirSuccess) {
        index = model.mkdir(parent, dirName);
        QVERIFY(index.isValid());
    }

    int rows = model.rowCount(parent);
    bool success = model.rmdir(index);

    if (!success) { // cleanup
        QDir dirtests(SRCDIR  "/dirtests/");
        dirtests.rmdir(dirName);
    }

    QCOMPARE(rows, rowCount);
    QCOMPARE(success, rmdirSuccess);
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例9: exempleDirModel

void Window::exempleDirModel()
{
    QVBoxLayout* layout = new QVBoxLayout;

    QDirModel* modele = new QDirModel;
    QTreeView* treeView = new QTreeView;
    QListView* listView = new QListView;

    treeView->setModel(modele);
    listView->setModel(modele);

    treeView->setRootIndex(modele->index("C:/MinGW"));
    listView->setRootIndex(modele->index("C:"));
    layout->addWidget(treeView);

    setCentralWidget(treeView);
}
开发者ID:cniel,项目名称:cpp_projects,代码行数:17,代码来源:Window.cpp

示例10: fileName

void tst_QDirModel::fileName()
{
    QDirModel model;

    QFETCH(QString, path);
    QFETCH(QString, result);
    QCOMPARE(model.fileName(model.index(path)), result);
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例11: setModel

void QModifyFileDialog::setModel(QString filePath)
{
    QDirModel* model = new QDirModel;
    m_ui->treeView->setModel(model);
    m_ui->treeView->setRootIndex(model->index(filePath));

    m_ui->treeView->hideColumn(1);
    m_ui->treeView->hideColumn(2);
    m_ui->treeView->hideColumn(3);
}
开发者ID:jagens,项目名称:chmcreator,代码行数:10,代码来源:qmodifyfiledialog.cpp

示例12: indexAt

void tst_QColumnView::indexAt()
{
    QColumnView view;
    QCOMPARE(view.indexAt(QPoint(0,0)), QModelIndex());
    QDirModel model;
    view.setModel(&model);

    QModelIndex home = model.index(QDir::homePath());
    QModelIndex homeFile = model.index(0, 0, home);
    if (!homeFile.isValid())
        return;
    view.setRootIndex(home);
    QRect rect = view.visualRect(QModelIndex());
    QVERIFY(!rect.isValid());
    rect = view.visualRect(homeFile);
    QVERIFY(rect.isValid());

    QModelIndex child;
    for (int i = 0; i < model.rowCount(home); ++i) {
        child = model.index(i, 0, home);
        rect = view.visualRect(child);
        QVERIFY(rect.isValid());
        if (i > 0)
            QVERIFY(rect.top() > 0);
        QCOMPARE(view.indexAt(rect.center()), child);

        view.selectionModel()->select(child, QItemSelectionModel::SelectCurrent);
        view.setCurrentIndex(child);
        qApp->processEvents();
        QTest::qWait(200);

        // test that the second row doesn't start at 0
        if (model.rowCount(child) > 0) {
            child = model.index(0, 0, child);
            QVERIFY(child.isValid());
            rect = view.visualRect(child);
            QVERIFY(rect.isValid());
            QVERIFY(rect.left() > 0);
            QCOMPARE(view.indexAt(rect.center()), child);
            break;
        }
    }
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:43,代码来源:tst_qcolumnview.cpp

示例13: rowsAboutToBeRemoved

void tst_QDirModel::rowsAboutToBeRemoved()
{
    QFETCH(QString, test_path);
    QFETCH(QStringList, initial_files);
    QFETCH(int, remove_row);
    QFETCH(QStringList, remove_files);
    QFETCH(QStringList, expected_files);

    rowsAboutToBeRemoved_cleanup(test_path); // clean up first
    QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files));

    QDirModel model;
    model.setReadOnly(false);

    qRegisterMetaType<QModelIndex>("QModelIndex");

    // NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory,
    // and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for
    // rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged
    QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged()));

    QModelIndex parent = model.index(test_path);
    QVERIFY(parent.isValid());

    // remove the file
    {
        QModelIndex index = model.index(remove_row, 0, parent);
        QVERIFY(index.isValid());
        QVERIFY(model.remove(index));
    }

    QCOMPARE(spy.count(), 1);

    // Compare the result
    for (int row = 0; row < expected_files.count(); ++row) {
        QModelIndex index = model.index(row, 0, parent);
        QString str = index.data().toString();
        QCOMPARE(str, expected_files.at(row));
    }

    QVERIFY(rowsAboutToBeRemoved_cleanup(test_path));
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例14: initDirTreeUI

void ChooseShareFilesDialog::initDirTreeUI(){
    QDirModel *model = new QDirModel;
    QTreeView *tree = ui->dirTree;
    tree->setModel(model);
    tree->setRootIndex(model->index(DIR_ROOT));
    //配置一个view去显示model中的数据,只需要简单地调用setModel(),并把目录model作为参数传递
    //setRootIndex()告诉views显示哪个目录的信息,这需要提供一个model index,然后用这个
    //model index去model中去获取数据
    //index()这个函数是QDirModel特有的,通过把一个目录做为参数,得到了需要的model index
    //其他的代码只是窗口show出来,进入程序的事件循环就好了

}
开发者ID:horryq,项目名称:p2pnetwork,代码行数:12,代码来源:choosesharefilesdialog.cpp

示例15: doSomethingExperimental

void MainWindowImpl::doSomethingExperimental()
{
	qDebug() << "MainWindowImpl::doSomethingExperimental()";
	//new QGraphicsLineItem( 0,0, 200, 200 )
	//impl->gstate.scene()->addItem(  );
	//impl->gstate.scene()->addWidget( new QFrame );

	if(0)
	{
	    QString fileName("eval.js");
	    QFile scriptFile(fileName);
	    if (!scriptFile.open(QIODevice::ReadOnly)) return;
	    qDebug() << "[ running script"<<fileName<<"]";
	    QScriptEngine & eng( impl->gstate.jsEngine() );
	    QTextStream stream(&scriptFile);
	    QString contents = stream.readAll();
	    scriptFile.close();
	    eng.evaluate(contents, fileName);
	    qDebug() << "[ done running script"<<fileName<<"]";
	}

	if(0)
	{
	    QBoardHomeView * v = new QBoardHomeView(0);
	    v->show();
	    connect( v, SIGNAL(itemActivated(QFileInfo const &)),
		     this, SLOT(loadFile(QFileInfo const &)) );

#if 0
	    QDirModel *model = new QDirModel;
	    model->setIconProvider( impl->fb->iconProvider() );
	    QTreeView *tree = new QTreeView(0);
	    tree->setModel(model);
	    for( int i = 1; i < 4; ++i )
	    {
		tree->setColumnHidden(i, true);
	    }
	    tree->setRootIndex(model->index(QDir::currentPath()));
	    tree->show();
	    QString fn("QBoard/manual/index.html");
	    QModelIndex sel;
#define FP sel = model->index(fn); \
	    qDebug() << fn << "sel.isValid() =="<<sel.isValid() \
		     << "filePath =="<<model->filePath(sel);
	    FP;
	    fn = QString("%1/QBoard/manual/index.html").arg(qboard::home().absolutePath());
	    FP;
	    fn = "/foo";
	    FP;
#undef FP
#endif
	}
开发者ID:SashaIliyn,项目名称:GUI-Project,代码行数:52,代码来源:MainWindowImpl.cpp


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