本文整理汇总了C++中QDirModel类的典型用法代码示例。如果您正苦于以下问题:C++ QDirModel类的具体用法?C++ QDirModel怎么用?C++ QDirModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDirModel类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QCOMPARE
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;
}
}
}
示例2: QVERIFY
void tst_QDirModel::filePath()
{
QFile::remove(SRCDIR "test.lnk");
QVERIFY(QFile(SRCDIR "tst_qdirmodel.cpp").link(SRCDIR "test.lnk"));
QDirModel model;
model.setResolveSymlinks(false);
QModelIndex index = model.index(SRCDIR "test.lnk");
QVERIFY(index.isValid());
#ifndef Q_OS_WINCE
QString path = SRCDIR;
#else
QString path = QFileInfo(SRCDIR).absoluteFilePath() + "/";
#endif
QCOMPARE(model.filePath(index), path + QString( "test.lnk"));
model.setResolveSymlinks(true);
QCOMPARE(model.filePath(index), path + QString( "tst_qdirmodel.cpp"));
QFile::remove(SRCDIR "test.lnk");
}
示例3: QFETCH
void tst_QDirModel::mkdir()
{
QFETCH(QString, dirName);
QFETCH(bool, mkdirSuccess);
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 = model.mkdir(parent, dirName);
bool success = index.isValid();
int rows = model.rowCount(parent);
if (success && !model.rmdir(index))
QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName));
QCOMPARE(rows, rowCount);
QCOMPARE(success, mkdirSuccess);
}
示例4: QCOMPARE
void tst_QColumnView::visualRegionForSelection()
{
ColumnView view;
QItemSelection emptyItemSelection;
QCOMPARE(QRegion(), view.visualRegionForSelection(emptyItemSelection));
// a region that isn't empty
QDirModel model;
view.setModel(&model);
// On Windows CE the home directory might actually be empty.
#ifndef Q_OS_WINCE
QString location = QDir::homePath();
#else
QString location = QLatin1String("/Windows");
#endif
QModelIndex home = model.index(location);
QVERIFY(model.rowCount(home) > 1);
QItemSelection itemSelection(model.index(0, 0, home), model.index(model.rowCount(home) - 1, 0, home));
QVERIFY(QRegion() != view.visualRegionForSelection(itemSelection));
}
示例5: f1
void tst_QDirModel::task244669_remove()
{
QFile f1(SRCDIR "dirtest/f1.txt");
QVERIFY(f1.open(QIODevice::WriteOnly));
f1.close();
QFile f2(SRCDIR "dirtest/f2.txt");
QVERIFY(f2.open(QIODevice::WriteOnly));
f2.close();
QDirModel model;
model.setReadOnly(false);
QPersistentModelIndex parent = model.index(SRCDIR "dirtest");
QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt");
QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt");
QVERIFY(parent.isValid());
QVERIFY(index1.isValid());
QVERIFY(index2.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data());
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
QVERIFY(model.remove(index1));
QVERIFY(parent.isValid());
QVERIFY(!index1.isValid());
QVERIFY(index2.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
QVERIFY(model.remove(index2));
QVERIFY(parent.isValid());
QVERIFY(!index2.isValid());
QVERIFY(!index1.isValid());
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
}
示例6: QFETCH
void tst_QColumnView::moveCursor()
{
QFETCH(bool, reverse);
if (reverse)
qApp->setLayoutDirection(Qt::RightToLeft);
ColumnView view;
// don't crash
view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier);
// don't do anything
QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());
QDirModel model;
view.setModel(&model);
QModelIndex home = model.index(QDir::homePath());
QModelIndex ci = view.currentIndex();
QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());
// left at root
view.setCurrentIndex(model.index(0,0));
ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), model.index(0,0));
// left shouldn't move up
int i = 0;
ci = model.index(0, 0);
while (i < model.rowCount() - 1 && !model.hasChildren(ci))
ci = model.index(++i, 0);
QVERIFY(model.hasChildren(ci));
view.setCurrentIndex(ci);
action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci);
// now move to the left (i.e. move over one column)
view.setCurrentIndex(home);
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), home.parent());
// right
action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight;
view.setCurrentIndex(ci);
QModelIndex mc = view.MoveCursor(action, Qt::NoModifier);
QCOMPARE(mc, model.index(0,0, ci));
// next one should move down
QModelIndex idx = model.index(0, 0, ci);
while (model.hasChildren(idx) && model.rowCount(ci) > idx.row() + 1)
idx = idx.sibling(idx.row() + 1, idx.column());
view.setCurrentIndex(idx);
mc = view.MoveCursor(action, Qt::NoModifier);
QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column()));
}
示例7: qDebug
void Widget::on_pushButtonChIDV3_clicked()
{
ui->treeView->setSelectionMode(QTreeView::ExtendedSelection);
ui->treeView->setSelectionBehavior(QTreeView::SelectRows);
QModelIndexList list = ui->treeView->selectionModel()->selectedIndexes();
QDirModel* model = (QDirModel*)ui->treeView->model();
QModelIndex index = list[0];
QFileInfo fileInfo = model->fileInfo(index);
QString selectedfilepath = fileInfo.absoluteFilePath();
qDebug() << selectedfilepath << '\n';
QSqlQuery query;
//query.exec("INSERT INTO test VALUES('','sss','sss')");
//query.exec("SELECT * FROM test");
QString selectedfromdb = "SELECT absdirectory FROM test WHERE symlinkdirectory = '" + selectedfilepath + "'";
query.exec(selectedfromdb);
query.next();
QString selectedasbd = query.value(0).toString();
qDebug() << selectedasbd << "\n";
FILE *pFile; //文件指针
Mp3Info song;
QByteArray ba = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
const char *dirnow = ba.data();
//printf("%s\n",dirnow);
pFile = fopen(dirnow, "wb");
fseek(pFile, -125, SEEK_END);
int i = 0;
char title[30];
for(i = 0;i < 30;i ++)
{
title[i] = ' ';
}
char artist[30];
for(i = 0;i < 30;i ++)
{
artist[i] = ' ';
}
char album[30];
for(i = 0;i < 30;i ++)
{
album[i] = ' ';
}
char year[4];
for(i = 0;i < 4;i ++)
{
year[i] = ' ';
}
char comment[28];
for(i = 0;i < 28;i ++)
{
comment[i] = ' ';
}
QByteArray ba1;
ba1 = ui->lineEditArtist->text().toAscii();//将所得文件名转换为字符//yfx0527
strcpy(artist,ba1.data());
ba1 = ui->lineEditTitle->text().toAscii();//将所得文件名转换为字符//yfx0527
strcpy(title,ba1.data());
ba1 = ui->lineEditAlbum->text().toAscii();//将所得文件名转换为字符//yfx0527
strcpy(album,ba1.data());
ba1 = ui->lineEditYear->text().toAscii();//将所得文件名转换为字符//yfx0527
strcpy(year,ba1.data());
ba1 = ui->lineEditComment->text().toAscii();//将所得文件名转换为字符//yfx0527
strcpy(comment,ba1.data());
char whatmm[3] = "XX";
fwrite(whatmm,sizeof(char),3,pFile);
fwrite(title,sizeof(char),30,pFile);
fwrite(artist,sizeof(char),30,pFile);
fwrite(album,sizeof(char),30,pFile);
fwrite(year,sizeof(char),4,pFile);
fwrite(comment,sizeof(char),28,pFile);
fclose(pFile);
}
示例8: on_pushButtonrefresh_clicked
void Widget::on_pushButtonrefresh_clicked()
{
QDirModel *model = new QDirModel;
ui->treeView->setModel(model);
ui->treeView->setRootIndex(model->index(ui->lineEditmubiaomulu->text() + "/mp3"));
}
示例9: itemActivated
void TemplateDialog::itemActivated(const QModelIndex & index)
{
QDirModel * model = qobject_cast<QDirModel*>(treeView->model());
if (model && !model->isDir(index))
accept();
}