diff --git a/src/gui/partitionmanagerwidget.cpp b/src/gui/partitionmanagerwidget.cpp index 0f3441f..f064547 100644 --- a/src/gui/partitionmanagerwidget.cpp +++ b/src/gui/partitionmanagerwidget.cpp @@ -179,7 +179,7 @@ Partition* PartitionManagerWidget::selectedPartition() // 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)); } @@ -322,22 +322,27 @@ void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidge return; } - const Partition& p = item->partition(); + const Partition* p = item->partition(); - QList findResult = treePartitions().findItems(p.deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0); + Q_ASSERT(p); - for (int idx = 0; idx < findResult.size(); idx++) + if (p) { - const PartitionTreeWidgetItem* ptwItem = dynamic_cast(findResult[idx]); + QList findResult = treePartitions().findItems(p->deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0); - if (ptwItem && ptwItem->partition() == &p) + for (int idx = 0; idx < findResult.size(); idx++) { - treePartitions().setCurrentItem(findResult[idx]); - break; + const PartitionTreeWidgetItem* ptwItem = dynamic_cast(findResult[idx]); + + 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) diff --git a/src/gui/partpropsdialog.cpp b/src/gui/partpropsdialog.cpp index 38659cb..c62f041 100644 --- a/src/gui/partpropsdialog.cpp +++ b/src/gui/partpropsdialog.cpp @@ -96,7 +96,7 @@ void PartPropsDialog::setupDialog() enableButtonOk(false); button(KDialog::Cancel)->setFocus(); - dialogWidget().partResizerWidget().init(device(), partition(), partition().firstSector(), partition().lastSector(), true, false); + dialogWidget().partWidget().init(&partition()); const QString mp = partition().mountPoint().isEmpty() ? i18nc("@item mountpoint", "(none found)") @@ -315,7 +315,7 @@ void PartPropsDialog::updatePartitionFileSystem() FileSystem* fs = FileSystemFactory::create(newFileSystemType(), partition().firstSector(), partition().lastSector()); partition().deleteFileSystem(); partition().setFileSystem(fs); - dialogWidget().partResizerWidget().update(); + dialogWidget().partWidget().update(); } void PartPropsDialog::onFilesystemChanged(int) diff --git a/src/gui/partpropswidget.h b/src/gui/partpropswidget.h index 4898a79..0f5fff8 100644 --- a/src/gui/partpropswidget.h +++ b/src/gui/partpropswidget.h @@ -32,7 +32,7 @@ class PartPropsWidget : public QWidget, public Ui::PartPropsWidgetBase PartPropsWidget(QWidget* parent) : QWidget(parent) { setupUi(this); } public: - PartResizerWidget& partResizerWidget() { Q_ASSERT(m_PartResizerWidget); return *m_PartResizerWidget; } + PartWidget& partWidget() { Q_ASSERT(m_PartWidget); return *m_PartWidget; } QLabel& mountPoint() { Q_ASSERT(m_LabelMountPoint); return *m_LabelMountPoint; } QLabel& role() { Q_ASSERT(m_LabelRole); return *m_LabelRole; } diff --git a/src/gui/partpropswidgetbase.ui b/src/gui/partpropswidgetbase.ui index 8b0838a..655b6ab 100644 --- a/src/gui/partpropswidgetbase.ui +++ b/src/gui/partpropswidgetbase.ui @@ -12,7 +12,7 @@ - + 300 @@ -360,9 +360,9 @@
kcombobox.h
- PartResizerWidget + PartWidget QWidget -
gui/partresizerwidget.h
+
gui/partwidget.h
1
diff --git a/src/gui/parttablewidget.cpp b/src/gui/parttablewidget.cpp index ca8292a..39c505d 100644 --- a/src/gui/parttablewidget.cpp +++ b/src/gui/parttablewidget.cpp @@ -118,7 +118,7 @@ void PartTableWidget::setActivePartition(const Partition* p) return; foreach (PartWidget* pw, findChildren()) - if (&pw->partition() == p) + if (pw->partition() == p) { setActiveWidget(pw); return; diff --git a/src/gui/partwidget.cpp b/src/gui/partwidget.cpp index cc276dd..94cd723 100644 --- a/src/gui/partwidget.cpp +++ b/src/gui/partwidget.cpp @@ -38,12 +38,22 @@ */ PartWidget::PartWidget(QWidget* parent, const Partition* p) : PartWidgetBase(parent), - m_Partition(p), + m_Partition(NULL), m_Active(false) { setFont(KGlobalSettings::smallestReadableFont()); - setToolTip(partition().deviceNode() + '\n' + partition().fileSystem().name() + ' ' + Capacity(partition()).toString()); + init(p); +} + +void PartWidget::init(const Partition* p) +{ + m_Partition = p; + + if (partition()) + setToolTip(partition()->deviceNode() + '\n' + partition()->fileSystem().name() + ' ' + Capacity(*partition()).toString()); + else + setToolTip(QString()); updateChildren(); } @@ -51,25 +61,29 @@ PartWidget::PartWidget(QWidget* parent, const Partition* p) : /** Updates the widget's children */ void PartWidget::updateChildren() { - foreach (QWidget* w, childWidgets()) + if (partition()) { - w->setVisible(false); - w->deleteLater(); - w->setParent(NULL); - } + foreach (QWidget* w, childWidgets()) + { + w->setVisible(false); + w->deleteLater(); + w->setParent(NULL); + } - foreach(const Partition* child, partition().children()) - { - QWidget* w = new PartWidget(this, child); - w->setVisible(true); - } + foreach(const Partition* child, partition()->children()) + { + QWidget* w = new PartWidget(this, child); + w->setVisible(true); + } - positionChildren(this, partition().children(), childWidgets()); + positionChildren(this, partition()->children(), childWidgets()); + } } void PartWidget::resizeEvent(QResizeEvent*) { - positionChildren(this, partition().children(), childWidgets()); + if (partition()) + positionChildren(this, partition()->children(), childWidgets()); } QColor PartWidget::activeColor(const QColor& col) const @@ -79,20 +93,23 @@ QColor PartWidget::activeColor(const QColor& col) const void PartWidget::paintEvent(QPaintEvent*) { - const int usedPercentage = partition().used() * 100 / partition().capacity(); + if (partition() == NULL) + return; + + const int usedPercentage = partition()->used() * 100 / partition()->capacity(); const int w = (width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100; QPainter painter(this); // draw border painter.setPen(isActive() ? 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, width() - 1, 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())); @@ -104,7 +121,7 @@ void PartWidget::paintEvent(QPaintEvent*) } // 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, width() - 1, height() - 1); const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text); diff --git a/src/gui/partwidget.h b/src/gui/partwidget.h index 226903f..06775d9 100644 --- a/src/gui/partwidget.h +++ b/src/gui/partwidget.h @@ -41,14 +41,15 @@ class PartWidget : public PartWidgetBase Q_OBJECT public: - PartWidget(QWidget* parent, const Partition* p); + PartWidget(QWidget* parent, const Partition* p = NULL); public: + void init(const Partition* p); void setActive(bool b) { m_Active = b; } bool isActive() const { return m_Active; } /**< @return true if this is the currently active widget */ void updateChildren(); - const Partition& partition() const { Q_ASSERT(m_Partition); return *m_Partition; } /**< @return the widget's Partition */ + const Partition* partition() const { return m_Partition; } /**< @return the widget's Partition */ protected: void paintEvent(QPaintEvent* event);