uic - fix to handle QTreeWidget with empty header(s)

This makes it possible for uic to handle QTreeWidget that in
the designer has one or more empty headers.

Before the right(most) empty items where there wasn't a
non-empty header to the right of them would not be visible.

The other empty items - where there was a header to the
right of it would not be empty but initialized with a number.

This patch ensures the same behavior that the QTableWidget
is having.

Task-number: QTBUG-18156

Change-Id: I19bfd3307befe46a1af2d6a3275f7446a15b3442
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-11-19 15:17:27 +01:00 committed by The Qt Project
parent b8e883bdb0
commit 37eb61677c
3 changed files with 165 additions and 0 deletions

View File

@ -2159,6 +2159,12 @@ void WriteInitialization::initializeTreeWidget(DomWidget *w)
const DomPropertyMap properties = propertyMap(column->elementProperty());
addCommonInitializers(&item, properties, i);
if (const DomProperty *p = properties.value(QLatin1String("text"))) {
DomString *str = p->elementString();
if (str && str->text().isEmpty())
m_output << m_indent << varName << "->headerItem()->setText(" << i << ", QString());\n";
}
}
const QString itemName = item.writeSetupUi(QString(), Item::DontConstruct);
item.writeRetranslateUi(varName + QLatin1String("->headerItem()"));

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget">
<column>
<property name="text">
<string/>
</property>
</column>
<column>
<property name="text">
<string>4</string>
</property>
</column>
<column>
<property name="text">
<string/>
</property>
</column>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,76 @@
/********************************************************************************
** Form generated from reading UI file 'bug18156QTreeWidget.ui'
**
** Created: Tue Nov 20 20:12:59 2012
** by: Qt User Interface Compiler version 5.0.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef BUG18156QTREEWIDGET_H
#define BUG18156QTREEWIDGET_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QTreeWidget>
QT_BEGIN_NAMESPACE
class Ui_Dialog
{
public:
QGridLayout *gridLayout;
QTreeWidget *treeWidget;
QDialogButtonBox *buttonBox;
void setupUi(QDialog *Dialog)
{
if (Dialog->objectName().isEmpty())
Dialog->setObjectName(QStringLiteral("Dialog"));
Dialog->resize(400, 300);
gridLayout = new QGridLayout(Dialog);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
treeWidget = new QTreeWidget(Dialog);
treeWidget->headerItem()->setText(0, QString());
treeWidget->headerItem()->setText(2, QString());
treeWidget->setObjectName(QStringLiteral("treeWidget"));
gridLayout->addWidget(treeWidget, 0, 0, 1, 1);
buttonBox = new QDialogButtonBox(Dialog);
buttonBox->setObjectName(QStringLiteral("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
retranslateUi(Dialog);
QObject::connect(buttonBox, SIGNAL(accepted()), Dialog, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), Dialog, SLOT(reject()));
QMetaObject::connectSlotsByName(Dialog);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0));
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
___qtreewidgetitem->setText(1, QApplication::translate("Dialog", "4", 0));
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // BUG18156QTREEWIDGET_H