move the updateLength-code from the part resizer widget to SizeDialogBase
because that's where it's actually being used exclusively. don't update the spinbox value in SizeDialogBase::onFreeSpaceBefore/AfterChanged() because if we do that the user cannot enter values digit by digit anymore (we'll just overwrite what he entered after each keystroke) svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1119113
This commit is contained in:
parent
80cbafc7cb
commit
d08ce3ac78
|
@ -41,6 +41,7 @@ class InsertDialog;
|
||||||
class NewDialog;
|
class NewDialog;
|
||||||
class EditMountPointDialog;
|
class EditMountPointDialog;
|
||||||
class PartPropsDialog;
|
class PartPropsDialog;
|
||||||
|
class SizeDialogBase;
|
||||||
|
|
||||||
class CreateFileSystemOperation;
|
class CreateFileSystemOperation;
|
||||||
class RestoreOperation;
|
class RestoreOperation;
|
||||||
|
@ -86,6 +87,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode
|
||||||
friend class NewDialog;
|
friend class NewDialog;
|
||||||
friend class EditMountPointDialog;
|
friend class EditMountPointDialog;
|
||||||
friend class PartPropsDialog;
|
friend class PartPropsDialog;
|
||||||
|
friend class SizeDialogBase;
|
||||||
|
|
||||||
friend class CreateFileSystemOperation;
|
friend class CreateFileSystemOperation;
|
||||||
friend class RestoreOperation;
|
friend class RestoreOperation;
|
||||||
|
|
|
@ -155,7 +155,7 @@ void NewDialog::onFilesystemChanged(int idx)
|
||||||
|
|
||||||
setupConstraints();
|
setupConstraints();
|
||||||
|
|
||||||
dialogWidget().partResizerWidget().updateLength(partition().length());
|
updateLength(partition().length());
|
||||||
dialogWidget().partResizerWidget().update();
|
dialogWidget().partResizerWidget().update();
|
||||||
|
|
||||||
updateHideAndShow();
|
updateHideAndShow();
|
||||||
|
|
|
@ -410,69 +410,6 @@ bool PartResizerWidget::updateLastSector(qint64 newLastSector)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates the Partition's length
|
|
||||||
@param newLength the new length
|
|
||||||
@return true on success
|
|
||||||
*/
|
|
||||||
bool PartResizerWidget::updateLength(qint64 newLength)
|
|
||||||
{
|
|
||||||
newLength = qBound(minimumLength(), newLength, qMin(totalSectors(), maximumLength()));
|
|
||||||
|
|
||||||
if (newLength == partition().length())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const qint64 oldLength = partition().length();
|
|
||||||
qint64 delta = newLength - oldLength;
|
|
||||||
|
|
||||||
qint64 tmp = qMin(delta, maximumLastSector(align()) - partition().lastSector());
|
|
||||||
delta -= tmp;
|
|
||||||
|
|
||||||
if (tmp != 0)
|
|
||||||
{
|
|
||||||
qint64 newLastSector = partition().lastSector() + tmp;
|
|
||||||
|
|
||||||
if (align())
|
|
||||||
newLastSector = PartitionAlignment::alignedLastSector(device(), partition(), newLastSector, minimumLastSector(align()), maximumLastSector(align()), minimumLength(), maximumLength());
|
|
||||||
|
|
||||||
if (newLastSector != partition().lastSector())
|
|
||||||
{
|
|
||||||
partition().setLastSector(newLastSector);
|
|
||||||
partition().fileSystem().setLastSector(newLastSector);
|
|
||||||
|
|
||||||
emit lastSectorChanged(partition().lastSector());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = qMin(delta, partition().firstSector() - minimumFirstSector(align()));
|
|
||||||
delta -= tmp;
|
|
||||||
|
|
||||||
if (tmp != 0)
|
|
||||||
{
|
|
||||||
qint64 newFirstSector = partition().firstSector() - tmp;
|
|
||||||
|
|
||||||
if (align())
|
|
||||||
newFirstSector = PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector, minimumFirstSector(align()), maximumFirstSector(align()), minimumLength(), maximumLength());
|
|
||||||
|
|
||||||
if (newFirstSector != partition().firstSector())
|
|
||||||
{
|
|
||||||
partition().setFirstSector(newFirstSector);
|
|
||||||
partition().fileSystem().setFirstSector(newFirstSector);
|
|
||||||
|
|
||||||
emit firstSectorChanged(partition().firstSector());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (partition().length() != oldLength)
|
|
||||||
{
|
|
||||||
emit lengthChanged(partition().length());
|
|
||||||
updatePositions();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the minimum sectors the Partition can be long.
|
/** Sets the minimum sectors the Partition can be long.
|
||||||
@note This value can never be less than 0 and never be higher than totalSectors()
|
@note This value can never be less than 0 and never be higher than totalSectors()
|
||||||
@param s the new minimum length
|
@param s the new minimum length
|
||||||
|
|
|
@ -85,10 +85,8 @@ class PartResizerWidget : public QWidget
|
||||||
signals:
|
signals:
|
||||||
void firstSectorChanged(qint64);
|
void firstSectorChanged(qint64);
|
||||||
void lastSectorChanged(qint64);
|
void lastSectorChanged(qint64);
|
||||||
void lengthChanged(qint64);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool updateLength(qint64 newLength);
|
|
||||||
bool updateFirstSector(qint64 newFirstSector);
|
bool updateFirstSector(qint64 newFirstSector);
|
||||||
bool updateLastSector(qint64 newLastSector);
|
bool updateLastSector(qint64 newLastSector);
|
||||||
bool movePartition(qint64 newFirstSector);
|
bool movePartition(qint64 newFirstSector);
|
||||||
|
|
|
@ -38,8 +38,13 @@ class SizeDetailsWidget : public QWidget, public Ui::SizeDetailsWidgetBase
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QDoubleSpinBox& spinFirstSector() { Q_ASSERT(m_SpinFirstSector); return *m_SpinFirstSector; }
|
QDoubleSpinBox& spinFirstSector() { Q_ASSERT(m_SpinFirstSector); return *m_SpinFirstSector; }
|
||||||
|
const QDoubleSpinBox& spinFirstSector() const { Q_ASSERT(m_SpinFirstSector); return *m_SpinFirstSector; }
|
||||||
|
|
||||||
QDoubleSpinBox& spinLastSector() { Q_ASSERT(m_SpinLastSector); return *m_SpinLastSector; }
|
QDoubleSpinBox& spinLastSector() { Q_ASSERT(m_SpinLastSector); return *m_SpinLastSector; }
|
||||||
|
const QDoubleSpinBox& spinLastSector() const { Q_ASSERT(m_SpinLastSector); return *m_SpinLastSector; }
|
||||||
|
|
||||||
QCheckBox& checkAlign() { Q_ASSERT(m_CheckAlign); return *m_CheckAlign; }
|
QCheckBox& checkAlign() { Q_ASSERT(m_CheckAlign); return *m_CheckAlign; }
|
||||||
|
const QCheckBox& checkAlign() const { Q_ASSERT(m_CheckAlign); return *m_CheckAlign; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,8 +111,8 @@ void SizeDialogBase::setupConstraints()
|
||||||
if (!canShrink() && !canGrow())
|
if (!canShrink() && !canGrow())
|
||||||
dialogWidget().spinCapacity().setEnabled(false);
|
dialogWidget().spinCapacity().setEnabled(false);
|
||||||
|
|
||||||
dialogWidget().partResizerWidget().setMaximumFirstSector(partition().maxFirstSector());
|
dialogWidget().partResizerWidget().setMaximumFirstSector(maximumFirstSector());
|
||||||
dialogWidget().partResizerWidget().setMinimumLastSector(partition().minLastSector());
|
dialogWidget().partResizerWidget().setMinimumLastSector(minimumLastSector());
|
||||||
|
|
||||||
const qint64 totalCapacity = sectorsToDialogUnit(partition(), maximumLastSector() - minimumFirstSector() + 1);
|
const qint64 totalCapacity = sectorsToDialogUnit(partition(), maximumLastSector() - minimumFirstSector() + 1);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ void SizeDialogBase::setupConstraints()
|
||||||
detailsWidget().spinFirstSector().setRange(minimumFirstSector(), maximumLastSector());
|
detailsWidget().spinFirstSector().setRange(minimumFirstSector(), maximumLastSector());
|
||||||
detailsWidget().spinLastSector().setRange(minimumFirstSector(), maximumLastSector());
|
detailsWidget().spinLastSector().setRange(minimumFirstSector(), maximumLastSector());
|
||||||
|
|
||||||
onAlignToggled(detailsWidget().checkAlign().isChecked());
|
onAlignToggled(align());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SizeDialogBase::setupConnections()
|
void SizeDialogBase::setupConnections()
|
||||||
|
@ -212,17 +212,56 @@ void SizeDialogBase::updateLength(qint64 newLength)
|
||||||
dialogWidget().spinCapacity().blockSignals(state);
|
dialogWidget().spinCapacity().blockSignals(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Updates the Partition's length
|
||||||
|
@param newLength the new length
|
||||||
|
@return true on success
|
||||||
|
*/
|
||||||
void SizeDialogBase::onCapacityChanged(double newCapacity)
|
void SizeDialogBase::onCapacityChanged(double newCapacity)
|
||||||
{
|
{
|
||||||
const qint64 newLength = dialogUnitToSectors(partition(), newCapacity);
|
qint64 newLength = dialogUnitToSectors(partition(), newCapacity);
|
||||||
dialogWidget().partResizerWidget().updateLength(newLength);
|
|
||||||
|
newLength = qBound(minimumLength(), newLength, qMin(maximumLastSector() - minimumFirstSector() + 1, maximumLength()));
|
||||||
|
|
||||||
|
if (newLength == partition().length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const qint64 oldLength = partition().length();
|
||||||
|
// const qint64 oldCapacity = sectorsToDialogUnit(partition(), oldLength);
|
||||||
|
|
||||||
|
qint64 delta = newLength - oldLength;
|
||||||
|
|
||||||
|
qint64 tmp = qMin(delta, maximumLastSector() - partition().lastSector());
|
||||||
|
delta -= tmp;
|
||||||
|
|
||||||
|
if (tmp != 0)
|
||||||
|
{
|
||||||
|
qint64 newLastSector = partition().lastSector() + tmp;
|
||||||
|
|
||||||
|
if (align())
|
||||||
|
newLastSector = PartitionAlignment::alignedLastSector(device(), partition(), newLastSector, minimumLastSector(), maximumLastSector(), minimumLength(), maximumLength());
|
||||||
|
|
||||||
|
dialogWidget().partResizerWidget().updateLastSector(newLastSector);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = qMin(delta, partition().firstSector() - minimumFirstSector());
|
||||||
|
delta -= tmp;
|
||||||
|
|
||||||
|
if (tmp != 0)
|
||||||
|
{
|
||||||
|
qint64 newFirstSector = partition().firstSector() - tmp;
|
||||||
|
|
||||||
|
if (align())
|
||||||
|
newFirstSector = PartitionAlignment::alignedFirstSector(device(), partition(), newFirstSector, minimumFirstSector(), maximumFirstSector(), minimumLength(), maximumLength());
|
||||||
|
|
||||||
|
dialogWidget().partResizerWidget().updateFirstSector(newFirstSector);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SizeDialogBase::onFreeSpaceBeforeChanged(double newBefore)
|
void SizeDialogBase::onFreeSpaceBeforeChanged(double newBefore)
|
||||||
{
|
{
|
||||||
qint64 newFirstSector = minimumFirstSector() + dialogUnitToSectors(partition(), newBefore);
|
qint64 newFirstSector = minimumFirstSector() + dialogUnitToSectors(partition(), newBefore);
|
||||||
|
|
||||||
if (detailsWidget().checkAlign().isChecked())
|
if (align())
|
||||||
{
|
{
|
||||||
const qint64 oldBefore = sectorsToDialogUnit(partition(), partition().firstSector() - minimumFirstSector());
|
const qint64 oldBefore = sectorsToDialogUnit(partition(), partition().firstSector() - minimumFirstSector());
|
||||||
const qint64 deltaCorrection = newBefore > oldBefore ? PartitionAlignment::firstDelta(device(), partition(), newFirstSector) : 0;
|
const qint64 deltaCorrection = newBefore > oldBefore ? PartitionAlignment::firstDelta(device(), partition(), newFirstSector) : 0;
|
||||||
|
@ -232,20 +271,13 @@ void SizeDialogBase::onFreeSpaceBeforeChanged(double newBefore)
|
||||||
if (dialogWidget().partResizerWidget().movePartition(newFirstSector) ||
|
if (dialogWidget().partResizerWidget().movePartition(newFirstSector) ||
|
||||||
dialogWidget().partResizerWidget().updateFirstSector(newFirstSector))
|
dialogWidget().partResizerWidget().updateFirstSector(newFirstSector))
|
||||||
setDirty();
|
setDirty();
|
||||||
|
|
||||||
// In most cases the capacity free before the partition's first sector that we calculated
|
|
||||||
// above from newBefore will not exactly equal newBefore (due to rounding errors). So
|
|
||||||
// make sure to set the spin box to the actual value.
|
|
||||||
const bool state = dialogWidget().spinFreeBefore().blockSignals(true);
|
|
||||||
dialogWidget().spinFreeBefore().setValue(sectorsToDialogUnit(partition(), partition().firstSector() - minimumFirstSector()));
|
|
||||||
dialogWidget().spinFreeBefore().blockSignals(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SizeDialogBase::onFreeSpaceAfterChanged(double newAfter)
|
void SizeDialogBase::onFreeSpaceAfterChanged(double newAfter)
|
||||||
{
|
{
|
||||||
qint64 newLastSector = maximumLastSector() - dialogUnitToSectors(partition(), newAfter);
|
qint64 newLastSector = maximumLastSector() - dialogUnitToSectors(partition(), newAfter);
|
||||||
|
|
||||||
if (detailsWidget().checkAlign().isChecked())
|
if (align())
|
||||||
{
|
{
|
||||||
const double oldAfter = sectorsToDialogUnit(partition(), maximumLastSector() - partition().lastSector());
|
const double oldAfter = sectorsToDialogUnit(partition(), maximumLastSector() - partition().lastSector());
|
||||||
const qint64 deltaCorrection = newAfter > oldAfter ? PartitionAlignment::lastDelta(device(), partition(), newLastSector) : 0;
|
const qint64 deltaCorrection = newAfter > oldAfter ? PartitionAlignment::lastDelta(device(), partition(), newLastSector) : 0;
|
||||||
|
@ -257,10 +289,6 @@ void SizeDialogBase::onFreeSpaceAfterChanged(double newAfter)
|
||||||
if (dialogWidget().partResizerWidget().movePartition(newFirstSector) ||
|
if (dialogWidget().partResizerWidget().movePartition(newFirstSector) ||
|
||||||
dialogWidget().partResizerWidget().updateLastSector(newLastSector))
|
dialogWidget().partResizerWidget().updateLastSector(newLastSector))
|
||||||
setDirty();
|
setDirty();
|
||||||
|
|
||||||
const bool state = dialogWidget().spinFreeAfter().blockSignals(true);
|
|
||||||
dialogWidget().spinFreeAfter().setValue(sectorsToDialogUnit(partition(), maximumLastSector() - partition().lastSector()));
|
|
||||||
dialogWidget().spinFreeAfter().blockSignals(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PartitionTable& SizeDialogBase::partitionTable() const
|
const PartitionTable& SizeDialogBase::partitionTable() const
|
||||||
|
@ -269,3 +297,19 @@ const PartitionTable& SizeDialogBase::partitionTable() const
|
||||||
|
|
||||||
return *device().partitionTable();
|
return *device().partitionTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SizeDialogBase::align() const
|
||||||
|
{
|
||||||
|
return detailsWidget().checkAlign().isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 SizeDialogBase::minimumLastSector() const
|
||||||
|
{
|
||||||
|
return partition().minLastSector();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 SizeDialogBase::maximumFirstSector() const
|
||||||
|
{
|
||||||
|
return partition().maxFirstSector();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,10 @@ class SizeDialogBase : public KDialog
|
||||||
virtual void setDirty() {}
|
virtual void setDirty() {}
|
||||||
virtual void updateLength(qint64 newLength);
|
virtual void updateLength(qint64 newLength);
|
||||||
|
|
||||||
|
virtual bool align() const;
|
||||||
|
virtual qint64 minimumLastSector() const;
|
||||||
|
virtual qint64 maximumFirstSector() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onFirstSectorChanged(qint64 newFirst);
|
void onFirstSectorChanged(qint64 newFirst);
|
||||||
void onLastSectorChanged(qint64 newLast);
|
void onLastSectorChanged(qint64 newLast);
|
||||||
|
|
Loading…
Reference in New Issue