44 #include <QGridLayout>
58 void init(QWidget* parent);
87 void insertRow(QGridLayout* layout,
int row)
const;
88 void removeRow(QGridLayout* layout,
int row)
const;
92 QMap<QtBrowserItem*, WidgetItem*> m_indexToItem;
93 QMap<WidgetItem*, QtBrowserItem*> m_itemToIndex;
94 QMap<QWidget*, WidgetItem*> m_widgetToItem;
95 QGridLayout* m_mainLayout;
96 QList<WidgetItem*> m_children;
97 QList<WidgetItem*> m_recreateQueue;
102 m_mainLayout =
new QGridLayout();
103 parent->setLayout(m_mainLayout);
104 QLayoutItem* item =
new QSpacerItem(0, 0,
105 QSizePolicy::Fixed, QSizePolicy::Expanding);
106 m_mainLayout->addItem(item, 0, 0);
111 QWidget* editor = qobject_cast<QWidget*>(q_ptr->sender());
118 if (!m_widgetToItem.contains(editor))
123 m_widgetToItem[editor]->widget = 0;
124 m_widgetToItem.remove(editor);
129 QListIterator<WidgetItem*> itItem(m_recreateQueue);
131 while (itItem.hasNext())
144 oldRow = m_children.indexOf(item);
150 oldRow = par->
children.indexOf(item);
160 item->
widget->setParent(w);
169 item->
widgetLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
177 l->addWidget(item->
widget, oldRow, 1, 1, 1);
188 item->
label =
new QLabel(w);
189 item->
label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
190 l->addWidget(item->
label, oldRow, 0, 1, span);
195 m_recreateQueue.clear();
198 void QtGroupBoxPropertyBrowserPrivate::updateLater()
200 QTimer::singleShot(0, q_ptr, SLOT(
slotUpdate()));
205 WidgetItem* afterItem = m_indexToItem.value(afterIndex);
209 newItem->
parent = parentItem;
211 QGridLayout* layout = 0;
212 QWidget* parentWidget = 0;
221 parentItem->
children.insert(0, newItem);
225 m_children.insert(0, newItem);
232 row = parentItem->
children.indexOf(afterItem) + 1;
233 parentItem->
children.insert(row, newItem);
237 row = m_children.indexOf(afterItem) + 1;
238 m_children.insert(row, newItem);
242 if (parentItem && hasHeader(parentItem))
249 layout = m_mainLayout;
250 parentWidget = q_ptr;;
256 m_recreateQueue.removeAll(parentItem);
266 oldRow = m_children.indexOf(parentItem);
272 oldRow = par->
children.indexOf(parentItem);
280 parentItem->
groupBox =
new QGroupBox(w);
281 parentItem->
layout =
new QGridLayout();
284 if (parentItem->
label)
286 l->removeWidget(parentItem->
label);
287 delete parentItem->
label;
288 parentItem->
label = 0;
293 l->removeWidget(parentItem->
widget);
295 parentItem->
layout->addWidget(parentItem->
widget, 0, 0, 1, 2);
305 if (parentItem->
line)
307 parentItem->
line->setFrameShape(QFrame::HLine);
308 parentItem->
line->setFrameShadow(QFrame::Sunken);
309 parentItem->
layout->addWidget(parentItem->
line, 1, 0, 1, 2);
312 l->addWidget(parentItem->
groupBox, oldRow, 0, 1, 2);
313 updateItem(parentItem);
316 layout = parentItem->
layout;
317 parentWidget = parentItem->
groupBox;
320 newItem->
label =
new QLabel(parentWidget);
321 newItem->
label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
327 newItem->
widgetLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
328 newItem->
widgetLabel->setTextFormat(Qt::PlainText);
333 m_widgetToItem[newItem->
widget] = newItem;
336 insertRow(layout, row);
341 layout->addWidget(newItem->
widget, row, 1);
352 layout->addWidget(newItem->
label, row, 0, 1, span);
354 m_itemToIndex[newItem] =
index;
355 m_indexToItem[
index] = newItem;
364 m_indexToItem.remove(
index);
365 m_itemToIndex.remove(item);
373 row = parentItem->
children.indexOf(item);
376 if (hasHeader(parentItem))
383 row = m_children.indexOf(item);
384 m_children.removeAt(row);
409 removeRow(m_mainLayout, row);
411 else if (parentItem->
children.count() != 0)
413 removeRow(parentItem->
layout, row);
424 oldRow = m_children.indexOf(parentItem);
429 oldRow = par->
children.indexOf(parentItem);
439 parentItem->
widget->hide();
440 parentItem->
widget->setParent(0);
452 l->removeWidget(parentItem->
groupBox);
455 parentItem->
line = 0;
458 if (!m_recreateQueue.contains(parentItem))
460 m_recreateQueue.append(parentItem);
466 m_recreateQueue.removeAll(item);
471 void QtGroupBoxPropertyBrowserPrivate::insertRow(QGridLayout* layout,
int row)
const
473 QMap<QLayoutItem*, QRect> itemToPos;
476 while (idx < layout->count())
479 layout->getItemPosition(idx, &r, &
c, &rs, &cs);
483 itemToPos[layout->takeAt(idx)] = QRect(r + 1,
c, rs, cs);
491 const QMap<QLayoutItem*, QRect>::ConstIterator icend = itemToPos.constEnd();
493 for (QMap<QLayoutItem*, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it)
495 const QRect r = it.value();
496 layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
500 void QtGroupBoxPropertyBrowserPrivate::removeRow(QGridLayout* layout,
int row)
const
502 QMap<QLayoutItem*, QRect> itemToPos;
505 while (idx < layout->count())
508 layout->getItemPosition(idx, &r, &
c, &rs, &cs);
512 itemToPos[layout->takeAt(idx)] = QRect(r - 1,
c, rs, cs);
520 const QMap<QLayoutItem*, QRect>::ConstIterator icend = itemToPos.constEnd();
522 for (QMap<QLayoutItem*, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it)
524 const QRect r = it.value();
525 layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
529 bool QtGroupBoxPropertyBrowserPrivate::hasHeader(WidgetItem* item)
const
546 void QtGroupBoxPropertyBrowserPrivate::updateItem(WidgetItem* item)
548 QtProperty*
property = m_itemToIndex[item]->property();
552 QFont font = item->groupBox->font();
553 font.setUnderline(property->isModified());
554 item->groupBox->setFont(font);
555 item->groupBox->setTitle(property->propertyName());
556 item->groupBox->setToolTip(property->toolTip());
557 item->groupBox->setStatusTip(property->statusTip());
558 item->groupBox->setWhatsThis(property->whatsThis());
559 item->groupBox->setEnabled(property->isEnabled());
564 QFont font = item->label->font();
565 font.setUnderline(property->isModified());
566 item->label->setFont(font);
567 item->label->setText(property->propertyName());
568 item->label->setToolTip(property->toolTip());
569 item->label->setStatusTip(property->statusTip());
570 item->label->setWhatsThis(property->whatsThis());
571 item->label->setEnabled(property->isEnabled());
574 if (item->widgetLabel)
576 QFont font = item->widgetLabel->font();
577 font.setUnderline(
false);
578 item->widgetLabel->setFont(font);
579 item->widgetLabel->setText(property->valueText());
580 item->widgetLabel->setToolTip(property->valueText());
581 item->widgetLabel->setEnabled(property->isEnabled());
586 QFont font = item->widget->font();
587 font.setUnderline(
false);
588 item->widget->setFont(font);
589 item->widget->setEnabled(property->isEnabled());
590 item->widget->setToolTip(property->valueText());
648 const QMap<QtGroupBoxPropertyBrowserPrivate::WidgetItem*, QtBrowserItem*>::ConstIterator icend = d_ptr->m_itemToIndex.constEnd();
650 for (QMap<QtGroupBoxPropertyBrowserPrivate::WidgetItem*, QtBrowserItem*>::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it)
684 #include "moc_qtgroupboxpropertybrowser.cpp"