Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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());
}
Ejemplo n.º 3
0
//! [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();
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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()));
}
Ejemplo n.º 6
0
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());
    }
}
Ejemplo n.º 7
0
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()));
}
Ejemplo n.º 8
0
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);
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
void tst_QDirModel::fileName()
{
    QDirModel model;

    QFETCH(QString, path);
    QFETCH(QString, result);
    QCOMPARE(model.fileName(model.index(path)), result);
}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
0
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;
        }
    }
}
Ejemplo n.º 13
0
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));
}
Ejemplo n.º 14
0
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出来,进入程序的事件循环就好了

}
Ejemplo n.º 15
0
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
	}
Ejemplo n.º 16
0
void tst_QDirModel::hidden()
{
#ifndef Q_OS_UNIX
    QSKIP("Test not implemented on non-Unixes");
#else
    QDir current;
    current.mkdir(".qtest_hidden");

    QDirModel model;
    QModelIndex index = model.index(QDir::currentPath() + "/.qtest_hidden");
    //QVERIFY(!index.isValid()); // hidden items are not listed, but if you specify a valid path, it will give a valid index

    current.mkdir(".qtest_hidden/qtest_visible");
    QModelIndex index2 = model.index(QDir::currentPath() + "/.qtest_hidden/qtest_visible");
    QVERIFY(index2.isValid());

    QDirModel model2;
    model2.setFilter(model2.filter() | QDir::Hidden);
    index = model2.index(QDir::currentPath() + "/.qtest_hidden");
    QVERIFY(index.isValid());
#endif
}
Ejemplo n.º 17
0
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));
}
Ejemplo n.º 18
0
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()));
}
Ejemplo n.º 19
0
DNetLoad::DNetLoad(QWidget *parent) :
    QDialog(parent)
{
    showMaximized();

    label=new QLabel(this);
    textBrowser=new QTextBrowser();
    loadBtn=new QPushButton("下载");
    tree=new QTreeWidget();
    rootTree=new QTreeView();
    progressBar=new QProgressBar();

    QStringList list;
    list<<"name"<<"size"<<"owner"<<"group"<<"date";
    tree->setHeaderLabels(list);
    tree->setColumnWidth(0,250);

    QDirModel *model = new QDirModel;
    rootTree->setModel(model);
    rootTree->setRootIndex(model->index("/"));
    rootTree->show();
    rootTree->setColumnWidth(0,300);


    QGridLayout *layout=new QGridLayout();
    layout->addWidget(tree,0,0,10,1);
    layout->addWidget(rootTree,0,1,18,1);
    layout->addWidget(loadBtn,10,0,1,1);
    layout->addWidget(textBrowser,11,0,5,1);
    layout->addWidget(progressBar,16,0);
    layout->addWidget(label,17,0);
    setLayout(layout);

    ftp = new QFtp(this);
    ftp->connectToHost("ftp.qt.nokia.com"); //连接到服务器
    ftp->login();   //登录
    ftp->cd("qt/source");   //跳转到“qt”目录下
    ftp->list();

    connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftpCommandStarted(int)));
    //当每条命令开始执行时发出相应的信号
    connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(ftpCommandFinished(int,bool)));
    connect(ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(addToList(QUrlInfo)));
    connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)),
            this,SLOT(progressBar_update(qint64,qint64)));

    connect(rootTree,SIGNAL(clicked(QModelIndex)),this,SLOT(rootTree_click(QModelIndex)));

    connect(loadBtn,SIGNAL(clicked()),this,SLOT(loadBtn_click()));
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget *window = new QWidget;
    QVBoxLayout *layout = new QVBoxLayout(window);
    QLabel *title = new QLabel("Some items from the directory model", window);
    title->setBackgroundRole(QPalette::Base);
    title->setMargin(8);
    layout->addWidget(title);
    
//! [0]
    QDirModel *model = new QDirModel;
    QModelIndex parentIndex = model->index(QDir::currentPath());
    int numRows = model->rowCount(parentIndex);
//! [0]

//! [1]
    for (int row = 0; row < numRows; ++row) {
        QModelIndex index = model->index(row, 0, parentIndex);
//! [1]

//! [2]
        QString text = model->data(index, Qt::DisplayRole).toString();
        // Display the text in a widget.
//! [2]

        QLabel *label = new QLabel(text, window);
        layout->addWidget(label);
//! [3]
    }
