Fix compile warnings

This commit is contained in:
Jonas Kvinge
2020-04-23 21:08:28 +02:00
parent a303850341
commit 8da4c88fd3
54 changed files with 509 additions and 461 deletions

View File

@@ -108,11 +108,11 @@ void AutoExpandingTreeView::ItemDoubleClicked(const QModelIndex &idx) {
ignore_next_click_ = true;
if (add_on_double_click_) {
QMimeData *data = model()->mimeData(QModelIndexList() << idx);
if (MimeData *mime_data = qobject_cast<MimeData*>(data)) {
mime_data->from_doubleclick_ = true;
QMimeData *q_mimedata = model()->mimeData(QModelIndexList() << idx);
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->from_doubleclick_ = true;
}
emit AddToPlaylistSignal(data);
emit AddToPlaylistSignal(q_mimedata);
}
}
@@ -127,11 +127,11 @@ void AutoExpandingTreeView::mousePressEvent(QMouseEvent *event) {
//enqueue to playlist with middleClick
if (event->button() == Qt::MidButton) {
QMimeData *data = model()->mimeData(selectedIndexes());
if (MimeData *mime_data = qobject_cast<MimeData*>(data)) {
mime_data->enqueue_now_ = true;
QMimeData *q_mimedata = model()->mimeData(selectedIndexes());
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->enqueue_now_ = true;
}
emit AddToPlaylistSignal(data);
emit AddToPlaylistSignal(q_mimedata);
}
}

View File

