本文整理汇总了C++中TreeModel::index方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeModel::index方法的具体用法?C++ TreeModel::index怎么用?C++ TreeModel::index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeModel
的用法示例。
在下文中一共展示了TreeModel::index方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
}
示例2: preview
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);
}
示例3: changeSameColumn
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);
}
示例4: parentCurrentIndex
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);
}
示例5: parentCurrentIndex
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);
QCOMPARE(view.createdColumns[0]->currentIndex(), first);
QCOMPARE(view.createdColumns[1]->currentIndex(), second);
QCOMPARE(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);
QTRY_COMPARE(view.createdColumns[2]->currentIndex(), third);
}
示例6: scrollTo
void tst_QColumnView::scrollTo()
{
QFETCH(bool, reverse);
QFETCH(bool, giveFocus);
if (reverse)
qApp->setLayoutDirection(Qt::RightToLeft);
ColumnView view;
view.resize(200, 200);
view.show();
view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible);
QCOMPARE(view.HorizontalOffset(), 0);
TreeModel model;
view.setModel(&model);
view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible);
QModelIndex home;
home = model.index(0, 0, home);
home = model.index(0, 0, home);
home = model.index(0, 0, home);
view.scrollTo(home, QAbstractItemView::EnsureVisible);
QModelIndex homeFile = model.index(0, 0, home);
view.setRootIndex(home);
QModelIndex index = model.index(0, 0, home);
view.scrollTo(index, QAbstractItemView::EnsureVisible);
QCOMPARE(view.HorizontalOffset(), 0);
// Embedded requires that at least one widget have focus
QWidget w;
w.show();
if (giveFocus)
view.setFocus(Qt::OtherFocusReason);
else
view.clearFocus();
QTRY_COMPARE(view.hasFocus(), giveFocus);
// scroll to the right
int level = 0;
int last = view.HorizontalOffset();
while(model.hasChildren(index) && level < 5) {
view.setCurrentIndex(index);
QTest::qWait(ANIMATION_DELAY);
view.scrollTo(index, QAbstractItemView::EnsureVisible);
QTest::qWait(ANIMATION_DELAY);
qApp->processEvents();
index = model.index(0, 0, index);
level++;
if (level >= 2) {
if (!reverse) {
QTRY_VERIFY(view.HorizontalOffset() < 0);
QTRY_VERIFY(last > view.HorizontalOffset());
} else {
QTRY_VERIFY(view.HorizontalOffset() > 0);
QTRY_VERIFY(last < view.HorizontalOffset());
}
}
last = view.HorizontalOffset();
}
// scroll to the left
int start = level;
while(index.parent().isValid() && index != view.rootIndex()) {
view.setCurrentIndex(index);
QTest::qWait(ANIMATION_DELAY);
view.scrollTo(index, QAbstractItemView::EnsureVisible);
index = index.parent();
if (start != level) {
if (!reverse)
QTRY_VERIFY(last < view.HorizontalOffset());
else
QTRY_VERIFY(last > view.HorizontalOffset());
}
level--;
last = view.HorizontalOffset();
}
// It shouldn't automatically steal focus if it doesn't have it
QTRY_COMPARE(view.hasFocus(), giveFocus);
// Try scrolling to something that is above the root index
home = model.index(0, 0, QModelIndex());
QModelIndex temp = model.index(1, 0, home);
home = model.index(0, 0, home);
home = model.index(0, 0, home);
view.setRootIndex(home);
view.scrollTo(model.index(0, 0, home));
QTest::qWait(ANIMATION_DELAY);
view.scrollTo(temp);
}
示例7: rootIndex
void tst_QColumnView::rootIndex()
{
ColumnView view;
// no model
view.setRootIndex(QModelIndex());
TreeModel model;
view.setModel(&model);
// A top level index
QModelIndex drive = model.firstLevel();
QVERIFY(view.visualRect(drive).isValid());
view.setRootIndex(QModelIndex());
QCOMPARE(view.HorizontalOffset(), 0);
QCOMPARE(view.rootIndex(), QModelIndex());
QVERIFY(view.visualRect(drive).isValid());
// A item under the rootIndex exists
QModelIndex home = model.thirdLevel();
QModelIndex homeFile = model.index(0, 0, home);
int i = 0;
while (i < model.rowCount(home) - 1 && !model.hasChildren(homeFile))
homeFile = model.index(++i, 0, home);
view.setRootIndex(home);
QCOMPARE(view.HorizontalOffset(), 0);
QCOMPARE(view.rootIndex(), home);
QVERIFY(!view.visualRect(drive).isValid());
QVERIFY(!view.visualRect(home).isValid());
if (homeFile.isValid())
QVERIFY(view.visualRect(homeFile).isValid());
// set root when there already is one and everything should still be ok
view.setRootIndex(home);
view.setCurrentIndex(homeFile);
view.scrollTo(model.index(0,0, homeFile));
QCOMPARE(view.HorizontalOffset(), 0);
QCOMPARE(view.rootIndex(), home);
QVERIFY(!view.visualRect(drive).isValid());
QVERIFY(!view.visualRect(home).isValid());
if (homeFile.isValid())
QVERIFY(view.visualRect(homeFile).isValid());
//
homeFile = model.thirdLevel();
home = homeFile.parent();
view.setRootIndex(home);
view.setCurrentIndex(homeFile);
view.show();
i = 0;
QModelIndex two = model.index(0, 0, homeFile);
while (i < model.rowCount(homeFile) - 1 && !model.hasChildren(two))
two = model.index(++i, 0, homeFile);
qApp->processEvents();
QTest::qWait(ANIMATION_DELAY);
view.setCurrentIndex(two);
view.scrollTo(two);
QTest::qWait(ANIMATION_DELAY);
qApp->processEvents();
QVERIFY(two.isValid());
QVERIFY(view.HorizontalOffset() != 0);
view.setRootIndex(homeFile);
QCOMPARE(view.HorizontalOffset(), 0);
}