//! [3]

    window->setWindowTitle("A simple model example");
    window->show();
    return app.exec();
}
Ejemplo n.º 21
0
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");
}
Ejemplo n.º 22
0
void tst_QColumnView::resize()
{
    ColumnView view;
    QDirModel model;
    view.setModel(&model);
    view.resize(200, 200);

    view.show();
    QModelIndex home = model.index(QDir::homePath()).parent();
    view.setCurrentIndex(home);
    QTest::qWait(ANIMATION_DELAY);
    view.resize(200, 300);
    QTest::qWait(ANIMATION_DELAY);

    QVERIFY(view.horizontalScrollBar()->maximum() != 0);
    view.resize(view.horizontalScrollBar()->maximum() * 10, 300);
    QTest::qWait(ANIMATION_DELAY);
    QVERIFY(view.horizontalScrollBar()->maximum() <= 0);
}
Ejemplo n.º 23
0
void tst_QColumnView::selectedColumns()
{
    ColumnView view;
    QDirModel model;
    view.setModel(&model);
    view.resize(800,300);
    view.show();

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

    QTest::qWait(ANIMATION_DELAY);

    for (int i = 0; i < view.createdColumns.count(); ++i) {
        QAbstractItemView *column = view.createdColumns.at(i);
        if (!column)
            continue;
        if (!column->rootIndex().isValid() || column->rootIndex() == home)
            continue;
        QTRY_VERIFY(column->currentIndex().isValid());
    }
}
Ejemplo n.º 24
0
void tst_QColumnView::setSelectionModel()
{
    ColumnView view;
    QDirModel model;
    view.setModel(&model);
    view.show();

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

    QItemSelectionModel *selectionModel = new QItemSelectionModel(&model);
    view.setSelectionModel(selectionModel);

    bool found = false;
    for (int i = 0; i < view.createdColumns.count(); ++i) {
        if (view.createdColumns.at(i)->selectionModel() == selectionModel) {
            found = true;
            break;
        }
    }
    QVERIFY(found);
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
void tst_QDirModel::unreadable()
{
#ifndef Q_OS_UNIX
    QSKIP("Test not implemented on non-Unixes");
#else
    // Create an empty file which has no read permissions (file will be removed by cleanup()).
    QFile unreadableFile(QDir::currentPath() + "qtest_unreadable");
    QVERIFY2(unreadableFile.open(QIODevice::WriteOnly | QIODevice::Text), qPrintable(unreadableFile.errorString()));
    unreadableFile.close();
    QVERIFY(unreadableFile.exists());
    QVERIFY2(unreadableFile.setPermissions(QFile::WriteOwner), qPrintable(unreadableFile.errorString()));

    // Check that we can't make a valid model index from an unreadable file.
    QDirModel model;
    QModelIndex index = model.index(QDir::currentPath() + "/qtest_unreadable");
    QVERIFY(!index.isValid());

    // Check that unreadable files are not treated like hidden files.
    QDirModel model2;
    model2.setFilter(model2.filter() | QDir::Hidden);
    index = model2.index(QDir::currentPath() + "/qtest_unreadable");
    QVERIFY(!index.isValid());
#endif
}
Ejemplo n.º 27
0
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());
}
Ejemplo n.º 28
0
void Widget::on_pushButtoncreate_clicked()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("test");
    db.setUserName("root");
    db.setPassword("xtloving");
    if (!db.open())
         qDebug() << "Failed to connect to root mysql admin";
    else
         std::cout<<"succeed!"<<std::endl;

    QSqlQuery query;
    query.exec("delete from test");
    query.exec("SELECT * FROM test");

    while(query.next())
    {
        QString id = query.value(0).toString();
        QString type = query.value(1).toString();
        QString data = query.value(2).toString();
        QString sqlout = id + "\n" + type + "\n" + data;
        //ui->listWidget->addItem(sqlout);
    }


    QString change1 = ui->lineEdityuanmulu->text();
    QString change2 = ui->lineEditmubiaomulu->text() + "/mp3";
    //const char* strchange1 = change1.toAscii().constData();
    //const char* strchange2 = change2.toAscii().constData();
    QByteArray ba = change1.toLatin1();
    const char *strchange1 = ba.data();
    //const char* strchange2 = change2.toAscii().constData();
    QByteArray ba2 = change2.toLatin1();
    const char *strchange2 = ba2.data();
    scan_dir(strchange1, strchange2);
    fflush(stdout);

    /*
    char *dest = const_cast<char*>(strchange2);
    strcat(dest,"/mp3");
    fd=watch_init(MASK,dest);
    watch_mon(fd);
    */
    pid_t pid;
    if((pid=fork())<0)
        printf("Fork error!");
    else if(pid==0){
    int fd;
    char *dest = const_cast<char*>(strchange2);
    //strcat(dest,"/mp3");
    fd=watch_init(MASK,dest);
    watch_mon(fd);
    }


    //ui->lineEditmubiaomulu->setText(ui->lineEditmubiaomulu->text() + "/mp3");
    QDirModel *model = new QDirModel;
    ui->treeView->setModel(model);
    ui->treeView->setRootIndex(model->index(ui->lineEditmubiaomulu->text() + "/mp3"));

}
Ejemplo n.º 29
0
void Widget::on_pushButtonrefresh_clicked()
{
    QDirModel *model = new QDirModel;
    ui->treeView->setModel(model);
    ui->treeView->setRootIndex(model->index(ui->lineEditmubiaomulu->text() + "/mp3"));
}