make isEmpty part of the public API, make the implementation of it slightly more efficient

svn path=/trunk/KDE/kdelibs/; revision=964311
This commit is contained in:
Aaron J. Seigo 2009-05-06 14:21:05 +00:00
parent b3bdde3483
commit fd2c597c4a
2 changed files with 19 additions and 11 deletions

View File

@ -232,7 +232,7 @@ Extender::Appearance Extender::appearance() const
QList<ExtenderGroup*> Extender::groups() const
{
QList<ExtenderGroup*> result;
foreach (ExtenderItem *item, attachedItems()) {
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (item->isGroup() && !result.contains(item->group())) {
result.append(item->group());
}
@ -266,7 +266,7 @@ void Extender::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet);
if (d->isEmpty() && popupApplet) {
if (isEmpty() && popupApplet) {
popupApplet->hidePopup();
}
}
@ -618,8 +618,8 @@ void ExtenderPrivate::updateBorders()
void ExtenderPrivate::updateEmptyExtenderLabel()
{
if (isEmpty() && !emptyExtenderLabel && !emptyExtenderMessage.isEmpty()
&& !spacerWidget ) {
if (q->isEmpty() && !emptyExtenderLabel &&
!emptyExtenderMessage.isEmpty() && !spacerWidget ) {
//add the empty extender label.
emptyExtenderLabel = new Label(q);
emptyExtenderLabel->setAlignment(Qt::AlignCenter);
@ -631,7 +631,7 @@ void ExtenderPrivate::updateEmptyExtenderLabel()
emptyExtenderLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
layout->addItem(emptyExtenderLabel);
} else if (!isEmpty() && emptyExtenderLabel) {
} else if (!q->isEmpty() && emptyExtenderLabel) {
//remove the empty extender label.
layout->removeItem(emptyExtenderLabel);
delete emptyExtenderLabel;
@ -649,16 +649,18 @@ ExtenderGroup *ExtenderPrivate::findGroup(const QString &name) const
return 0;
}
bool ExtenderPrivate::isEmpty() const
bool Extender::isEmpty() const
{
if (q->attachedItems().isEmpty()) {
return true;
} else {
//If there are only groups, consider this extender empty
return (q->attachedItems().size() == q->groups().size());
//If there are no items or only groups, consider this extender empty
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (!item->isGroup()) {
return false;
}
}
return true;
}
} // Plasma namespace
#include "extender.moc"

View File

@ -156,6 +156,12 @@ class PLASMA_EXPORT Extender : public QGraphicsWidget
*/
bool hasItem(const QString &name) const;
/**
* @return true if the Extender is visually empty (though it may have items such as
* empty groups or detached items associatd with it)
*/
bool isEmpty() const;
/**
* Use this function to instruct the extender on how to render it's items. Usually you will
* want to call this function in your applet's constraintsEvent, allthough this is already