@@ -158,24 +158,24 @@ void FileView::ChangeFilePathWithoutUndo(const QString &new_path) {
}
void FileView::ItemActivated(const QModelIndex &index) {
if (model_->isDir(index))
ChangeFilePath(model_->filePath(index));
void FileView::ItemActivated(const QModelIndex &idx) {
if (model_->isDir(idx))
ChangeFilePath(model_->filePath(idx));
}
void FileView::ItemDoubleClick(const QModelIndex &index) {
void FileView::ItemDoubleClick(const QModelIndex &idx) {
if (model_->isDir(index))
if (model_->isDir(idx))
return;
QString file_path = model_->filePath(index);
QString file_path = model_->filePath(idx);
MimeData *data = new MimeData;
data->from_doubleclick_ = true;
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
data->name_for_new_playlist_ = file_path;
MimeData *mimedata = new MimeData;
mimedata->from_doubleclick_ = true;
mimedata->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
mimedata->name_for_new_playlist_ = file_path;
emit AddToPlaylist(data);
emit AddToPlaylist(mimedata);
}

View File

@@ -74,8 +74,8 @@ class FileView : public QWidget {
void FileUp();
void FileHome();
void ChangeFilePath(const QString &new_path);
void ItemActivated(const QModelIndex &index);
void ItemDoubleClick(const QModelIndex &index);
void ItemActivated(const QModelIndex &idx);
void ItemDoubleClick(const QModelIndex &idx);
void Delete(const QStringList &filenames);
void DeleteFinished(const SongList &songs_with_errors);

View File

@@ -78,17 +78,17 @@ QList<QUrl> FileViewList::UrlListFromSelection() const {
MimeData *FileViewList::MimeDataFromSelection() const {
MimeData *data = new MimeData;
data->setUrls(UrlListFromSelection());
MimeData *mimedata = new MimeData;
mimedata->setUrls(UrlListFromSelection());
QList<QString> filenames = FilenamesFromSelection();
// if just one folder selected - use it's path as the new playlist's name
if (filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) {
if (filenames.first().length() > 20) {
data->name_for_new_playlist_ = QDir(filenames.first()).dirName();
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
}
else {
data->name_for_new_playlist_ = filenames.first();
mimedata->name_for_new_playlist_ = filenames.first();
}
}
// otherwise, use the current root path
@@ -97,18 +97,18 @@ MimeData *FileViewList::MimeDataFromSelection() const {
if (path.length() > 20) {
QFileInfo info(path);
if (info.isDir()) {
data->name_for_new_playlist_ = QDir(info.filePath()).dirName();
mimedata->name_for_new_playlist_ = QDir(info.filePath()).dirName();
}
else {
data->name_for_new_playlist_ = info.baseName();
mimedata->name_for_new_playlist_ = info.baseName();
}
}
else {
data->name_for_new_playlist_ = path;
mimedata->name_for_new_playlist_ = path;
}
}
return data;
return mimedata;
}
@@ -124,9 +124,11 @@ QStringList FileViewList::FilenamesFromSelection() const {
}
void FileViewList::LoadSlot() {
MimeData *data = MimeDataFromSelection();
data->clear_first_ = true;
emit AddToPlaylist(data);
MimeData *mimedata = MimeDataFromSelection();
mimedata->clear_first_ = true;
emit AddToPlaylist(mimedata);
}
void FileViewList::AddToPlaylistSlot() {
@@ -134,9 +136,11 @@ void FileViewList::AddToPlaylistSlot() {
}
void FileViewList::OpenInNewPlaylistSlot() {
MimeData *data = MimeDataFromSelection();
data->open_in_new_playlist_ = true;
emit AddToPlaylist(data);
MimeData *mimedata = MimeDataFromSelection();
mimedata->open_in_new_playlist_ = true;
emit AddToPlaylist(mimedata);
}
void FileViewList::CopyToCollectionSlot() {
@@ -175,10 +179,10 @@ void FileViewList::mousePressEvent(QMouseEvent *e) {
// we need to update the menu selection
menu_selection_ = selectionModel()->selection();
MimeData *data = new MimeData;
data->setUrls(UrlListFromSelection());
data->enqueue_now_ = true;
emit AddToPlaylist(data);
MimeData *mimedata = new MimeData;
mimedata->setUrls(UrlListFromSelection());
mimedata->enqueue_now_ = true;
emit AddToPlaylist(mimedata);
break;
}
default:

View File

@@ -46,11 +46,6 @@ class SystemTrayIcon;
class QDBusPendingCallWatcher;
#ifdef HAVE_DBUS
QDBusArgument& operator<< (QDBusArgument &arg, const QImage &image);
const QDBusArgument &operator>> (const QDBusArgument &arg, QImage &image);
#endif
class OSD : public QObject {
Q_OBJECT

View File

@@ -51,6 +51,9 @@
#ifdef HAVE_DBUS
QDBusArgument &operator<< (QDBusArgument &arg, const QImage &image);
const QDBusArgument &operator>> (const QDBusArgument &arg, QImage &image);
QDBusArgument &operator<<(QDBusArgument &arg, const QImage &image) {
if (image.isNull()) {

View File

@@ -40,24 +40,25 @@ THE SOFTWARE.
#include "core/iconloader.h"
class QSearchFieldPrivate : public QObject {
public:
QSearchFieldPrivate(QSearchField *searchField, QLineEdit *lineEdit, QToolButton *clearButton)
: QObject(searchField), lineEdit(lineEdit), clearButton(clearButton) {}
public:
QSearchFieldPrivate(QSearchField *searchField, QLineEdit *lineedit, QToolButton *clearbutton)
: QObject(searchField), lineedit_(lineedit), clearbutton_(clearbutton) {}
int lineEditFrameWidth() const {
return lineEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
return lineedit_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
}
int clearButtonPaddedWidth() const {
return clearButton->width() + lineEditFrameWidth() * 2;
return clearbutton_->width() + lineEditFrameWidth() * 2;
}
int clearButtonPaddedHeight() const {
return clearButton->height() + lineEditFrameWidth() * 2;
return clearbutton_->height() + lineEditFrameWidth() * 2;
}
QPointer<QLineEdit> lineEdit;
QPointer<QToolButton> clearButton;
QPointer<QLineEdit> lineedit_;
QPointer<QToolButton> clearbutton_;
};
QSearchField::QSearchField(QWidget *parent) : QWidget(parent) {
@@ -68,21 +69,21 @@ QSearchField::QSearchField(QWidget *parent) : QWidget(parent) {
connect(lineEdit, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(setText(QString)));
QToolButton *clearButton = new QToolButton(this);
QToolButton *clearbutton = new QToolButton(this);
QIcon clearIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
clearButton->setIcon(clearIcon);
clearButton->setIconSize(QSize(16, 16));
clearButton->setStyleSheet("border: none; padding: 0px;");
clearButton->resize(clearButton->sizeHint());
clearbutton->setIcon(clearIcon);
clearbutton->setIconSize(QSize(16, 16));
clearbutton->setStyleSheet("border: none; padding: 0px;");
clearbutton->resize(clearbutton->sizeHint());
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(clearbutton, SIGNAL(clicked()), this, SLOT(clear()));
pimpl = new QSearchFieldPrivate(this, lineEdit, clearButton);
pimpl = new QSearchFieldPrivate(this, lineEdit, clearbutton);
const int frame_width = lineEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
lineEdit->setStyleSheet(QString("QLineEdit { padding-left: %1px; } ").arg(clearButton->width()));
lineEdit->setStyleSheet(QString("QLineEdit { padding-left: %1px; } ").arg(clearbutton->width()));
const int width = frame_width + qMax(lineEdit->minimumSizeHint().width(), pimpl->clearButtonPaddedWidth());
const int height = frame_width + qMax(lineEdit->minimumSizeHint().height(), pimpl->clearButtonPaddedHeight());
lineEdit->setMinimumSize(width, height);
@@ -97,25 +98,27 @@ QSearchField::QSearchField(QWidget *parent) : QWidget(parent) {
void QSearchField::setText(const QString &text) {
Q_ASSERT(pimpl && pimpl->clearButton && pimpl->lineEdit);
if (!(pimpl && pimpl->clearButton && pimpl->lineEdit)) return;
if (text != this->text()) pimpl->lineEdit->setText(text);
Q_ASSERT(pimpl && pimpl->clearbutton_ && pimpl->lineedit_);
if (!(pimpl && pimpl->clearbutton_ && pimpl->lineedit_)) return;
if (text != this->text()) pimpl->lineedit_->setText(text);
}
void QSearchField::setPlaceholderText(const QString &text) {
Q_ASSERT(pimpl && pimpl->lineEdit);
if (!(pimpl && pimpl->lineEdit)) return;
pimpl->lineEdit->setPlaceholderText(text);
Q_ASSERT(pimpl && pimpl->lineedit_);
if (!(pimpl && pimpl->lineedit_)) return;
pimpl->lineedit_->setPlaceholderText(text);
}
QString QSearchField::placeholderText() const {
return pimpl->lineEdit->placeholderText();
return pimpl->lineedit_->placeholderText();
}
void QSearchField::setFocus(Qt::FocusReason reason) {
Q_ASSERT(pimpl && pimpl->lineEdit);
if (pimpl && pimpl->lineEdit) pimpl->lineEdit->setFocus(reason);
Q_ASSERT(pimpl && pimpl->lineedit_);
if (pimpl && pimpl->lineedit_) pimpl->lineedit_->setFocus(reason);
}
void QSearchField::setFocus() {
@@ -123,35 +126,47 @@ void QSearchField::setFocus() {
}
void QSearchField::clear() {
Q_ASSERT(pimpl && pimpl->lineEdit);
if (!(pimpl && pimpl->lineEdit)) return;
pimpl->lineEdit->clear();
Q_ASSERT(pimpl && pimpl->lineedit_);
if (!(pimpl && pimpl->lineedit_)) return;
pimpl->lineedit_->clear();
}
void QSearchField::selectAll() {
Q_ASSERT(pimpl && pimpl->lineEdit);
if (!(pimpl && pimpl->lineEdit)) return;
pimpl->lineEdit->selectAll();
Q_ASSERT(pimpl && pimpl->lineedit_);
if (!(pimpl && pimpl->lineedit_)) return;
pimpl->lineedit_->selectAll();
}
QString QSearchField::text() const {
Q_ASSERT(pimpl && pimpl->lineEdit);
if (!(pimpl && pimpl->lineEdit)) return QString();
return pimpl->lineEdit->text();
Q_ASSERT(pimpl && pimpl->lineedit_);
if (!(pimpl && pimpl->lineedit_)) return QString();
return pimpl->lineedit_->text();
}
void QSearchField::resizeEvent(QResizeEvent *resizeEvent) {
Q_ASSERT(pimpl && pimpl->clearButton && pimpl->lineEdit);
if (!(pimpl && pimpl->clearButton && pimpl->lineEdit)) return;
Q_ASSERT(pimpl && pimpl->clearbutton_ && pimpl->lineedit_);
if (!(pimpl && pimpl->clearbutton_ && pimpl->lineedit_)) return;
QWidget::resizeEvent(resizeEvent);
const int x = pimpl->lineEditFrameWidth();
const int y = (height() - pimpl->clearButton->height())/2;
pimpl->clearButton->move(x, y);
const int y = (height() - pimpl->clearbutton_->height())/2;
pimpl->clearbutton_->move(x, y);
}
bool QSearchField::eventFilter(QObject *o, QEvent *e) {
if (pimpl && pimpl->lineEdit && o == pimpl->lineEdit) {
if (pimpl && pimpl->lineedit_ && o == pimpl->lineedit_) {
// Forward some lineEdit events to QSearchField (only those we need for
// now, but some might be added later if needed)
switch (e->type()) {
@@ -164,4 +179,5 @@ bool QSearchField::eventFilter(QObject *o, QEvent *e) {
}
}
return QWidget::eventFilter(o, e);
}

View File

@@ -40,15 +40,14 @@
const int StretchHeaderView::kMinimumColumnWidth = 10;
const int StretchHeaderView::kMagicNumber = 0x502c950f;
StretchHeaderView::StretchHeaderView(Qt::Orientation orientation, QWidget* parent)
StretchHeaderView::StretchHeaderView(const Qt::Orientation orientation, QWidget *parent)
: QHeaderView(orientation, parent),
stretch_enabled_(false),
in_mouse_move_event_(false)
{
in_mouse_move_event_(false) {
connect(this, SIGNAL(sectionResized(int,int,int)), SLOT(SectionResized(int,int,int)));
}
void StretchHeaderView::setModel(QAbstractItemModel* model) {
void StretchHeaderView::setModel(QAbstractItemModel *model) {
QHeaderView::setModel(model);
@@ -113,7 +112,7 @@ void StretchHeaderView::UpdateWidths(const QList<int>& sections) {
}
void StretchHeaderView::HideSection(int logical) {
void StretchHeaderView::HideSection(const int logical) {
// Would this hide the last section?
bool all_hidden = true;
@@ -151,36 +150,41 @@ void StretchHeaderView::ShowSection(int logical) {
visible_count ++;
}
column_widths_[logical] =
visible_count == 0 ? 1.0 : 1.0 / visible_count;
column_widths_[logical] = visible_count == 0 ? 1.0 : 1.0 / visible_count;
NormaliseWidths();
UpdateWidths();
}
void StretchHeaderView::SetSectionHidden(int logical, bool hidden) {
void StretchHeaderView::SetSectionHidden(const int logical, const bool hidden) {
if (hidden) {
HideSection(logical);
}
else {
ShowSection(logical);
}
}
void StretchHeaderView::resizeEvent(QResizeEvent* event) {
void StretchHeaderView::resizeEvent(QResizeEvent *event) {
QHeaderView::resizeEvent(event);
if (!stretch_enabled_) return;
UpdateWidths();
}
void StretchHeaderView::mouseMoveEvent(QMouseEvent* e) {
void StretchHeaderView::mouseMoveEvent(QMouseEvent *e) {
in_mouse_move_event_ = true;
QHeaderView::mouseMoveEvent(e);
in_mouse_move_event_ = false;
}
void StretchHeaderView::SectionResized(int logical, int, int new_size) {
void StretchHeaderView::SectionResized(const int logical, const int, const int new_size) {
if (!stretch_enabled_) return;
@@ -210,7 +214,7 @@ void StretchHeaderView::ToggleStretchEnabled() {
SetStretchEnabled(!is_stretch_enabled());
}
void StretchHeaderView::SetStretchEnabled(bool enabled) {
void StretchHeaderView::SetStretchEnabled(const bool enabled) {
stretch_enabled_ = enabled;
@@ -230,7 +234,7 @@ void StretchHeaderView::SetStretchEnabled(bool enabled) {
}
void StretchHeaderView::SetColumnWidth(int logical, ColumnWidthType width) {
void StretchHeaderView::SetColumnWidth(const int logical, const ColumnWidthType width) {
if (!stretch_enabled_) return;
@@ -240,13 +244,14 @@ void StretchHeaderView::SetColumnWidth(int logical, ColumnWidthType width) {
for (int i=0 ; i<count() ; ++i)
if (!isSectionHidden(i) && i != logical)
other_columns << i;
NormaliseWidths(other_columns);
}
bool StretchHeaderView::RestoreState(const QByteArray& data) {
bool StretchHeaderView::RestoreState(const QByteArray &sdata) {
QDataStream s(data);
QDataStream s(sdata);
s.setVersion(QDataStream::Qt_5_6);
int magic_number = 0;

View File

@@ -39,32 +39,32 @@ class StretchHeaderView : public QHeaderView {
Q_OBJECT
public:
explicit StretchHeaderView(Qt::Orientation orientation, QWidget* parent = nullptr);
explicit StretchHeaderView(const Qt::Orientation orientation, QWidget* parent = nullptr);
typedef double ColumnWidthType;
static const int kMinimumColumnWidth;
static const int kMagicNumber;
void setModel(QAbstractItemModel* model);
void setModel(QAbstractItemModel *model);
// Serialises the proportional and actual column widths.
// Use these instead of QHeaderView::restoreState and QHeaderView::saveState to persist the proportional values directly and avoid floating point errors over time.
bool RestoreState(const QByteArray& data);
bool RestoreState(const QByteArray &sdata);
QByteArray SaveState() const;
// Hides a section and resizes all other sections to fill the gap. Does nothing if you try to hide the last section.
void HideSection(int logical);
void HideSection(const int logical);
// Shows a section and resizes all other sections to make room.
void ShowSection(int logical);
void ShowSection(const int logical);
// Calls either HideSection or ShowSection.
void SetSectionHidden(int logical, bool hidden);
void SetSectionHidden(const int logical, const bool hidden);
// Sets the width of the given column and resizes other columns appropriately.
// width is the proportion of the entire width from 0.0 to 1.0.
void SetColumnWidth(int logical, ColumnWidthType width);
void SetColumnWidth(const int logical, const ColumnWidthType width);
bool is_stretch_enabled() const { return stretch_enabled_; }
@@ -72,16 +72,16 @@ class StretchHeaderView : public QHeaderView {
// Changes the stretch mode. Enabling stretch mode will initialise the
// proportional column widths from the current state of the header.
void ToggleStretchEnabled();
void SetStretchEnabled(bool enabled);
void SetStretchEnabled(const bool enabled);
signals:
// Emitted when the stretch mode is changed.
void StretchEnabledChanged(bool enabled);
void StretchEnabledChanged(const bool enabled);
protected:
// QWidget
void mouseMoveEvent(QMouseEvent* e);
void resizeEvent(QResizeEvent* event);
void mouseMoveEvent(QMouseEvent *e);
void resizeEvent(QResizeEvent *event);
private:
// Scales column_widths_ values so the total is 1.0.
@@ -91,7 +91,7 @@ class StretchHeaderView : public QHeaderView {
void UpdateWidths(const QList<int>& sections = QList<int>());
private slots:
void SectionResized(int logical, int old_size, int new_size);
void SectionResized(const int logical, const int old_size, const int new_size);
private:
bool stretch_enabled_;