clean up partwidget class: don't use qpointers, don't use a pointer for access
to the partition property. still needs more work. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1113951
This commit is contained in:
parent
d98563b094
commit
0d2f3ccc84
|
@ -173,13 +173,13 @@ void PartitionManagerWidget::setSelectedPartition(const Partition* p)
|
|||
|
||||
Partition* PartitionManagerWidget::selectedPartition()
|
||||
{
|
||||
if (selectedDevice() == NULL || selectedDevice()->partitionTable() == NULL || partTableWidget().activeWidget() == NULL || partTableWidget().activeWidget()->partition() == NULL)
|
||||
if (selectedDevice() == NULL || selectedDevice()->partitionTable() == NULL || partTableWidget().activeWidget() == NULL)
|
||||
return NULL;
|
||||
|
||||
// The active partition we get from the part table widget is const; we need non-const.
|
||||
// So take the first sector and find the partition in the selected device's
|
||||
// partition table.
|
||||
const Partition* activePartition = partTableWidget().activeWidget()->partition();
|
||||
const Partition* activePartition = &partTableWidget().activeWidget()->partition();
|
||||
return selectedDevice()->partitionTable()->findPartitionBySector(activePartition->firstSector(), PartitionRole(PartitionRole::Any));
|
||||
}
|
||||
|
||||
|
@ -318,24 +318,22 @@ void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidge
|
|||
return;
|
||||
}
|
||||
|
||||
const Partition* p = item->partition();
|
||||
const Partition& p = item->partition();
|
||||
|
||||
Q_ASSERT(p);
|
||||
|
||||
QList<QTreeWidgetItem*> findResult = treePartitions().findItems(p->deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0);
|
||||
QList<QTreeWidgetItem*> findResult = treePartitions().findItems(p.deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0);
|
||||
|
||||
for (int idx = 0; idx < findResult.size(); idx++)
|
||||
{
|
||||
const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(findResult[idx]);
|
||||
|
||||
if (ptwItem && ptwItem->partition() == p)
|
||||
if (ptwItem && ptwItem->partition() == &p)
|
||||
{
|
||||
treePartitions().setCurrentItem(findResult[idx]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit selectedPartitionChanged(p);
|
||||
emit selectedPartitionChanged(&p);
|
||||
}
|
||||
|
||||
void PartitionManagerWidget::on_m_PartTableWidget_customContextMenuRequested(const QPoint& pos)
|
||||
|
|
|
@ -101,7 +101,7 @@ void PartTableWidget::setActivePartition(const Partition* p)
|
|||
return;
|
||||
|
||||
foreach (PartWidget* pw, findChildren<PartWidget*>())
|
||||
if (pw->partition() == p)
|
||||
if (&pw->partition() == p)
|
||||
{
|
||||
setActiveWidget(pw);
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2008,2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
|
@ -36,22 +36,23 @@
|
|||
|
||||
/** Creates a new PartWidget
|
||||
@param parent pointer to the parent widget
|
||||
@param ptWidget pointer to the PartTableWidget this widget will be in
|
||||
@param p pointer to the Partition this widget will show
|
||||
@param ptWidget pointer to the PartTableWidget this widget will be in or NULL if none
|
||||
@param p pointer to the Partition this widget will show. must not be NULL.
|
||||
@param show_children true if this widget is supposed to show child widgets
|
||||
*/
|
||||
PartWidget::PartWidget(QWidget* parent, const PartTableWidget* ptWidget, const Partition* p, bool show_children) :
|
||||
QWidget(parent),
|
||||
PartWidgetBase(),
|
||||
m_PartTableWidget(const_cast<PartTableWidget*>(ptWidget)),
|
||||
m_Partition(const_cast<Partition*>(p)),
|
||||
m_Widgets(),
|
||||
m_PartTableWidget(ptWidget),
|
||||
m_Partition(p),
|
||||
m_ChildWidgets(),
|
||||
m_ShowChildren(show_children)
|
||||
{
|
||||
setFont(KGlobalSettings::smallestReadableFont());
|
||||
|
||||
if (partition())
|
||||
setToolTip(partition()->deviceNode() + '\n' + partition()->fileSystem().name() + ' ' + Capacity(*partition()).toString());
|
||||
Q_ASSERT(p);
|
||||
|
||||
setToolTip(partition().deviceNode() + '\n' + partition().fileSystem().name() + ' ' + Capacity(partition()).toString());
|
||||
|
||||
updateChildren();
|
||||
}
|
||||
|
@ -59,39 +60,36 @@ PartWidget::PartWidget(QWidget* parent, const PartTableWidget* ptWidget, const P
|
|||
/** Updates the widget's children */
|
||||
void PartWidget::updateChildren()
|
||||
{
|
||||
foreach (QWidget* w, widgets())
|
||||
foreach (QWidget* w, childWidgets())
|
||||
{
|
||||
w->setVisible(false);
|
||||
w->deleteLater();
|
||||
}
|
||||
|
||||
widgets().clear();
|
||||
childWidgets().clear();
|
||||
|
||||
if (partition() && showChildren())
|
||||
if (showChildren())
|
||||
{
|
||||
foreach(Partition* child, partition()->children())
|
||||
foreach(const Partition* child, partition().children())
|
||||
{
|
||||
widgets().append(new PartWidget(this, partTableWidget(), child));
|
||||
widgets().last()->show();
|
||||
childWidgets().append(new PartWidget(this, partTableWidget(), child));
|
||||
childWidgets().last()->show();
|
||||
}
|
||||
|
||||
positionChildren(this, partition()->children(), widgets());
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return true if this is the currently active widget */
|
||||
bool PartWidget::active() const
|
||||
{
|
||||
if (partTableWidget() == NULL)
|
||||
return false;
|
||||
|
||||
return partTableWidget()->activeWidget() == this;
|
||||
return partTableWidget() != NULL && partTableWidget()->activeWidget() == this;
|
||||
}
|
||||
|
||||
void PartWidget::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
if (partition() && showChildren())
|
||||
positionChildren(this, partition()->children(), widgets());
|
||||
if (showChildren())
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
}
|
||||
|
||||
void PartWidget::paintEvent(QPaintEvent*)
|
||||
|
@ -101,31 +99,25 @@ void PartWidget::paintEvent(QPaintEvent*)
|
|||
|
||||
QColor PartWidget::activeColor(const QColor& col) const
|
||||
{
|
||||
if (active())
|
||||
return col.darker(130);
|
||||
|
||||
return col;
|
||||
return active() ? col.darker(130) : col;
|
||||
}
|
||||
|
||||
void PartWidget::drawPartition(QWidget* destWidget)
|
||||
{
|
||||
if (partition() == NULL)
|
||||
return;
|
||||
|
||||
const int usedPercentage = partition()->used() * 100 / partition()->capacity();
|
||||
const int usedPercentage = partition().used() * 100 / partition().capacity();
|
||||
const int w = (destWidget->width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100;
|
||||
|
||||
QPainter painter(destWidget);
|
||||
|
||||
// draw border
|
||||
painter.setPen(active() ? QColor(250, 250, 250) : QColor(20, 20, 20));
|
||||
painter.setBrush(activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())));
|
||||
painter.setBrush(activeColor(Config::fileSystemColorCode(partition().fileSystem().type())));
|
||||
painter.drawRect(QRect(0, 0, destWidget->width() - 1, destWidget->height() - 1));
|
||||
|
||||
if (partition()->roles().has(PartitionRole::Extended))
|
||||
if (partition().roles().has(PartitionRole::Extended))
|
||||
return;
|
||||
|
||||
if (!partition()->roles().has(PartitionRole::Unallocated))
|
||||
if (!partition().roles().has(PartitionRole::Unallocated))
|
||||
{
|
||||
// draw free space background
|
||||
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
|
||||
|
@ -137,7 +129,7 @@ void PartWidget::drawPartition(QWidget* destWidget)
|
|||
}
|
||||
|
||||
// draw name and size
|
||||
QString text = partition()->deviceNode().remove("/dev/") + '\n' + Capacity(*partition()).toString();
|
||||
QString text = partition().deviceNode().remove("/dev/") + '\n' + Capacity(partition()).toString();
|
||||
|
||||
const QRect textRect(0, 0, destWidget->width() - 1, destWidget->height() - 1);
|
||||
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2008,2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
|
@ -22,12 +22,13 @@
|
|||
#define PARTWIDGET__H
|
||||
|
||||
#include "gui/partwidgetbase.h"
|
||||
#include "gui/parttablewidget.h"
|
||||
|
||||
#include "core/partition.h"
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
class PartTableWidget;
|
||||
class Partition;
|
||||
|
||||
class QPaintEvent;
|
||||
class QResizeEvent;
|
||||
|
@ -49,17 +50,16 @@ class PartWidget : public QWidget, public PartWidgetBase
|
|||
bool active() const;
|
||||
void updateChildren();
|
||||
|
||||
const Partition* partition() const { return m_Partition.isNull() ? NULL : m_Partition; } /**< @return the widget's Partition or NULL if none set */
|
||||
const Partition& partition() const { Q_ASSERT(m_Partition); return *m_Partition; } /**< @return the widget's Partition */
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
PartTableWidget* partTableWidget() { return m_PartTableWidget.isNull() ? NULL : m_PartTableWidget; }
|
||||
const PartTableWidget* partTableWidget() const { return m_PartTableWidget.isNull() ? NULL : m_PartTableWidget; }
|
||||
const PartTableWidget* partTableWidget() const { return m_PartTableWidget; }
|
||||
|
||||
QList<PartWidget*>& widgets() { return m_Widgets; }
|
||||
const QList<PartWidget*>& widgets() const { return m_Widgets; }
|
||||
QList<PartWidget*>& childWidgets() { return m_ChildWidgets; }
|
||||
const QList<PartWidget*>& childWidgets() const { return m_ChildWidgets; }
|
||||
|
||||
void drawPartition(QWidget* destWidget);
|
||||
bool showChildren() const { return m_ShowChildren; }
|
||||
|
@ -67,9 +67,9 @@ class PartWidget : public QWidget, public PartWidgetBase
|
|||
QColor activeColor(const QColor& col) const;
|
||||
|
||||
private:
|
||||
QPointer<PartTableWidget> m_PartTableWidget;
|
||||
QPointer<Partition> m_Partition;
|
||||
QList<PartWidget*> m_Widgets;
|
||||
const PartTableWidget* m_PartTableWidget;
|
||||
const Partition* m_Partition;
|
||||
QList<PartWidget*> m_ChildWidgets;
|
||||
const bool m_ShowChildren;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue