本文整理汇总了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);
}
示例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());
}
示例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();
}
示例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);
}
示例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()));
}
示例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());
}
}
示例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()));
}
示例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);
}
示例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);
}
示例10: fileName
void tst_QDirModel::fileName()
{
QDirModel model;
QFETCH(QString, path);
QFETCH(QString, result);
QCOMPARE(model.fileName(model.index(path)), result);
}
示例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);
}
示例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;
}
}
}
示例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));
}
示例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出来,进入程序的事件循环就好了
}
示例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
}