More conversion from QStringList to QList<const Partition*>.
listPhysicalVolumes::checkedItems is now QList based.
This commit is contained in:
parent
e2afd2c683
commit
5bebcfbbc8
|
@ -27,7 +27,7 @@
|
|||
#include <KLocalizedString>
|
||||
#include <KSharedConfig>
|
||||
|
||||
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& pvList, qint32& peSize, FS::lvm2_pv::PhysicalVolumes physicalVolumes, QList<Device*> devices)
|
||||
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& pvList, qint32& peSize, FS::lvm2_pv::PhysicalVolumes physicalVolumes, QList<Device*> devices)
|
||||
: VolumeGroupDialog(parent, vgName, pvList)
|
||||
, m_PESize(peSize)
|
||||
, m_PhysicalVolumes(physicalVolumes)
|
||||
|
@ -49,7 +49,7 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam
|
|||
void CreateVolumeGroupDialog::setupDialog()
|
||||
{
|
||||
for (const auto &p : m_PhysicalVolumes)
|
||||
if (p.first == QString() && !LvmDevice::s_DirtyPVs.contains(p.second->deviceNode()))
|
||||
if (p.first == QString() && !LvmDevice::s_DirtyPVs.contains(p.second))
|
||||
dialogWidget().listPV().addPartition(*p.second, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class CreateVolumeGroupDialog : public VolumeGroupDialog
|
|||
Q_DISABLE_COPY(CreateVolumeGroupDialog)
|
||||
|
||||
public:
|
||||
CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& pvList, qint32& peSize, FS::lvm2_pv::PhysicalVolumes physicalVolumes, QList<Device*> devices);
|
||||
CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& pvList, qint32& peSize, FS::lvm2_pv::PhysicalVolumes physicalVolumes, QList<Device*> devices);
|
||||
|
||||
protected:
|
||||
void accept() override;
|
||||
|
|
|
@ -21,17 +21,7 @@
|
|||
#include <util/globallog.h>
|
||||
#include <util/capacity.h>
|
||||
|
||||
class ListPhysicalVolumeWidgetItem : public QListWidgetItem
|
||||
{
|
||||
public:
|
||||
ListPhysicalVolumeWidgetItem(const Partition& p, bool checked) :
|
||||
QListWidgetItem(p.deviceNode() + QStringLiteral(" | ") + Capacity::formatByteSize(p.capacity()))
|
||||
{
|
||||
setToolTip(p.deviceNode());
|
||||
setSizeHint(QSize(0, 32));
|
||||
setCheckState( checked ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ListPhysicalVolumes::ListPhysicalVolumes(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
|
@ -46,15 +36,22 @@ void ListPhysicalVolumes::addPartition(const Partition& p, bool checked)
|
|||
listPhysicalVolumes().addItem(item);
|
||||
}
|
||||
|
||||
QStringList ListPhysicalVolumes::checkedItems()
|
||||
QList<const Partition *> ListPhysicalVolumes::checkedItems()
|
||||
{
|
||||
QStringList rlist = QStringList();
|
||||
QList<const Partition *> partitionList;
|
||||
for (int i = 0; i < listPhysicalVolumes().count(); i++) {
|
||||
QListWidgetItem* item = listPhysicalVolumes().item(i);
|
||||
if(item && item->checkState() == Qt::Checked) {
|
||||
rlist << item->text().split(QStringLiteral("|"))[0].trimmed();
|
||||
}
|
||||
ListPhysicalVolumeWidgetItem* item = dynamic_cast<ListPhysicalVolumeWidgetItem*>(listPhysicalVolumes().item(i));
|
||||
if(item && item->checkState() == Qt::Checked)
|
||||
partitionList.append(item->partition());
|
||||
}
|
||||
return rlist;
|
||||
return partitionList;
|
||||
}
|
||||
|
||||
ListPhysicalVolumeWidgetItem::ListPhysicalVolumeWidgetItem(const Partition& p, bool checked)
|
||||
: QListWidgetItem(p.deviceNode() + QStringLiteral(" | ") + Capacity::formatByteSize(p.capacity()))
|
||||
, m_Partition(&p)
|
||||
{
|
||||
setToolTip(p.deviceNode());
|
||||
setSizeHint(QSize(0, 32));
|
||||
setCheckState( checked ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,16 @@ class Device;
|
|||
class QPoint;
|
||||
class KActionCollection;
|
||||
|
||||
class ListPhysicalVolumeWidgetItem : public QListWidgetItem
|
||||
{
|
||||
public:
|
||||
ListPhysicalVolumeWidgetItem(const Partition& p, bool checked);
|
||||
const Partition* partition() const { return m_Partition; }
|
||||
|
||||
private:
|
||||
const Partition* m_Partition;
|
||||
};
|
||||
|
||||
class ListPhysicalVolumes : public QWidget, public Ui::ListPhysicalVolumesBase
|
||||
{
|
||||
Q_DISABLE_COPY(ListPhysicalVolumes)
|
||||
|
@ -38,7 +48,7 @@ public:
|
|||
|
||||
void addPartition(const Partition& p, bool checked);
|
||||
|
||||
QStringList checkedItems();
|
||||
QList<const Partition *> checkedItems();
|
||||
|
||||
QListWidget& listPhysicalVolumes() {
|
||||
Q_ASSERT(m_ListPhysicalVolumes);
|
||||
|
|
|
@ -1102,17 +1102,32 @@ void MainWindow::onExportPartitionTable()
|
|||
|
||||
void MainWindow::onCreateNewVolumeGroup()
|
||||
{
|
||||
QString* vgname = new QString();
|
||||
QStringList* pvlist = new QStringList();
|
||||
qint32 pesize = 4;
|
||||
// *NOTE*: vgname & pvlist will be modified and validated by the dialog
|
||||
QPointer<CreateVolumeGroupDialog> dlg = new CreateVolumeGroupDialog(this, *vgname, *pvlist, pesize, operationStack().physicalVolumes(), operationStack().previewDevices());
|
||||
if (dlg->exec() == QDialog::Accepted) {
|
||||
operationStack().push(new CreateVolumeGroupOperation(*vgname, *pvlist, pesize));
|
||||
}
|
||||
QString vgName;
|
||||
QList<const Partition*> pvList;
|
||||
qint32 peSize = 4;
|
||||
// *NOTE*: vgName & pvList will be modified and validated by the dialog
|
||||
QPointer<CreateVolumeGroupDialog> dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, operationStack().physicalVolumes(), operationStack().previewDevices());
|
||||
if (dlg->exec() == QDialog::Accepted)
|
||||
operationStack().push(new CreateVolumeGroupOperation(vgName, pvList, peSize));
|
||||
|
||||
delete dlg;
|
||||
delete vgname;
|
||||
delete pvlist;
|
||||
}
|
||||
|
||||
void MainWindow::onResizeVolumeGroup()
|
||||
{
|
||||
if (pmWidget().selectedDevice()->type() == Device::LVM_Device) {
|
||||
LvmDevice* tmpDev = dynamic_cast<LvmDevice*>(pmWidget().selectedDevice());
|
||||
|
||||
QString* vgName = new QString(tmpDev->name()); // This line only purpose is to make volumeGroupDialog happy
|
||||
QList<const Partition*> pvList;
|
||||
// *NOTE*: pvList will be modified and validated by the dialog
|
||||
|
||||
QPointer<ResizeVolumeGroupDialog> dlg = new ResizeVolumeGroupDialog(this, *vgName, pvList, *tmpDev, operationStack().physicalVolumes());
|
||||
if (dlg->exec() == QDialog::Accepted)
|
||||
operationStack().push(new ResizeVolumeGroupOperation(*tmpDev, pvList));
|
||||
|
||||
delete dlg;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onRemoveVolumeGroup()
|
||||
|
@ -1144,24 +1159,6 @@ void MainWindow::onDeactivateVolumeGroup()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onResizeVolumeGroup()
|
||||
{
|
||||
if (pmWidget().selectedDevice()->type() == Device::LVM_Device) {
|
||||
LvmDevice* tmpDev = dynamic_cast<LvmDevice*>(pmWidget().selectedDevice());
|
||||
|
||||
QString* vgName = new QString(tmpDev->name()); // This line only purpose is to make volumeGroupDialog happy
|
||||
QStringList* pvList = new QStringList();
|
||||
// *NOTE*: pvList will be modified and validated by the dialog
|
||||
|
||||
QPointer<ResizeVolumeGroupDialog> dlg = new ResizeVolumeGroupDialog(this, *vgName, *pvList, *tmpDev, operationStack().physicalVolumes());
|
||||
if (dlg->exec() == QDialog::Accepted) {
|
||||
operationStack().push(new ResizeVolumeGroupOperation(*tmpDev, *pvList));
|
||||
}
|
||||
delete dlg;
|
||||
delete pvList;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onFileSystemSupport()
|
||||
{
|
||||
FileSystemSupportDialog dlg(this);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
@param parent pointer to the parent widget
|
||||
@param d the Device to show properties for
|
||||
*/
|
||||
ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& partList, VolumeManagerDevice& d, FS::lvm2_pv::PhysicalVolumes physicalVolumes)
|
||||
ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& partList, VolumeManagerDevice& d, FS::lvm2_pv::PhysicalVolumes physicalVolumes)
|
||||
: VolumeGroupDialog(parent, vgName, partList)
|
||||
, m_Device(d)
|
||||
, m_PhysicalVolumes(physicalVolumes)
|
||||
|
@ -54,7 +54,7 @@ void ResizeVolumeGroupDialog::setupDialog()
|
|||
for (const auto &p : m_PhysicalVolumes) {
|
||||
if (p.first == device().name())
|
||||
dialogWidget().listPV().addPartition(*p.second, true);
|
||||
else if (p.first == QString() && !LvmDevice::s_DirtyPVs.contains(p.second->deviceNode())) // TODO: Remove LVM PVs in current VG
|
||||
else if (p.first == QString() && !LvmDevice::s_DirtyPVs.contains(p.second)) // TODO: Remove LVM PVs in current VG
|
||||
dialogWidget().listPV().addPartition(*p.second, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class ResizeVolumeGroupDialog : public VolumeGroupDialog
|
|||
Q_DISABLE_COPY(ResizeVolumeGroupDialog)
|
||||
|
||||
public:
|
||||
ResizeVolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& partList, VolumeManagerDevice& d, FS::lvm2_pv::PhysicalVolumes physicalVolumes);
|
||||
ResizeVolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& partList, VolumeManagerDevice& d, FS::lvm2_pv::PhysicalVolumes physicalVolumes);
|
||||
|
||||
protected:
|
||||
void accept() override;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
@param vgName Volume Group name
|
||||
@param pvList List of LVM Physical Volumes used to create Volume Group
|
||||
*/
|
||||
VolumeGroupDialog::VolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& pvList) :
|
||||
VolumeGroupDialog::VolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& pvList) :
|
||||
QDialog(parent),
|
||||
m_DialogWidget(new VolumeGroupWidget(this)),
|
||||
m_TargetName(vgName),
|
||||
|
@ -140,8 +140,11 @@ void VolumeGroupDialog::updateSectorInfos()
|
|||
|
||||
void VolumeGroupDialog::updateSizeInfos()
|
||||
{
|
||||
QStringList checkedPartitions = dialogWidget().listPV().checkedItems();
|
||||
m_TotalSize = FS::lvm2_pv::getPVSize(checkedPartitions);
|
||||
const QList <const Partition *> checkedPartitions = dialogWidget().listPV().checkedItems();
|
||||
m_TotalSize = 0;
|
||||
for (const auto &p : checkedPartitions)
|
||||
m_TotalSize += p->capacity() - p->capacity() % (dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Byte, Capacity::MiB)); // subtract space which is too small to hold PE
|
||||
|
||||
dialogWidget().totalSize().setText(Capacity::formatByteSize(m_TotalSize));
|
||||
|
||||
//Probably a bad design for updating state here; the state should be changed inside the update button function.
|
||||
|
|
|
@ -32,7 +32,7 @@ class VolumeGroupDialog : public QDialog
|
|||
Q_DISABLE_COPY(VolumeGroupDialog)
|
||||
|
||||
public:
|
||||
VolumeGroupDialog(QWidget* parent, QString& vgName, QStringList& pvList);
|
||||
VolumeGroupDialog(QWidget* parent, QString& vgName, QList<const Partition*>& pvList);
|
||||
~VolumeGroupDialog();
|
||||
|
||||
protected:
|
||||
|
@ -64,11 +64,11 @@ protected:
|
|||
return m_TargetName;
|
||||
}
|
||||
|
||||
QStringList& targetPVList() {
|
||||
QList<const Partition*>& targetPVList() {
|
||||
return m_TargetPVList;
|
||||
}
|
||||
|
||||
const QStringList& targetPVList() const {
|
||||
const QList<const Partition*>& targetPVList() const {
|
||||
return m_TargetPVList;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ protected:
|
|||
protected:
|
||||
VolumeGroupWidget* m_DialogWidget;
|
||||
QString& m_TargetName;
|
||||
QStringList& m_TargetPVList;
|
||||
QList<const Partition*>& m_TargetPVList;
|
||||
bool m_IsValidSize;
|
||||
bool m_IsValidName;
|
||||
|
||||
|
|
Loading…
Reference in New Issue