don't keep a list of our children in PartTableWidget either; like in

PartWidget, we can just let Qt handle that for us

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1114047
This commit is contained in:
Volker Lanz 2010-04-12 16:08:13 +00:00
parent c1a6713e45
commit 22978e66b8
3 changed files with 22 additions and 15 deletions

View File

@ -32,8 +32,8 @@
*/
PartTableWidget::PartTableWidget(QWidget* parent) :
QWidget(parent),
PartWidgetBase(),
m_PartitionTable(NULL),
m_Widgets(),
m_LabelEmpty(i18nc("@info", "Please select a device."), this),
m_ReadOnly(false)
{
@ -53,12 +53,12 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
{
foreach(const Partition* p, partitionTable()->children())
{
widgets().append(new PartWidget(this, p));
widgets().last()->show();
QWidget* w = new PartWidget(this, p);
w->setVisible(true);
}
}
if (widgets().isEmpty())
if (childWidgets().isEmpty())
{
labelEmpty().setVisible(true);
labelEmpty().setText(i18nc("@info", "No valid partition table was found on this device."));
@ -67,12 +67,23 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
else
{
labelEmpty().setVisible(false);
positionChildren(this, partitionTable()->children(), widgets());
positionChildren(this, partitionTable()->children(), childWidgets());
}
update();
}
QList<PartWidget*> PartTableWidget::childWidgets()
{
QList<PartWidget*> rval;
foreach(QObject* o, children())
if (PartWidget* w = qobject_cast<PartWidget*>(o))
rval.append(w);
return rval;
}
PartWidget* PartTableWidget::activeWidget()
{
foreach (PartWidget* pw, findChildren<PartWidget*>())
@ -139,23 +150,22 @@ void PartTableWidget::clear()
// that its event handler is currently running. therefore, do not delete
// the part widgets here but schedule them for deletion once the app
// returns to the main loop (and the event handler has finished).
foreach(PartWidget* p, widgets())
foreach(PartWidget* p, childWidgets())
{
p->setVisible(false);
p->deleteLater();
p->setParent(NULL);
}
widgets().clear();
update();
}
void PartTableWidget::resizeEvent(QResizeEvent*)
{
if (partitionTable() == NULL || widgets().isEmpty())
if (partitionTable() == NULL || childWidgets().isEmpty())
labelEmpty().resize(size());
else
positionChildren(this, partitionTable()->children(), widgets());
positionChildren(this, partitionTable()->children(), childWidgets());
}
void PartTableWidget::mousePressEvent(QMouseEvent* event)

View File

@ -65,10 +65,7 @@ class PartTableWidget : public QWidget, public PartWidgetBase
void mousePressEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void drawPartitions() const;
QList<PartWidget*>& widgets() { return m_Widgets; }
const QList<PartWidget*>& widgets() const { return m_Widgets; }
QList<PartWidget*> childWidgets();
const PartitionTable* partitionTable() const { return m_PartitionTable; }
@ -77,7 +74,6 @@ class PartTableWidget : public QWidget, public PartWidgetBase
private:
const PartitionTable* m_PartitionTable;
QList<PartWidget*> m_Widgets;
QLabel m_LabelEmpty;
bool m_ReadOnly;
};

View File

@ -67,6 +67,7 @@ void PartWidget::updateChildren()
{
w->setVisible(false);
w->deleteLater();
w->setParent(NULL);
}
foreach(const Partition* child, partition().children())