|
@@ -40,40 +40,50 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
{
|
|
{
|
|
QApplication app(argc, argv);
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
-#if 0
|
|
|
|
- QFileSystemModel model;
|
|
|
|
- model.setRootPath(QDir::currentPath());
|
|
|
|
-#else
|
|
|
|
- QStandardItemModel model;
|
|
|
|
- QList<QStandardItem*> row0;
|
|
|
|
- row0 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
- row0[0]->setText("not user checkable");
|
|
|
|
- model.appendRow(row0);
|
|
|
|
- QList<QStandardItem*> row1;
|
|
|
|
- row1 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
- row1[0]->setCheckable(true);
|
|
|
|
- row1[0]->setText("checkable");
|
|
|
|
- model.appendRow(row1);
|
|
|
|
- QList<QStandardItem*> row2;
|
|
|
|
- row2 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
- row2[0]->setCheckable(true);
|
|
|
|
- row2[0]->setText("checkable");
|
|
|
|
- model.appendRow(row2);
|
|
|
|
-#endif
|
|
|
|
|
|
+ QStandardItemModel model;
|
|
|
|
+ QList<QStandardItem*> row0;
|
|
|
|
+ row0 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
+ row0[0]->setText("not user checkable");
|
|
|
|
+ model.appendRow(row0);
|
|
|
|
+ QList<QStandardItem*> row1;
|
|
|
|
+ row1 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
+ row1[0]->setCheckable(true);
|
|
|
|
+ row1[0]->setText("checkable");
|
|
|
|
+ model.appendRow(row1);
|
|
|
|
+ QList<QStandardItem*> row2;
|
|
|
|
+ row2 << new QStandardItem << new QStandardItem << new QStandardItem;
|
|
|
|
+ row2[0]->setCheckable(true);
|
|
|
|
+ row2[0]->setText("checkable");
|
|
|
|
+ model.appendRow(row2);
|
|
|
|
+
|
|
|
|
+ // items are unchecked by default
|
|
|
|
+ if (row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
|
|
+ {
|
|
|
|
+ std::cerr << "QStandardItem default failed: "
|
|
|
|
+ << static_cast<int>(row0[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row1[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row2[0]->checkState()) << std::endl;
|
|
|
|
+ return EXIT_FAILURE;
|
|
|
|
+ }
|
|
|
|
|
|
QTableView table;
|
|
QTableView table;
|
|
table.setModel(&model);
|
|
table.setModel(&model);
|
|
|
|
|
|
|
|
+ // Header is checked by default
|
|
model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);
|
|
model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);
|
|
|
|
|
|
QHeaderView* previousHeaderView = table.horizontalHeader();
|
|
QHeaderView* previousHeaderView = table.horizontalHeader();
|
|
bool oldClickable = previousHeaderView->isClickable();
|
|
bool oldClickable = previousHeaderView->isClickable();
|
|
|
|
|
|
- ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, &table);
|
|
|
|
|
|
+ ctkCheckableHeaderView* headerView =
|
|
|
|
+ new ctkCheckableHeaderView(Qt::Horizontal, &table);
|
|
headerView->setClickable(oldClickable);
|
|
headerView->setClickable(oldClickable);
|
|
headerView->setMovable(previousHeaderView->isMovable());
|
|
headerView->setMovable(previousHeaderView->isMovable());
|
|
headerView->setHighlightSections(previousHeaderView->highlightSections());
|
|
headerView->setHighlightSections(previousHeaderView->highlightSections());
|
|
- headerView->setPropagateToItems(true);
|
|
|
|
|
|
+ // propagatetoitems is true by default
|
|
|
|
+ //headerView->setPropagateToItems(true);
|
|
|
|
|
|
// sets the model to the headerview
|
|
// sets the model to the headerview
|
|
table.setHorizontalHeader(headerView);
|
|
table.setHorizontalHeader(headerView);
|
|
@@ -84,19 +94,30 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
<< headerView->isClickable() << std::endl;
|
|
<< headerView->isClickable() << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
- if (headerView->checkState(0) == Qt::Unchecked)
|
|
|
|
|
|
+ // As propagateToItems is true, once the model is set to the headerview,
|
|
|
|
+ // the checkable header is updated from the check state of all the items
|
|
|
|
+ // all the items are unchecked by default, so the header becomes unchecked
|
|
|
|
+ if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "ctkCheckableHeaderView::checkstate() failed: "
|
|
std::cerr << "ctkCheckableHeaderView::checkstate() failed: "
|
|
- << static_cast<int>(headerView->checkState(0)) << std::endl;
|
|
|
|
|
|
+ << static_cast<int>(headerView->checkState(0)) << " "
|
|
|
|
+ << static_cast<int>(row0[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row1[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row2[0]->checkState()) << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
+ // Retrieve checkstate of the header
|
|
Qt::CheckState checkstate;
|
|
Qt::CheckState checkstate;
|
|
if (!headerView->checkState(0, checkstate))
|
|
if (!headerView->checkState(0, checkstate))
|
|
{
|
|
{
|
|
std::cerr << "ctkCheckableHeaderView::checkstate() failed: "
|
|
std::cerr << "ctkCheckableHeaderView::checkstate() failed: "
|
|
- << static_cast<int>(headerView->checkState(0, checkstate)) << std::endl;
|
|
|
|
|
|
+ << static_cast<int>(checkstate) << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
+
|
|
QFocusEvent focus(QEvent::FocusIn,Qt::TabFocusReason);
|
|
QFocusEvent focus(QEvent::FocusIn,Qt::TabFocusReason);
|
|
headerView->eventFilter(headerView, &focus);
|
|
headerView->eventFilter(headerView, &focus);
|
|
|
|
|
|
@@ -113,35 +134,42 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
<< headerView->propagateToItems() << std::endl;
|
|
<< headerView->propagateToItems() << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
-
|
|
|
|
- // uncheck the header
|
|
|
|
- headerView->toggleCheckState(0);
|
|
|
|
-
|
|
|
|
- if (headerView->checkState(0) != Qt::Unchecked)
|
|
|
|
|
|
+ if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
- std::cerr << "ctkCheckableHeaderView::toggleCheckState() failed: "
|
|
|
|
- << static_cast<int>(headerView->checkState(0)) << std::endl;
|
|
|
|
|
|
+ std::cerr << "ctkCheckableHeaderView::propagateToItems() failed: "
|
|
|
|
+ << static_cast<int>(headerView->checkState(0)) << " "
|
|
|
|
+ << static_cast<int>(row0[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row1[0]->checkState()) << " "
|
|
|
|
+ << static_cast<int>(row2[0]->checkState()) << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // check the header
|
|
|
|
+ headerView->toggleCheckState(0);
|
|
|
|
+
|
|
// make sure it didn't uncheck the checkable items
|
|
// make sure it didn't uncheck the checkable items
|
|
- if (row0[0]->checkState() != Qt::Checked ||
|
|
|
|
- row1[0]->checkState() != Qt::Checked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ if (headerView->checkState(0) != Qt::Checked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
- std::cerr << "ctkCheckableHeaderView::toggleCheckState() failed: "
|
|
|
|
- << static_cast<int>(row0[0]->checkState()) << " "
|
|
|
|
|
|
+ std::cerr << __LINE__ << " ctkCheckableHeaderView::toggleCheckState() failed: "
|
|
|
|
+ << static_cast<int>(headerView->checkState(0)) << " "
|
|
|
|
+ << static_cast<int>(row0[0]->checkState()) << " "
|
|
<< static_cast<int>(row1[0]->checkState()) << " "
|
|
<< static_cast<int>(row1[0]->checkState()) << " "
|
|
<< static_cast<int>(row2[0]->checkState()) << std::endl;
|
|
<< static_cast<int>(row2[0]->checkState()) << std::endl;
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- row0[0]->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
+ row0[0]->setCheckState(Qt::Checked);
|
|
// make sure it didn't uncheck the checkable items
|
|
// make sure it didn't uncheck the checkable items
|
|
- if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
- row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row1[0]->checkState() != Qt::Checked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ if (headerView->checkState(0) != Qt::Checked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -151,13 +179,14 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // The checkable header gets updated with the item check states
|
|
headerView->setPropagateToItems(true);
|
|
headerView->setPropagateToItems(true);
|
|
|
|
|
|
if (!headerView->propagateToItems() ||
|
|
if (!headerView->propagateToItems() ||
|
|
headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
- row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row1[0]->checkState() != Qt::Checked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ row0[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "ctkCheckableHeaderView::setPropagateToItems() failed: "
|
|
std::cerr << "ctkCheckableHeaderView::setPropagateToItems() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -167,12 +196,12 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- row0[0]->setCheckState(Qt::Checked);
|
|
|
|
|
|
+ row0[0]->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
- if (headerView->checkState(0) != Qt::Checked ||
|
|
|
|
- row0[0]->checkState() != Qt::Checked ||
|
|
|
|
- row1[0]->checkState() != Qt::Checked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -182,13 +211,13 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- row1[0]->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
+ row1[0]->setCheckState(Qt::Checked);
|
|
|
|
|
|
// make sure it didn't uncheck the checkable items
|
|
// make sure it didn't uncheck the checkable items
|
|
if (headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
if (headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
- row0[0]->checkState() != Qt::Checked ||
|
|
|
|
- row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -198,13 +227,13 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- row1[0]->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
+ row1[0]->setCheckState(Qt::Checked);
|
|
|
|
|
|
- // make sure it didn't uncheck the checkable items
|
|
|
|
|
|
+ // make sure it didn't check the checkable items
|
|
if (headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
if (headerView->checkState(0) != Qt::PartiallyChecked ||
|
|
- row0[0]->checkState() != Qt::Checked ||
|
|
|
|
- row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -214,14 +243,14 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- row0[0]->setCheckState(Qt::Unchecked);
|
|
|
|
- row2[0]->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
+ row0[0]->setCheckState(Qt::Checked);
|
|
|
|
+ row2[0]->setCheckState(Qt::Checked);
|
|
|
|
|
|
- // make sure the header is now unchecked
|
|
|
|
- if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
- row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
- row2[0]->checkState() != Qt::Unchecked)
|
|
|
|
|
|
+ // make sure the header is now checked
|
|
|
|
+ if (headerView->checkState(0) != Qt::Checked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Checked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Checked)
|
|
{
|
|
{
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
std::cerr << "QStandardItem::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -231,12 +260,12 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
return EXIT_FAILURE;
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
- headerView->setCheckState(0, Qt::Checked);
|
|
|
|
|
|
+ headerView->setCheckState(0, Qt::Unchecked);
|
|
|
|
|
|
- if (headerView->checkState(0) != Qt::Checked ||
|
|
|
|
- row0[0]->checkState() != Qt::Checked ||
|
|
|
|
- row1[0]->checkState() != Qt::Checked ||
|
|
|
|
- row2[0]->checkState() != Qt::Checked)
|
|
|
|
|
|
+ if (headerView->checkState(0) != Qt::Unchecked ||
|
|
|
|
+ row0[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row1[0]->checkState() != Qt::Unchecked ||
|
|
|
|
+ row2[0]->checkState() != Qt::Unchecked)
|
|
{
|
|
{
|
|
std::cerr << "ctkCheckableHeaderView::setCheckState() failed: "
|
|
std::cerr << "ctkCheckableHeaderView::setCheckState() failed: "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
<< static_cast<int>(headerView->checkState(0)) << " "
|
|
@@ -247,7 +276,6 @@ int ctkCheckableHeaderViewTest1(int argc, char * argv [] )
|
|
}
|
|
}
|
|
|
|
|
|
table.show();
|
|
table.show();
|
|
- //table.raise();
|
|
|
|
|
|
|
|
if (argc < 2 || QString(argv[1]) != "-I" )
|
|
if (argc < 2 || QString(argv[1]) != "-I" )
|
|
{
|
|
{
|