void TreeViewWidget::addObjects(openstudio::IddObjectType type)
{
  if(type == openstudio::IddObjectType::UserCustom){
    return;
  }

  QModelIndexList rowList;
  if(mTreeView->getSelectedRows(rowList)){
    mTreeView->expand(rowList.at(0));
    openstudio::Handle handle = mTreeModel->modelAtIndex(rowList.at(0))->handle();
    TreeModel * model = static_cast<TreeModel *>(mTreeView->model());
    model->addRows(rowList,type);
    loadModel();

    ///! TODO this is a hack to get all indexes on all tree nodes
    expandAllNodes();
    QModelIndex index;
    QModelIndexList persistentIndexList = mTreeModel->getPersistentIndexList();

    for(int i=0; i<persistentIndexList.size(); i++){
      index = persistentIndexList.at(i);
      if(index.isValid()){
        if(mTreeModel->modelAtIndex(index)->handle() == handle){
          mTreeView->setCurrentIndex(index);
          break;
        }
      }
    }

    emit modelDirty();
  }
}
Exemple #2
0
void ProjectsTree::setCurrent(int id)
{
    if (id) {
	current_project_id = id;
        updateActions();  //
	TreeModel *model = (TreeModel *)view->model();
	TreeItem *item = model->getItem(id);

        if (item) {
	    statusBar()->showMessage(tr("Long.name.%1").arg(item->getName()));
#if defined TRAYPROJECT
	    trayIcon->showMessage("Change", item->getName());
#endif
	} else {
	    statusBar()->showMessage(tr("Bad Project: (%1)").arg(id));
	}
	for (int i = 0; i < recent_projects.size(); ++i) {
	    if (recent_projects[i] == id) {
	        recent_projects.removeAt(i);
	    }
	}
	recent_projects.append(id);
	while (recent_projects.size() > 10) {
            recent_projects.removeFirst();
	}
	redrawRecentMenu();
    } else {
	statusBar()->showMessage(tr("No Project: (%1)").arg(id));
    }
}
Exemple #3
0
void MetaEditor::moveRowDown()
{
    QModelIndex index = view->selectionModel()->currentIndex();
    TreeModel *model = qobject_cast<TreeModel *>(view->model());
    if (model->moveRowDown(index.row(), index.parent()))
        updateActions();
}
Exemple #4
0
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::collection_ptr& collection )
{
    m_currentCollection = collection;

    TreeView* view;
    if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() )
    {
        view = new TreeView();
        view->proxyModel()->setStyle( PlayableProxyModel::Collection );
        TreeModel* model = new TreeModel();
        view->setTreeModel( model );

        if ( collection && collection->source()->isLocal() )
            view->setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) );
        else
            view->setEmptyTip( tr( "This collection is empty." ) );

        model->addCollection( collection );

        m_treeViews.insert( collection, view );
    }
    else
    {
        view = m_treeViews.value( collection ).data();
    }

    setPage( view );
    return view;
}
Exemple #5
0
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::collection_ptr& collection )
{
    m_currentCollection = collection;

    TreeWidget* widget;
    if ( !m_treeWidgets.contains( collection ) || m_treeWidgets.value( collection ).isNull() )
    {
        widget = new TreeWidget();
        widget->view()->proxyModel()->setStyle( PlayableProxyModel::Collection );
        TreeModel* model = new TreeModel();
        widget->view()->setTreeModel( model );

        if ( !collection.isNull() )
            widget->view()->setEmptyTip( collection->emptyText() );

        model->addCollection( collection );

        m_treeWidgets.insert( collection, widget );
    }
    else
    {
        widget = m_treeWidgets.value( collection ).data();
    }

    setPage( widget );
    return widget;
}
Exemple #6
0
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::collection_ptr& collection )
{
    m_currentCollection = collection;

    FlexibleTreeView* view;
    if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() )
    {
        view = new FlexibleTreeView();

        view->columnView()->proxyModel()->setStyle( PlayableProxyModel::Collection );
        TreeModel* model = new TreeModel();

        view->setTreeModel( model );

        model->addCollection( collection );
        setPage( view );

        if ( !collection.isNull() )
            view->setEmptyTip( collection->emptyText() );

        m_collectionViews.insert( collection, view );
    }
    else
    {
        view = m_collectionViews.value( collection ).data();
    }
    view->restoreViewMode();

    setPage( view );
    return view;
}
void tst_QColumnView::moveGrip()
{
    QFETCH(bool, reverse);
    if (reverse)
        qApp->setLayoutDirection(Qt::RightToLeft);
    ColumnView view;
    TreeModel model;
    view.setModel(&model);
    QModelIndex home = model.thirdLevel();
    view.setCurrentIndex(home);
    view.resize(640, 200);
    view.show();
    QTest::qWait(ANIMATION_DELAY);

    int columnNum = view.createdColumns.count() - 2;
    QVERIFY(columnNum >= 0);
    QObjectList list = view.createdColumns[columnNum]->children();
    QColumnViewGrip *grip = 0;
    for (int i = 0; i < list.count(); ++i) {
        if ((grip = qobject_cast<QColumnViewGrip *>(list[i]))) {
            break;
        }
    }
    if (!grip)
        return;

    QAbstractItemView *column = qobject_cast<QAbstractItemView *>(grip->parent());
    int oldX = column->width();
    QCOMPARE(view.columnWidths()[columnNum], oldX);
    grip->moveGrip(10);
    QCOMPARE(view.columnWidths()[columnNum], (oldX + (reverse ? -10 : 10)));
}
Exemple #8
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi(this);

    QStringList headers;
    headers << tr("Title") << tr("Description");

    QFile file(":/default.txt");
    file.open(QIODevice::ReadOnly);
    TreeModel *model = new TreeModel(headers, file.readAll());
    file.close();

    view->setModel(model);
    for (int column = 0; column < model->columnCount(); ++column)
        view->resizeColumnToContents(column);

    connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));

    connect(view->selectionModel(),
            SIGNAL(selectionChanged(const QItemSelection &,
                                    const QItemSelection &)),
            this, SLOT(updateActions()));

    connect(actionsMenu, SIGNAL(aboutToShow()), this, SLOT(updateActions()));
    connect(insertRowAction, SIGNAL(triggered()), this, SLOT(insertRow()));
    connect(insertColumnAction, SIGNAL(triggered()), this, SLOT(insertColumn()));
    connect(removeRowAction, SIGNAL(triggered()), this, SLOT(removeRow()));
    connect(removeColumnAction, SIGNAL(triggered()), this, SLOT(removeColumn()));
    connect(insertChildAction, SIGNAL(triggered()), this, SLOT(insertChild()));

    updateActions();
}
Exemple #9
0
void tst_TreeModel::testIteration()
{
    TreeModel<> m;
    TreeItem *r = m.rootItem();
    TreeItem *group0 = createItem("group0");
    TreeItem *group1 = createItem("group1");
    TreeItem *item10 = createItem("item10");
    TreeItem *item11 = createItem("item11");
    TreeItem *item12 = createItem("item12");
    group1->appendChild(item10);
    group1->appendChild(item11);
    TreeItem *group2 = createItem("group2");
    TreeItem *item20 = createItem("item20");
    TreeItem *item21 = createItem("item21");
    TreeItem *item22 = createItem("item22");
    r->appendChild(group0);
    r->appendChild(group1);
    r->appendChild(group2);
    group1->appendChild(item12);
    group2->appendChild(item20);
    group2->appendChild(item21);
    group2->appendChild(item22);

    QCOMPARE(r->childCount(), 3);
    QCOMPARE(countLevelItems(r, 1), 3);
    QCOMPARE(countLevelItems(r, 2), 6);
    QCOMPARE(countLevelItems(r, 3), 0);
    QCOMPARE(countLevelItems(group0, 1), 0);
    QCOMPARE(countLevelItems(group1, 1), 3);
    QCOMPARE(countLevelItems(group1, 2), 0);
    QCOMPARE(countLevelItems(group2, 1), 3);
    QCOMPARE(countLevelItems(group2, 2), 0);
}
void
CollectionViewPage::onCollectionChanged()
{
    TreeModel* model = new TreeModel();
    PlayableModel* flatModel = new PlayableModel();
    PlayableModel* albumModel = new PlayableModel();

    setTreeModel( model );
    setFlatModel( flatModel );
    setAlbumModel( albumModel );

    model->addCollection( m_collection );
    flatModel->appendTracks( m_collection );
    albumModel->appendAlbums( m_collection );

    if ( m_collection && m_collection->source() && m_collection->source()->isLocal() )
    {
        setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) );
    }
    else
        setEmptyTip( tr( "This collection is empty." ) );

    if ( m_collection.objectCast<ScriptCollection>() )
        m_trackView->setEmptyTip( tr( "Cloud collections aren't supported in the flat view yet. We will have them covered soon. Switch to another view to navigate them." ) );
}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    a.setOrganizationName("CodeRush");
    a.setOrganizationDomain("coderush.me");
    a.setApplicationName("UEFIExtract");

    if (a.arguments().length() > 32) {
        std::cout << "Too many arguments" << std::endl;
        return 1;
    }

    if (a.arguments().length() > 1) {
        QString path = a.arguments().at(1);
        QFileInfo fileInfo(path);
        if (!fileInfo.exists())
            return ERR_FILE_OPEN;

        QFile inputFile;
        inputFile.setFileName(path);
        if (!inputFile.open(QFile::ReadOnly))
            return ERR_FILE_OPEN;

        QByteArray buffer = inputFile.readAll();
        inputFile.close();

        TreeModel model;
        FfsParser ffsParser(&model);
        STATUS result = ffsParser.parse(buffer);
        if (result)
            return result;

        std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
        for (size_t i = 0; i < messages.size(); i++) {
            std::cout << messages[i].first.toLatin1().constData() << std::endl;
        }

        FfsDumper ffsDumper(&model);

        if (a.arguments().length() == 2) {
            return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != ERR_SUCCESS);
        }
        else {
            UINT32 returned = 0;
            for (int i = 2; i < a.arguments().length(); i++) {
                result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), a.arguments().at(i));
                if (result)
                    returned |= (1 << (i - 1));
            }
            return returned;
        }
    }
    else {
        std::cout << "UEFIExtract 0.10.8" << std::endl << std::endl
                  << "Usage: UEFIExtract imagefile [FileGUID_1 FileGUID_2 ... FileGUID_31]" << std::endl
                  << "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise" << std::endl;
        return 1;
    }
}
Exemple #12
0
MetaEditor::MetaEditor(QWidget *parent)
  : QDialog(parent),
    m_mainWindow(qobject_cast<MainWindow *>(parent)),
    m_Relator(MarcRelators::instance()),
    m_RemoveRow(new QShortcut(QKeySequence(Qt::ControlModifier + Qt::Key_Delete),this, 0, 0, Qt::WidgetWithChildrenShortcut))
{
    setupUi(this);

    m_book = m_mainWindow->GetCurrentBook();
    m_version = m_book->GetConstOPF()->GetEpubVersion();
    m_opfdata = m_book->GetOPF()->GetText();

    QStringList headers;
    headers << tr("Name") << tr("Value");

    QString data = GetOPFMetadata();

    TreeModel *model = new TreeModel(headers, data);
    view->setModel(model);
    for (int column = 0; column < model->columnCount(); ++column)
        view->resizeColumnToContents(column);

    if (!isVisible()) {
        ReadSettings();
    }

    if (m_version.startsWith('3')) { 
        loadMetadataElements();
        loadMetadataProperties();
    } else {
        loadE2MetadataElements();
        loadE2MetadataProperties();
    }

    connect(view->selectionModel(),
            SIGNAL(selectionChanged(const QItemSelection &,
                                    const QItemSelection &)),
            this, SLOT(updateActions()));

    connect(delButton, SIGNAL(clicked()), this, SLOT(removeRow()));
    connect(tbMoveUp, SIGNAL(clicked()), this, SLOT(moveRowUp()));
    connect(tbMoveDown, SIGNAL(clicked()), this, SLOT(moveRowDown()));
    connect(m_RemoveRow, SIGNAL(activated()), this, SLOT(removeRow()));

    if (m_version.startsWith('3')) {
        connect(addMetaButton, SIGNAL(clicked()), this, SLOT(selectElement()));
        connect(addPropButton, SIGNAL(clicked()), this, SLOT(selectProperty()));
    } else {
        connect(addMetaButton, SIGNAL(clicked()), this, SLOT(selectE2Element()));
        connect(addPropButton, SIGNAL(clicked()), this, SLOT(selectE2Property()));
    }

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveData()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    updateActions();
}
void TreeViewWidget::copyObjects()
{
  mModelObjectsToPaste.clear();
  QModelIndexList rowList;
  if(mTreeView->getSelectedRows(rowList)){
    TreeModel * model = static_cast<TreeModel *>(mTreeView->model());
    BOOST_FOREACH(const QModelIndex& row, rowList){
      mModelObjectsToPaste.push_back(*(model->modelAtIndex(row)));
    }
Exemple #14
0
void ProjectsTree::exposeCurrentProject()
{
    TreeModel *model = view->model();

    const QModelIndex &item = model->getCurrentIndex();

    show();

    view->scrollTo(item, QAbstractItemView::PositionAtCenter);
}
Exemple #15
0
void MetaEditor::saveData()
{
    WriteSettings();

    TreeModel *model = qobject_cast<TreeModel *>(view->model());
    QString data = model->getAllModelData();

    QString newopfdata = SetNewOPFMetadata(data);
    m_book->GetOPF()->SetText(newopfdata);
    QDialog::accept();
}
Exemple #16
0
void UEFITool::insert(const UINT8 mode)
{
    QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
    if (!index.isValid())
        return;

    TreeModel* model = ffsEngine->treeModel();
    UINT8 type;

    if (mode == CREATE_MODE_BEFORE || mode == CREATE_MODE_AFTER)
        type = model->type(index.parent());
    else
        type = model->type(index);

    QString path;
    switch (type) {
    case Types::Volume:
        path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"), currentDir, "FFS files (*.ffs *.bin);;All files (*.*)");
        break;
    case Types::File:
    case Types::Section:
        path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"), currentDir, "Section files (*.sct *.bin);;All files (*.*)");
        break;
    default:
        return;
    }

    if (path.trimmed().isEmpty())
        return;

    QFileInfo fileInfo = QFileInfo(path);
    if (!fileInfo.exists()) {
        ui->statusBar->showMessage(tr("Please select existing file"));
        return;
    }

    QFile inputFile;
    inputFile.setFileName(path);

    if (!inputFile.open(QFile::ReadOnly)) {
        QMessageBox::critical(this, tr("Insertion failed"), tr("Can't open output file for reading"), QMessageBox::Ok);
        return;
    }

    QByteArray buffer = inputFile.readAll();
    inputFile.close();

    UINT8 result = ffsEngine->insert(index, buffer, mode);
    if (result) {
        QMessageBox::critical(this, tr("Insertion failed"), errorMessage(result), QMessageBox::Ok);
        return;
    }
    ui->actionSaveImageFile->setEnabled(true);
}
void TreeViewWidget::removeObjects()
{
  QModelIndexList rowList;
  if(mTreeView->getSelectedRows(rowList)){
    std::vector<openstudio::Handle> handles;
    TreeModel * model = static_cast<TreeModel *>(mTreeView->model());
    model->removeRows(rowList,handles);
    if(!handles.empty()){
      loadModel();
      emit modelDirty();
    }
  }
}
Exemple #18
0
void TestResultView::displayTestResult(const TestResult *const result)
{
    if(!result)
    {
        displayNone();
        return;
    }

    /* ------- the Test Status Label --------- */
    resultStatus->setText(result->status() ? TestResult::displayName(result->status())
                                           : QLatin1String("Not Applicable"));
    /* --------------------------------------- */

    /* ------------ the AST View ------------- */
    ASTItem *astTree = result->astTree();
    static_cast<TreeModel *>(astView->model())->setRoot(astTree);
    /* --------------------------------------- */

    /* ------- the Error code/msg View ------- */
    ErrorItem *msgRoot = new ErrorItem(ErrorHandler::Message(), 0);

    const ErrorHandler::Message::List msgs(result->messages());
    ErrorHandler::Message::List::const_iterator it(msgs.constBegin());
    const ErrorHandler::Message::List::const_iterator end(msgs.constEnd());

    for(; it != end; ++it)
        msgRoot->appendChild(new ErrorItem(*it, msgRoot));

    TreeModel *etm = static_cast<TreeModel *>(messageOutput->model());
    etm->setRoot(msgRoot);
    /* --------------------------------------- */

    const QPatternist::Item::List items(result->items());
    /* ----- the Serialized Output View ------ */
    serializedResult->setPlainText(result->asSerialized());
    /* --------------------------------------- */

    /* ------ the Item List Output View ------ */
    XDTItemItem *itemRoot = new XDTItemItem(QPatternist::Item(), 0);
    QPatternist::Item item;

    QPatternist::Item::List::const_iterator itemIt(items.constBegin());
    const QPatternist::Item::List::const_iterator itemsEnd(items.constEnd());

    for(; itemIt != itemsEnd; ++itemIt)
        itemRoot->appendChild(new XDTItemItem(*itemIt, itemRoot));

    TreeModel *itm = static_cast<TreeModel *>(itemListResult->model());
    itm->setRoot(itemRoot);
    /* --------------------------------------- */
}
void TreeModelBase::execSyncV(      FieldContainer    &oFrom,
                                        ConstFieldMaskArg  whichField,
                                        AspectOffsetStore &oOffsets,
                                        ConstFieldMaskArg  syncMode,
                                  const UInt32             uiSyncInfo)
{
    TreeModel *pThis = static_cast<TreeModel *>(this);

    pThis->execSync(static_cast<TreeModel *>(&oFrom),
                    whichField,
                    oOffsets,
                    syncMode,
                    uiSyncInfo);
}
void tst_QColumnView::pullRug()
{
    QFETCH(bool, removeModel);
    ColumnView view;
    TreeModel model;
    view.setModel(&model);
    QModelIndex home = model.thirdLevel();
    view.setCurrentIndex(home);
    if (removeModel)
        view.setModel(0);
    else
        view.setCurrentIndex(QModelIndex());
    QTest::qWait(ANIMATION_DELAY);
    // don't crash
}
Exemple #21
0
void UEFITool::populateUi(const QModelIndex &current)
{
    if (!current.isValid())
        return;

    TreeModel* model = ffsEngine->treeModel();
    UINT8 type = model->type(current);
    UINT8 subtype =  model->subtype(current);

    // Set info text
    ui->infoEdit->setPlainText(model->info(current));

    // Enable menus
    ui->menuCapsuleActions->setEnabled(type == Capsule);
    ui->menuImageActions->setEnabled(type == Image);
    ui->menuRegionActions->setEnabled(type == Region);
    ui->menuPaddingActions->setEnabled(type == Padding);
    ui->menuVolumeActions->setEnabled(type == Volume);
    ui->menuFileActions->setEnabled(type == File);
    ui->menuSectionActions->setEnabled(type == Section);

    // Enable actions
    ui->actionExtract->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current) && model->hasEmptyTail(current));
    ui->actionRebuild->setEnabled(type == Volume || type == File || type == Section);
    ui->actionExtractBody->setDisabled(model->hasEmptyHeader(current));
    ui->actionRemove->setEnabled(type == Volume || type == File || type == Section);
    ui->actionInsertInto->setEnabled((type == Volume && subtype != UnknownVolume) || 
        (type == File && subtype != EFI_FV_FILETYPE_ALL && subtype != EFI_FV_FILETYPE_RAW && subtype != EFI_FV_FILETYPE_PAD) ||
        (type == Section && (subtype == EFI_SECTION_COMPRESSION || subtype == EFI_SECTION_GUID_DEFINED || subtype == EFI_SECTION_DISPOSABLE)));
    ui->actionInsertBefore->setEnabled(type == File || type == Section);
    ui->actionInsertAfter->setEnabled(type == File || type == Section);
    ui->actionReplace->setEnabled((type == Region && subtype != DescriptorRegion) || type == File || type == Section);
    ui->actionReplaceBody->setEnabled(type == File || type == Section);
}
Exemple #22
0
void tst_TreeModel::testMixed()
{
    TreeModel<TreeItem, ItemA, ItemB> m;
    TreeItem *r = m.rootItem();
    TreeItem *ra;
    r->appendChild(new ItemA);
    r->appendChild(ra = new ItemA);
    ra->appendChild(new ItemB);
    ra->appendChild(new ItemB);

    int n = 0;
    m.forItemsAtLevel<1>([&n](ItemA *) { ++n; });
    QCOMPARE(n, 2);

    n = 0;
    m.forItemsAtLevel<2>([&n](ItemB *) { ++n; });
    QCOMPARE(n, 2);
}
void tst_QColumnView::scrollContentsBy()
{
    QFETCH(bool, reverse);
    if (reverse)
        qApp->setLayoutDirection(Qt::RightToLeft);
    ColumnView view;
    view.ScrollContentsBy(-1, -1);
    view.ScrollContentsBy(0, 0);

    TreeModel model;
    view.setModel(&model);
    view.ScrollContentsBy(0, 0);

    QModelIndex home = model.thirdLevel();
    view.setCurrentIndex(home);
    QTest::qWait(ANIMATION_DELAY);
    view.ScrollContentsBy(0, 0);
}
Exemple #24
0
void TestResultView::displayNone()
{
    TreeModel *tm;

    tm = static_cast<TreeModel *>(astView->model());
    Q_ASSERT(tm);
    tm->setRoot(0);

    tm = static_cast<TreeModel *>(messageOutput->model());
    Q_ASSERT(tm);
    tm->setRoot(0);

    tm = static_cast<TreeModel *>(itemListResult->model());
    Q_ASSERT(tm);
    tm->setRoot(0);

    serializedResult->clear();
    resultStatus->clear();
}
Exemple #25
0
void UEFITool::contextMenuEvent(QContextMenuEvent* event)
{
    if (ui->messageListWidget->underMouse()) {
        ui->menuMessages->exec(event->globalPos());
        return;
    }

    if(!ui->structureTreeView->underMouse())
        return;

    QPoint pt = event->pos();
    QModelIndex index = ui->structureTreeView->indexAt(ui->structureTreeView->viewport()->mapFrom(this, pt));
    if(!index.isValid())
        return;

    TreeModel* model = ffsEngine->treeModel();
    switch(model->type(index))
    {
    case Capsule:
        ui->menuCapsuleActions->exec(event->globalPos());
        break;
    case Image:
        ui->menuImageActions->exec(event->globalPos());
        break;
    case Region:
        ui->menuRegionActions->exec(event->globalPos());
        break;
    case Padding:
        ui->menuPaddingActions->exec(event->globalPos());
        break;
    case Volume:
        ui->menuVolumeActions->exec(event->globalPos());
        break;
    case File:
        ui->menuFileActions->exec(event->globalPos());
        break;
    case Section:
        ui->menuSectionActions->exec(event->globalPos());
        break;
    }
}
void
CollectionViewPage::onCollectionChanged()
{
    TreeModel* model = new TreeModel();
    PlayableModel* flatModel = new PlayableModel();
    PlayableModel* albumModel = new PlayableModel();

    setTreeModel( model );
    setFlatModel( flatModel );
    setAlbumModel( albumModel );

    model->addCollection( m_collection );
    flatModel->appendTracks( m_collection );
    albumModel->appendAlbums( m_collection );

    if ( m_collection && m_collection->isLocal() )
    {
        setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) );
    }
    else
        setEmptyTip( tr( "This collection is empty." ) );
}
int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	qRegisterMetaType<TreeModel>("TreeModel");
	qRegisterMetaType<MetaModel>("TreeItem");
	qRegisterMetaType<MetaModel>("MetaModel");
	qRegisterMetaType<UndoManager>("UndoManager");
	qmlRegisterType<DataContainer>("org.libelektra.qtgui", 1, 0, "DataContainer");

	QQmlApplicationEngine engine;
	QQmlContext* ctxt = engine.rootContext();

	TreeModel model;
	NoLeavesProxyModel treeFilter;
	OnlyLeavesProxyModel tableFilter;
	UndoManager manager;

	treeFilter.setSourceModel(&model);
	tableFilter.setSourceModel(&model);

	engine.setObjectOwnership(&treeFilter, QQmlApplicationEngine::CppOwnership);
	engine.setObjectOwnership(&tableFilter, QQmlApplicationEngine::CppOwnership);

	ctxt->setContextProperty("treeModel", &model);
	ctxt->setContextProperty("noLeavesProxyModel", &treeFilter);
	ctxt->setContextProperty("onlyLeavesProxyModel", &tableFilter);
	ctxt->setContextProperty("undoManager", &manager);

	model.populateModel();

	new ModelTest(&model);
	new ModelTest(&treeFilter);
	new ModelTest(&tableFilter);

	engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

	return app.exec();
}
void tst_QColumnView::changeSameColumn()
{
    ColumnView view;
    TreeModel model;
    view.setModel(&model);
    QModelIndex second;

    QModelIndex home = model.secondLevel();
    //index(QDir::homePath());
    view.setCurrentIndex(home);
    for (int i = 0; i < model.rowCount(home.parent()); ++i) {
        QModelIndex idx = model.index(i, 0, home.parent());
        if (model.hasChildren(idx) && idx != home) {
            second = idx;
            break;
        }
    }
    QVERIFY(second.isValid());

    QList<QPointer<QAbstractItemView> > old = view.createdColumns;
    view.setCurrentIndex(second);

    QCOMPARE(old, view.createdColumns);
}
Exemple #29
0
void tst_QColumnView::parentCurrentIndex()
{
    QFETCH(int, firstRow);
    QFETCH(int, secondRow);

    ColumnView view;
    TreeModel model;
    view.setModel(&model);
    view.show();

    QModelIndex first;
    QModelIndex second;
    QModelIndex third;
    first = model.index(0, 0, QModelIndex());
    second = model.index(firstRow, 0, first);
    third = model.index(0, 0, second);
    QVERIFY(first.isValid());
    QVERIFY(second.isValid());
    QVERIFY(third.isValid());
    view.setCurrentIndex(third);
    QTest::qWait(ANIMATION_DELAY);
    QTRY_COMPARE(view.createdColumns[0]->currentIndex(), first);
    QTRY_COMPARE(view.createdColumns[1]->currentIndex(), second);
    QTRY_COMPARE(view.createdColumns[2]->currentIndex(), third);

    first = model.index(0, 0, QModelIndex());
    second = model.index(secondRow, 0, first);
    third = model.index(0, 0, second);
    QVERIFY(first.isValid());
    QVERIFY(second.isValid());
    QVERIFY(third.isValid());
    view.setCurrentIndex(third);
    QTest::qWait(ANIMATION_DELAY);
    QTRY_COMPARE(view.createdColumns[0]->currentIndex(), first);
    QTRY_COMPARE(view.createdColumns[1]->currentIndex(), second);

    // The next two lines should be removed when QTBUG-22707 is resolved.
    QEXPECT_FAIL("", "QTBUG-22707", Abort);
    QVERIFY(view.createdColumns[2]);

    QTRY_COMPARE(view.createdColumns[2]->currentIndex(), third);
}
void tst_QColumnView::preview()
{
    QColumnView view;
    QCOMPARE(view.previewWidget(), (QWidget*)0);
    TreeModel model;
    view.setModel(&model);
    QCOMPARE(view.previewWidget(), (QWidget*)0);
    QModelIndex home = model.index(0, 0);
    QVERIFY(home.isValid());
    QVERIFY(model.hasChildren(home));
    view.setCurrentIndex(home);
    QCOMPARE(view.previewWidget(), (QWidget*)0);

    QModelIndex file;
    QVERIFY(model.rowCount(home) > 0);
    for (int i = 0; i < model.rowCount(home); ++i) {
        if (!model.hasChildren(model.index(i, 0, home))) {
            file = model.index(i, 0, home);
            break;
        }
    }
    QVERIFY(file.isValid());
    view.setCurrentIndex(file);
    QVERIFY(view.previewWidget() != (QWidget*)0);

    QWidget *previewWidget = new QWidget(&view);
    view.setPreviewWidget(previewWidget);
    QCOMPARE(view.previewWidget(), previewWidget);
    QVERIFY(previewWidget->parent() != ((QWidget*)&view));
    view.setCurrentIndex(home);

    // previewWidget should be marked for deletion
    QWidget *previewWidget2 = new QWidget(&view);
    view.setPreviewWidget(previewWidget2);
    QCOMPARE(view.previewWidget(), previewWidget2);
}