From 17e6c32633ebc373f02d981cbf781674e93d8061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 11 Sep 2017 13:41:03 +0100 Subject: [PATCH] Fix more implicit type conversion warnings. --- src/core/copysource.h | 2 +- src/core/copysourcedevice.cpp | 2 +- src/core/copysourcedevice.h | 2 +- src/core/copysourcefile.cpp | 2 +- src/core/copysourcefile.h | 6 ++--- src/core/copysourceshred.cpp | 2 +- src/core/copysourceshred.h | 6 ++--- src/core/copytarget.h | 2 +- src/core/copytargetdevice.cpp | 2 +- src/core/copytargetdevice.h | 2 +- src/core/copytargetfile.cpp | 2 +- src/core/copytargetfile.h | 6 ++--- src/core/device.cpp | 2 +- src/core/device.h | 6 ++--- src/core/diskdevice.cpp | 4 ++-- src/core/diskdevice.h | 10 ++++----- src/core/lvmdevice.cpp | 4 ++-- src/core/partition.h | 4 ++-- src/core/partitiontable.h | 4 ++-- src/core/smartattribute.cpp | 4 ++-- src/core/smartstatus.cpp | 10 ++++----- src/core/smartstatus.h | 26 +++++++++++----------- src/core/volumemanagerdevice.cpp | 2 +- src/core/volumemanagerdevice.h | 2 +- src/fs/fat16.cpp | 4 ++-- src/fs/fat32.cpp | 4 ++-- src/fs/luks.cpp | 2 +- src/gui/partresizerwidget.cpp | 16 +++++++------ src/gui/partwidget.cpp | 2 +- src/gui/partwidgetbase.cpp | 4 ++-- src/gui/partwidgetbase.h | 3 +++ src/plugins/libparted/libpartedbackend.cpp | 22 +++++++++--------- 32 files changed, 88 insertions(+), 83 deletions(-) diff --git a/src/core/copysource.h b/src/core/copysource.h index baa8378..2faa185 100644 --- a/src/core/copysource.h +++ b/src/core/copysource.h @@ -41,7 +41,7 @@ protected: public: virtual bool open() = 0; - virtual qint32 sectorSize() const = 0; + virtual qint64 sectorSize() const = 0; virtual bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) = 0; virtual qint64 length() const = 0; virtual bool overlaps(const CopyTarget& target) const = 0; diff --git a/src/core/copysourcedevice.cpp b/src/core/copysourcedevice.cpp index d147429..cb41ccb 100644 --- a/src/core/copysourcedevice.cpp +++ b/src/core/copysourcedevice.cpp @@ -58,7 +58,7 @@ bool CopySourceDevice::open() /** Returns the Device's sector size @return the sector size */ -qint32 CopySourceDevice::sectorSize() const +qint64 CopySourceDevice::sectorSize() const { return device().logicalSize(); } diff --git a/src/core/copysourcedevice.h b/src/core/copysourcedevice.h index d5581b7..2352140 100644 --- a/src/core/copysourcedevice.h +++ b/src/core/copysourcedevice.h @@ -44,7 +44,7 @@ public: public: bool open() override; - qint32 sectorSize() const override; + qint64 sectorSize() const override; bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; qint64 length() const override; bool overlaps(const CopyTarget& target) const override; diff --git a/src/core/copysourcefile.cpp b/src/core/copysourcefile.cpp index 0414b8c..d8ceff4 100644 --- a/src/core/copysourcefile.cpp +++ b/src/core/copysourcefile.cpp @@ -25,7 +25,7 @@ @param filename filename of the file to copy from @param sectorsize the sector size to assume for the file, usually the target Device's sector size */ -CopySourceFile::CopySourceFile(const QString& filename, qint32 sectorsize) : +CopySourceFile::CopySourceFile(const QString& filename, qint64 sectorsize) : CopySource(), m_File(filename), m_SectorSize(sectorsize) diff --git a/src/core/copysourcefile.h b/src/core/copysourcefile.h index e0a8dba..5baf7d9 100644 --- a/src/core/copysourcefile.h +++ b/src/core/copysourcefile.h @@ -36,14 +36,14 @@ class CopyTarget; class CopySourceFile : public CopySource { public: - CopySourceFile(const QString& filename, qint32 sectorsize); + CopySourceFile(const QString& filename, qint64 sectorsize); public: bool open() override; bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; qint64 length() const override; - qint32 sectorSize() const override { + qint64 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } bool overlaps(const CopyTarget&) const override { @@ -66,7 +66,7 @@ protected: protected: QFile m_File; - qint32 m_SectorSize; + qint64 m_SectorSize; }; #endif diff --git a/src/core/copysourceshred.cpp b/src/core/copysourceshred.cpp index fd35c54..1672f4c 100644 --- a/src/core/copysourceshred.cpp +++ b/src/core/copysourceshred.cpp @@ -22,7 +22,7 @@ @param s the size the copy source will (pretend to) have @param sectorsize the sectorsize the copy source will (pretend to) have */ -CopySourceShred::CopySourceShred(qint64 s, qint32 sectorsize, bool randomShred) : +CopySourceShred::CopySourceShred(qint64 s, qint64 sectorsize, bool randomShred) : CopySource(), m_Size(s), m_SectorSize(sectorsize), diff --git a/src/core/copysourceshred.h b/src/core/copysourceshred.h index 43bc09d..e22f21d 100644 --- a/src/core/copysourceshred.h +++ b/src/core/copysourceshred.h @@ -34,14 +34,14 @@ class CopyTarget; class CopySourceShred : public CopySource { public: - CopySourceShred(qint64 size, qint32 sectorsize, bool randomShred); + CopySourceShred(qint64 size, qint64 sectorsize, bool randomShred); public: bool open() override; bool readSectors(void* buffer, qint64 readOffset, qint64 numSectors) override; qint64 length() const override; - qint32 sectorSize() const override { + qint64 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } bool overlaps(const CopyTarget&) const override { @@ -67,7 +67,7 @@ protected: private: qint64 m_Size; - qint32 m_SectorSize; + qint64 m_SectorSize; QFile m_SourceFile; }; diff --git a/src/core/copytarget.h b/src/core/copytarget.h index 5c3cd98..0847bff 100644 --- a/src/core/copytarget.h +++ b/src/core/copytarget.h @@ -40,7 +40,7 @@ protected: public: virtual bool open() = 0; - virtual qint32 sectorSize() const = 0; + virtual qint64 sectorSize() const = 0; virtual bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) = 0; virtual qint64 firstSector() const = 0; virtual qint64 lastSector() const = 0; diff --git a/src/core/copytargetdevice.cpp b/src/core/copytargetdevice.cpp index b53004a..1ca1b38 100644 --- a/src/core/copytargetdevice.cpp +++ b/src/core/copytargetdevice.cpp @@ -54,7 +54,7 @@ bool CopyTargetDevice::open() } /** @return the Device's sector size */ -qint32 CopyTargetDevice::sectorSize() const +qint64 CopyTargetDevice::sectorSize() const { return device().logicalSize(); } diff --git a/src/core/copytargetdevice.h b/src/core/copytargetdevice.h index 8042f3c..c39cb04 100644 --- a/src/core/copytargetdevice.h +++ b/src/core/copytargetdevice.h @@ -46,7 +46,7 @@ public: public: bool open() override; - qint32 sectorSize() const override; + qint64 sectorSize() const override; bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) override; qint64 firstSector() const override { return m_FirstSector; /**< @return the first sector to write to */ diff --git a/src/core/copytargetfile.cpp b/src/core/copytargetfile.cpp index 64f6470..1b016e3 100644 --- a/src/core/copytargetfile.cpp +++ b/src/core/copytargetfile.cpp @@ -21,7 +21,7 @@ @param filename name of the file to write to @param sectorsize the "sector size" of the file to write to, usually the sector size of the CopySourceDevice */ -CopyTargetFile::CopyTargetFile(const QString& filename, qint32 sectorsize) : +CopyTargetFile::CopyTargetFile(const QString& filename, qint64 sectorsize) : CopyTarget(), m_File(filename), m_SectorSize(sectorsize) diff --git a/src/core/copytargetfile.h b/src/core/copytargetfile.h index 4a25f7c..e2b0f1b 100644 --- a/src/core/copytargetfile.h +++ b/src/core/copytargetfile.h @@ -36,13 +36,13 @@ class QString; class CopyTargetFile : public CopyTarget { public: - CopyTargetFile(const QString& filename, qint32 sectorsize); + CopyTargetFile(const QString& filename, qint64 sectorsize); public: bool open() override; bool writeSectors(void* buffer, qint64 writeOffset, qint64 numSectors) override; - qint32 sectorSize() const override { + qint64 sectorSize() const override { return m_SectorSize; /**< @return the file's sector size */ } qint64 firstSector() const override { @@ -62,7 +62,7 @@ protected: protected: QFile m_File; - qint32 m_SectorSize; + qint64 m_SectorSize; }; #endif diff --git a/src/core/device.cpp b/src/core/device.cpp index 0aa26ad..7e2c4a5 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -30,7 +30,7 @@ */ Device::Device(const QString& name, const QString& deviceNode, - const qint32 logicalSize, + const qint64 logicalSize, const qint64 totalLogical, const QString& iconName, Device::Type type) diff --git a/src/core/device.h b/src/core/device.h index 9553361..7a6968b 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -54,7 +54,7 @@ public: }; protected: - explicit Device(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); + explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); public: explicit Device(const Device& other); @@ -108,7 +108,7 @@ public: m_PartitionTable = ptable; } - virtual qint32 logicalSize() const { + virtual qint64 logicalSize() const { return m_LogicalSize; } @@ -125,7 +125,7 @@ public: protected: QString m_Name; QString m_DeviceNode; - qint32 m_LogicalSize; + qint64 m_LogicalSize; qint64 m_TotalLogical; PartitionTable* m_PartitionTable; QString m_IconName; diff --git a/src/core/diskdevice.cpp b/src/core/diskdevice.cpp index ebed401..6e6fac4 100644 --- a/src/core/diskdevice.cpp +++ b/src/core/diskdevice.cpp @@ -39,7 +39,7 @@ #define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */ #endif -static qint32 getPhysicalSectorSize(const QString& device_node) +static qint64 getPhysicalSectorSize(const QString& device_node) { /* * possible ways of getting the physical sector size for a drive: @@ -85,7 +85,7 @@ DiskDevice::DiskDevice(const QString& name, qint32 heads, qint32 numSectors, qint32 cylinders, - qint32 sectorSize, + qint64 sectorSize, const QString& iconName) : Device(name, deviceNode, sectorSize, (static_cast(heads) * cylinders * numSectors), iconName, Device::Disk_Device) , m_Heads(heads) diff --git a/src/core/diskdevice.h b/src/core/diskdevice.h index cd5002d..9c4a359 100644 --- a/src/core/diskdevice.h +++ b/src/core/diskdevice.h @@ -48,7 +48,7 @@ class LIBKPMCORE_EXPORT DiskDevice : public Device friend class CoreBackend; public: - DiskDevice(const QString& name, const QString& deviceNode, qint32 heads, qint32 numSectors, qint32 cylinders, qint32 sectorSize, const QString& iconName = QString()); + DiskDevice(const QString& name, const QString& deviceNode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconName = QString()); public: qint32 heads() const { @@ -60,10 +60,10 @@ public: qint32 sectorsPerTrack() const { return m_SectorsPerTrack; /**< @return the number of sectors on the Device in CHS notation */ } - qint32 physicalSectorSize() const { + qint64 physicalSectorSize() const { return m_PhysicalSectorSize; /**< @return the physical sector size the Device uses or -1 if unknown */ } - qint32 logicalSectorSize() const { + qint64 logicalSectorSize() const { return m_LogicalSectorSize; /**< @return the logical sector size the Device uses */ } qint64 totalSectors() const { @@ -77,8 +77,8 @@ private: qint32 m_Heads; qint32 m_SectorsPerTrack; qint32 m_Cylinders; - qint32 m_LogicalSectorSize; - qint32 m_PhysicalSectorSize; + qint64 m_LogicalSectorSize; + qint64 m_PhysicalSectorSize; }; #endif diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 6efe24e..fa7287b 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -147,7 +147,7 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl fs->setSectorsUsed( (storage.bytesTotal() - storage.bytesFree()) / logicalSize() ); } else if (fs->supportGetUsed() == FileSystem::cmdSupportFileSystem) - fs->setSectorsUsed(qCeil(fs->readUsedCapacity(lvPath) / static_cast(logicalSize()))); + fs->setSectorsUsed(qCeil(fs->readUsedCapacity(lvPath) / static_cast(logicalSize()))); } if (fs->supportGetLabel() != FileSystem::cmdSupportNone) { @@ -250,7 +250,7 @@ const QStringList LvmDevice::getLVs(const QString& vgName) qint64 LvmDevice::getPeSize(const QString& vgName) { QString val = getField(QStringLiteral("vg_extent_size"), vgName); - return val.isEmpty() ? -1 : val.toInt(); + return val.isEmpty() ? -1 : val.toLongLong(); } qint64 LvmDevice::getTotalPE(const QString& vgName) diff --git a/src/core/partition.h b/src/core/partition.h index ec67a18..0cd5e6d 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -162,7 +162,7 @@ public: return m_LastSector; /**< @return the Partition's last sector on the Device */ } qint64 sectorsUsed() const; - qint32 sectorSize() const { + qint64 sectorSize() const { return m_SectorSize; /**< @return the sector size on the Partition's Device */ } qint64 length() const { @@ -293,7 +293,7 @@ private: PartitionTable::Flags m_AvailableFlags; PartitionTable::Flags m_ActiveFlags; bool m_IsMounted; - qint32 m_SectorSize; + qint64 m_SectorSize; State m_State; }; diff --git a/src/core/partitiontable.h b/src/core/partitiontable.h index 49b887a..d0ba741 100644 --- a/src/core/partitiontable.h +++ b/src/core/partitiontable.h @@ -134,8 +134,8 @@ public: PartitionRole::Roles childRoles(const Partition& p) const; - int numPrimaries() const; - int maxPrimaries() const { + qint32 numPrimaries() const; + qint32 maxPrimaries() const { return m_MaxPrimaries; /**< @return max number of primary partitions this PartitionTable can handle */ } diff --git a/src/core/smartattribute.cpp b/src/core/smartattribute.cpp index bec3c40..0346bcb 100644 --- a/src/core/smartattribute.cpp +++ b/src/core/smartattribute.cpp @@ -28,7 +28,7 @@ static QString getAttrName(qint32 id); static QString getAttrDescription(qint32 id); -static QString getPrettyValue(qint64 value, qint64 unit); +static QString getPrettyValue(quint64 value, qint64 unit); static SmartAttribute::Assessment getAssessment(const SkSmartAttributeParsedData* a); static QString getRaw(const uint8_t*); @@ -68,7 +68,7 @@ QString SmartAttribute::assessmentToString(Assessment a) } } -static QString getPrettyValue(qint64 value, qint64 unit) +static QString getPrettyValue(quint64 value, qint64 unit) { QString rval; diff --git a/src/core/smartstatus.cpp b/src/core/smartstatus.cpp index 4e121c4..2a7c280 100644 --- a/src/core/smartstatus.cpp +++ b/src/core/smartstatus.cpp @@ -36,10 +36,10 @@ SmartStatus::SmartStatus(const QString& device_path) : m_Firmware(), m_Overall(Bad), m_SelfTestStatus(Success), - m_Temp(-99), - m_BadSectors(-99), - m_PowerCycles(-99), - m_PoweredOn(-99) + m_Temp(0), + m_BadSectors(0), + m_PowerCycles(0), + m_PoweredOn(0) { update(); } @@ -191,7 +191,7 @@ void SmartStatus::update() setInitSuccess(true); } -QString SmartStatus::tempToString(qint64 mkelvin) +QString SmartStatus::tempToString(quint64 mkelvin) { const double celsius = (mkelvin - 273150.0) / 1000.0; const double fahrenheit = 9.0 * celsius / 5.0 + 32; diff --git a/src/core/smartstatus.h b/src/core/smartstatus.h index 29e44dd..c68a0ca 100644 --- a/src/core/smartstatus.h +++ b/src/core/smartstatus.h @@ -81,16 +81,16 @@ public: const QString& firmware() const { return m_Firmware; } - qint64 temp() const { + quint64 temp() const { return m_Temp; } - qint64 badSectors() const { + quint64 badSectors() const { return m_BadSectors; } - qint64 powerCycles() const { + quint64 powerCycles() const { return m_PowerCycles; } - qint64 poweredOn() const { + quint64 poweredOn() const { return m_PoweredOn; } const Attributes& attributes() const { @@ -103,7 +103,7 @@ public: return m_SelfTestStatus; } - static QString tempToString(qint64 mkelvin); + static QString tempToString(quint64 mkelvin); static QString overallAssessmentToString(Overall o); static QString selfTestStatusToString(SmartStatus::SelfTestStatus s); @@ -120,19 +120,19 @@ protected: void setFirmware(const QString& f) { m_Firmware = f; } - void setTemp(qint64 t) { + void setTemp(quint64 t) { m_Temp = t; } void setInitSuccess(bool b) { m_InitSuccess = b; } - void setBadSectors(qint64 s) { + void setBadSectors(quint64 s) { m_BadSectors = s; } - void setPowerCycles(qint64 p) { + void setPowerCycles(quint64 p) { m_PowerCycles = p; } - void setPoweredOn(qint64 t) { + void setPoweredOn(quint64 t) { m_PoweredOn = t; } void setOverall(Overall o) { @@ -153,10 +153,10 @@ private: QString m_Firmware; Overall m_Overall; SelfTestStatus m_SelfTestStatus; - qint64 m_Temp; - qint64 m_BadSectors; - qint64 m_PowerCycles; - qint64 m_PoweredOn; + quint64 m_Temp; + quint64 m_BadSectors; + quint64 m_PowerCycles; + quint64 m_PoweredOn; Attributes m_Attributes; }; diff --git a/src/core/volumemanagerdevice.cpp b/src/core/volumemanagerdevice.cpp index 6210b83..8c996cf 100644 --- a/src/core/volumemanagerdevice.cpp +++ b/src/core/volumemanagerdevice.cpp @@ -22,7 +22,7 @@ */ VolumeManagerDevice::VolumeManagerDevice(const QString& name, const QString& deviceNode, - const qint32 logicalSize, + const qint64 logicalSize, const qint64 totalLogical, const QString& iconName, Device::Type type) diff --git a/src/core/volumemanagerdevice.h b/src/core/volumemanagerdevice.h index e4e43b0..db4272e 100644 --- a/src/core/volumemanagerdevice.h +++ b/src/core/volumemanagerdevice.h @@ -42,7 +42,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device public: - VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); + VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); /** * @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1) diff --git a/src/fs/fat16.cpp b/src/fs/fat16.cpp index 4d0e445..b5bbb91 100644 --- a/src/fs/fat16.cpp +++ b/src/fs/fat16.cpp @@ -159,11 +159,11 @@ bool fat16::create(Report& report, const QString& deviceNode) bool fat16::updateUUID(Report& report, const QString& deviceNode) const { - qint32 t = time(nullptr); + qint64 t = time(nullptr); char uuid[4]; for (auto &u : uuid) { - u = t & 0xff; + u = static_cast(t & 0xff); t >>= 8; } diff --git a/src/fs/fat32.cpp b/src/fs/fat32.cpp index 14e93be..583c528 100644 --- a/src/fs/fat32.cpp +++ b/src/fs/fat32.cpp @@ -48,11 +48,11 @@ bool fat32::create(Report& report, const QString& deviceNode) bool fat32::updateUUID(Report& report, const QString& deviceNode) const { - qint32 t = time(nullptr); + qint64 t = time(nullptr); char uuid[4]; for (auto &u : uuid) { - u = t & 0xff; + u = static_cast(t & 0xff); t >>= 8; } diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index 0796487..a80cf01 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -337,7 +337,7 @@ void luks::loadInnerFileSystem(const QString& mapperNode) setLabel(m_innerFs->readLabel(mapperNode)); setUUID(m_innerFs->readUUID(mapperNode)); if (m_innerFs->supportGetUsed() == FileSystem::cmdSupportFileSystem) - setSectorsUsed(std::ceil((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / static_cast(sectorSize()) )); + setSectorsUsed(static_cast(std::ceil((m_innerFs->readUsedCapacity(mapperNode) + payloadOffset()) / static_cast(sectorSize()) ))); m_innerFs->scan(mapperNode); } diff --git a/src/gui/partresizerwidget.cpp b/src/gui/partresizerwidget.cpp index eb4d4d9..662b0b5 100644 --- a/src/gui/partresizerwidget.cpp +++ b/src/gui/partresizerwidget.cpp @@ -25,6 +25,8 @@ #include "fs/filesystem.h" +#include + #include #include #include @@ -80,8 +82,8 @@ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 ma setReadOnly(read_only); setMoveAllowed(move_allowed); - setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors())); - setMaximumLength(qMin(totalSectors(), partition().maximumSectors())); + setMinimumLength(std::max(partition().sectorsUsed(), partition().minimumSectors())); + setMaximumLength(std::min(totalSectors(), partition().maximumSectors())); // set margins to accommodate to top/bottom button asymmetric layouts QStyleOptionButton bOpt; @@ -142,12 +144,12 @@ long double PartResizerWidget::sectorsPerPixel() const int PartResizerWidget::partWidgetStart() const { - return handleWidth() + (partition().firstSector() - minimumFirstSector()) / sectorsPerPixel(); + return static_cast(handleWidth() + (partition().firstSector() - minimumFirstSector()) / sectorsPerPixel()); } int PartResizerWidget::partWidgetWidth() const { - return partition().length() / sectorsPerPixel(); + return static_cast(partition().length() / sectorsPerPixel()); } void PartResizerWidget::updatePositions() @@ -287,13 +289,13 @@ void PartResizerWidget::mouseMoveEvent(QMouseEvent* event) int x = event->pos().x() - m_Hotspot; if (draggedWidget() == &leftHandle()) { - const qint64 newFirstSector = qMax(minimumFirstSector() + x * sectorsPerPixel(), 0.0L); + const qint64 newFirstSector = static_cast(std::max(minimumFirstSector() + x * sectorsPerPixel(), 0.0L)); updateFirstSector(newFirstSector); } else if (draggedWidget() == &rightHandle()) { - const qint64 newLastSector = qMin(static_cast(minimumFirstSector() + (x - rightHandle().width()) * sectorsPerPixel()), maximumLastSector()); + const qint64 newLastSector = static_cast(std::min(static_cast(minimumFirstSector() + (x - rightHandle().width()) * sectorsPerPixel()), maximumLastSector())); updateLastSector(newLastSector); } else if (draggedWidget() == &partWidget() && moveAllowed()) { - const qint64 newFirstSector = qMax(minimumFirstSector() + (x - handleWidth()) * sectorsPerPixel(), 0.0L); + const qint64 newFirstSector = static_cast(std::max(minimumFirstSector() + (x - handleWidth()) * sectorsPerPixel(), 0.0L)); movePartition(newFirstSector); } } diff --git a/src/gui/partwidget.cpp b/src/gui/partwidget.cpp index 53d9ce3..c73a1e1 100644 --- a/src/gui/partwidget.cpp +++ b/src/gui/partwidget.cpp @@ -93,7 +93,7 @@ void PartWidget::paintEvent(QPaintEvent*) if (partition() == nullptr) return; - const int usedPercentage = partition()->used() * 100 / partition()->capacity(); + const int usedPercentage = static_cast(partition()->used() * 100 / partition()->capacity()); const int w = width() * usedPercentage / 100; QPainter painter(this); diff --git a/src/gui/partwidgetbase.cpp b/src/gui/partwidgetbase.cpp index ccbec9b..599607b 100644 --- a/src/gui/partwidgetbase.cpp +++ b/src/gui/partwidgetbase.cpp @@ -83,7 +83,7 @@ bool levelChildrenWidths(QList& childrenWidth, const QList& minC // if we have adjusted one or more partitions (and not ALL of them, because in that // case, nothing will help us), go through the partitions again and reduce the // on screen widths of those big enough anyway - const qint32 reduce = ceil(1.0 * adjust / numReducable); + const qint32 reduce = static_cast(std::ceil(1.0 * adjust / numReducable)); for (qint32 i = 0; i < childrenWidth.size(); i++) if (childrenWidth[i] > minChildrenWidth[i]) childrenWidth[i] -= reduce; @@ -115,7 +115,7 @@ void PartWidgetBase::positionChildren(const QWidget* destWidget, const Partition // calculate unleveled width for each child and store it for (const auto &p : partitions) { - childrenWidth.append(p->length() * destWidgetWidth / totalLength); + childrenWidth.append(static_cast(p->length() * destWidgetWidth / totalLength)); // Calculate the minimum width for the widget. This is easy for primary and logical partitions: they // just have a fixed min width (configured in m_MinWidth). But for extended partitions things diff --git a/src/gui/partwidgetbase.h b/src/gui/partwidgetbase.h index 977b499..0d83222 100644 --- a/src/gui/partwidgetbase.h +++ b/src/gui/partwidgetbase.h @@ -30,6 +30,9 @@ class Partition; class PartWidget; class QWidget; +bool distributeLostPixels(QList& childrenWidth, qint32 lostPixels); +bool levelChildrenWidths(QList& childrenWidth, const QList& minChildrenWidth, const qint32 destWidgetWidth); + /** Base class for all widgets that need to position Partitions. @author Volker Lanz */ diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index ba8e914..99ad0d3 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -105,21 +105,21 @@ typedef struct _GPTDiskData GPTDiskData; @param d the Device in question @return the first sector usable by a Partition */ -static quint64 firstUsableSector(const Device& d) +static qint64 firstUsableSector(const Device& d) { PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData()); PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr; - quint64 rval = 0; + qint64 rval = 0; if (pedDisk) - rval = pedDisk->dev->bios_geom.sectors; + rval = static_cast(pedDisk->dev->bios_geom.sectors); if (pedDisk && strcmp(pedDisk->type->name, "gpt") == 0) { GPTDiskData* gpt_disk_data = reinterpret_cast(pedDisk->disk_specific); PedGeometry* geom = reinterpret_cast(&gpt_disk_data->data_area); if (geom) - rval = geom->start; + rval = static_cast(geom->start); else rval += 32; } @@ -133,16 +133,16 @@ static quint64 firstUsableSector(const Device& d) @param d the Device in question @return the last sector usable by a Partition */ -static quint64 lastUsableSector(const Device& d) +static qint64 lastUsableSector(const Device& d) { PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData()); PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr; - quint64 rval = 0; + qint64 rval = 0; if (pedDisk) - rval = static_cast< quint64 >( pedDisk->dev->bios_geom.sectors ) * - pedDisk->dev->bios_geom.heads * - pedDisk->dev->bios_geom.cylinders - 1; + rval = static_cast< qint64 >( pedDisk->dev->bios_geom.sectors ) * + static_cast< qint64 >( pedDisk->dev->bios_geom.heads ) * + static_cast< qint64 >( pedDisk->dev->bios_geom.cylinders - 1 ); if (pedDisk && strcmp(pedDisk->type->name, "gpt") == 0) { GPTDiskData* gpt_disk_data = reinterpret_cast(pedDisk->disk_specific); @@ -446,8 +446,8 @@ QList LibPartedBackend::scanDevices(bool excludeReadOnly) deviceNodes << deviceNode; } - quint32 totalDevices = deviceNodes.length(); - for (quint32 i = 0; i < totalDevices; ++i) { + int totalDevices = deviceNodes.length(); + for (int i = 0; i < totalDevices; ++i) { const QString deviceNode = deviceNodes[i]; emitScanProgress(deviceNode, i * 100 / totalDevices);