Clang: fix warnings on partition splitter

- initialize all the fields
 - member-initialization order
 - silence warnings about double<->int
 - drop unused parameter to setSplitPartition
This commit is contained in:
Adriaan de Groot 2017-09-08 07:50:09 -04:00
parent 3aa540a69e
commit 31fa9e4251
3 changed files with 18 additions and 16 deletions

View File

@ -474,8 +474,7 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current,
part->partitionPath(), part->partitionPath(),
qRound64( part->used() * 1.1 ), qRound64( part->used() * 1.1 ),
part->capacity() - requiredStorageB, part->capacity() - requiredStorageB,
part->capacity() / 2, part->capacity() / 2 );
*Calamares::Branding::ProductName );
if ( m_isEfi ) if ( m_isEfi )
setupEfiSystemPartitionSelector(); setupEfiSystemPartitionSelector();

View File

@ -34,18 +34,18 @@
#include <QStyleOption> #include <QStyleOption>
static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts
(int)( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts
static const int CORNER_RADIUS = 3; static const int CORNER_RADIUS = 3;
static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 ); static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 );
PartitionSplitterWidget::PartitionSplitterWidget( QWidget* parent ) PartitionSplitterWidget::PartitionSplitterWidget( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, m_resizing( false )
, m_itemToResize( PartitionSplitterItem::null() ) , m_itemToResize( PartitionSplitterItem::null() )
, m_itemToResizeNext( PartitionSplitterItem::null() ) , m_itemToResizeNext( PartitionSplitterItem::null() )
, m_itemMinSize( 0 ) , m_itemMinSize( 0 )
, m_itemMaxSize( 0 ) , m_itemMaxSize( 0 )
, m_itemPrefSize( 0 ) , m_itemPrefSize( 0 )
, m_resizing( false )
, m_resizeHandleX( 0 ) , m_resizeHandleX( 0 )
, HANDLE_SNAP( QApplication::startDragDistance() ) , HANDLE_SNAP( QApplication::startDragDistance() )
, m_drawNestedPartitions( false ) , m_drawNestedPartitions( false )
@ -114,8 +114,7 @@ void
PartitionSplitterWidget::setSplitPartition( const QString& path, PartitionSplitterWidget::setSplitPartition( const QString& path,
qint64 minSize, qint64 minSize,
qint64 maxSize, qint64 maxSize,
qint64 preferredSize, qint64 preferredSize )
const QString& newLabel )
{ {
cDebug() << Q_FUNC_INFO << "path:" << path cDebug() << Q_FUNC_INFO << "path:" << path
<< "\nminSize:" << minSize << "\nminSize:" << minSize
@ -287,6 +286,8 @@ PartitionSplitterWidget::minimumSizeHint() const
void void
PartitionSplitterWidget::paintEvent( QPaintEvent* event ) PartitionSplitterWidget::paintEvent( QPaintEvent* event )
{ {
Q_UNUSED( event );
QPainter painter( this ); QPainter painter( this );
painter.fillRect( rect(), palette().window() ); painter.fillRect( rect(), palette().window() );
painter.setRenderHint( QPainter::Antialiasing ); painter.setRenderHint( QPainter::Antialiasing );
@ -400,6 +401,8 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
void void
PartitionSplitterWidget::mouseReleaseEvent( QMouseEvent* event ) PartitionSplitterWidget::mouseReleaseEvent( QMouseEvent* event )
{ {
Q_UNUSED( event );
m_resizing = false; m_resizing = false;
} }
@ -491,7 +494,7 @@ PartitionSplitterWidget::drawResizeHandle( QPainter* painter,
painter->setRenderHint( QPainter::Antialiasing, false ); painter->setRenderHint( QPainter::Antialiasing, false );
painter->setPen( Qt::black ); painter->setPen( Qt::black );
painter->drawLine( x, 0, x, h - 1 ); painter->drawLine( x, 0, x, int(h) - 1 );
} }
@ -511,20 +514,20 @@ PartitionSplitterWidget::drawPartitions( QPainter* painter,
for ( int row = 0; row < count; ++row ) for ( int row = 0; row < count; ++row )
{ {
const PartitionSplitterItem& item = items[ row ]; const PartitionSplitterItem& item = items[ row ];
int width; qreal width;
if ( row < count - 1 ) if ( row < count - 1 )
width = totalWidth * ( item.size / total ); width = totalWidth * ( item.size / total );
else else
// Make sure we fill the last pixel column // Make sure we fill the last pixel column
width = rect.right() - x + 1; width = rect.right() - x + 1;
drawSection( painter, rect, x, width, item ); drawSection( painter, rect, x, int(width), item );
if ( !item.children.isEmpty() ) if ( !item.children.isEmpty() )
{ {
QRect subRect( QRect subRect(
x + EXTENDED_PARTITION_MARGIN, x + EXTENDED_PARTITION_MARGIN,
rect.y() + EXTENDED_PARTITION_MARGIN, rect.y() + EXTENDED_PARTITION_MARGIN,
width - 2 * EXTENDED_PARTITION_MARGIN, int(width) - 2 * EXTENDED_PARTITION_MARGIN,
rect.height() - 2 * EXTENDED_PARTITION_MARGIN rect.height() - 2 * EXTENDED_PARTITION_MARGIN
); );
drawPartitions( painter, subRect, item.children ); drawPartitions( painter, subRect, item.children );
@ -600,7 +603,7 @@ PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterIte
PartitionSplitterItem thisItem = originalItems[ row ]; PartitionSplitterItem thisItem = originalItems[ row ];
QPair< QVector< PartitionSplitterItem >, qreal > pair = computeItemsVector( thisItem.children ); QPair< QVector< PartitionSplitterItem >, qreal > pair = computeItemsVector( thisItem.children );
thisItem.children = pair.first; thisItem.children = pair.first;
thisItem.size = pair.second; thisItem.size = qint64(pair.second);
items += thisItem; items += thisItem;
total += thisItem.size; total += thisItem.size;
} }
@ -614,7 +617,7 @@ PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterIte
if ( items[ row ].size < 0.01 * total ) // If this item is smaller than 1% of everything, if ( items[ row ].size < 0.01 * total ) // If this item is smaller than 1% of everything,
{ // force its width to 1%. { // force its width to 1%.
adjustedTotal -= items[ row ].size; adjustedTotal -= items[ row ].size;
items[ row ].size = 0.01 * total; items[ row ].size = qint64(0.01 * total);
adjustedTotal += items[ row ].size; adjustedTotal += items[ row ].size;
} }
} }

View File

@ -40,9 +40,10 @@ struct PartitionSplitterItem
qint64 size; qint64 size;
Status status; Status status;
QVector< PartitionSplitterItem > children; using ChildVector = QVector< PartitionSplitterItem >;
ChildVector children;
static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal }; } static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal, ChildVector() }; }
bool isNull() const { return itemPath.isEmpty() && size == 0 && status == Normal; } bool isNull() const { return itemPath.isEmpty() && size == 0 && status == Normal; }
operator bool() const { return !isNull(); } operator bool() const { return !isNull(); }
@ -59,8 +60,7 @@ public:
void setSplitPartition( const QString& path, void setSplitPartition( const QString& path,
qint64 minSize, qint64 minSize,
qint64 maxSize, qint64 maxSize,
qint64 preferredSize, qint64 preferredSize );
const QString& newLabel );
qint64 splitPartitionSize() const; qint64 splitPartitionSize() const;
qint64 newPartitionSize() const; qint64 newPartitionSize() const;