From 8c1aaed08aca17c5e155d73618dd8afbda48d7c3 Mon Sep 17 00:00:00 2001 From: J-Donald Tournier Date: Fri, 5 Jun 2020 14:11:44 +0100 Subject: [PATCH] Fix compiler warnings - Qt 5.15 has marked quite a few bits of their code as obsolete, which generated a lot of warnings. - warning about inaccuracies converting large ints to float. --- src/gui/dialog/dicom.cpp | 2 +- src/gui/dialog/file.cpp | 2 +- src/gui/dialog/list.cpp | 16 +++--- src/gui/dwi/render_frame.cpp | 3 +- src/gui/mrview/sync/enums.h | 60 ++++++++++---------- src/gui/mrview/tool/connectome/matrix_list.h | 8 +-- src/gui/mrview/tool/connectome/node_list.h | 4 +- src/gui/mrview/tool/odf/model.h | 8 +-- src/gui/mrview/tool/view.cpp | 10 ++-- src/gui/mrview/volume.cpp | 12 ++-- src/gui/mrview/window.cpp | 7 ++- 11 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/gui/dialog/dicom.cpp b/src/gui/dialog/dicom.cpp index bc9e856a68..cf93154255 100644 --- a/src/gui/dialog/dicom.cpp +++ b/src/gui/dialog/dicom.cpp @@ -103,7 +103,7 @@ namespace MR } Qt::ItemFlags flags (const QModelIndex& index) const { - if (!index.isValid()) return (0); + if (!index.isValid()) return {}; return (Qt::ItemIsEnabled | Qt::ItemIsSelectable); } diff --git a/src/gui/dialog/file.cpp b/src/gui/dialog/file.cpp index 94e61f4b4c..50949932db 100644 --- a/src/gui/dialog/file.cpp +++ b/src/gui/dialog/file.cpp @@ -24,7 +24,7 @@ #ifdef MRTRIX_MACOSX # define FILE_DIALOG_OPTIONS QFileDialog::DontUseNativeDialog #else -# define FILE_DIALOG_OPTIONS static_cast (0) +# define FILE_DIALOG_OPTIONS QFileDialog::Options() #endif namespace MR diff --git a/src/gui/dialog/list.cpp b/src/gui/dialog/list.cpp index 8a06c85001..ce5167d699 100644 --- a/src/gui/dialog/list.cpp +++ b/src/gui/dialog/list.cpp @@ -25,40 +25,40 @@ namespace MR QVariant TreeModel::data (const QModelIndex& index, int role) const { - if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) return QVariant(); + if (!index.isValid()) return {}; + if (role != Qt::DisplayRole) return {}; return static_cast (index.internalPointer())->data (index.column()); } Qt::ItemFlags TreeModel::flags (const QModelIndex& index) const { - if (!index.isValid()) return 0; + if (!index.isValid()) return {}; return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QVariant TreeModel::headerData (int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) return rootItem->data (section); - return QVariant(); + return {}; } QModelIndex TreeModel::index (int row, int column, const QModelIndex& parent) const { - if (!hasIndex (row, column, parent)) return QModelIndex(); + if (!hasIndex (row, column, parent)) return {}; TreeItem* parentItem; if (!parent.isValid()) parentItem = rootItem; else parentItem = static_cast (parent.internalPointer()); TreeItem* childItem = parentItem->child (row); if (childItem) return createIndex (row, column, childItem); - else return QModelIndex(); + else return {}; } QModelIndex TreeModel::parent (const QModelIndex& index) const { - if (!index.isValid()) return QModelIndex(); + if (!index.isValid()) return {}; TreeItem* childItem = static_cast (index.internalPointer()); TreeItem* parentItem = childItem->parent(); - if (parentItem == rootItem) return QModelIndex(); + if (parentItem == rootItem) return {}; return createIndex (parentItem->row(), 0, parentItem); } diff --git a/src/gui/dwi/render_frame.cpp b/src/gui/dwi/render_frame.cpp index 79ece8fe9b..1234742820 100644 --- a/src/gui/dwi/render_frame.cpp +++ b/src/gui/dwi/render_frame.cpp @@ -332,7 +332,8 @@ namespace MR void RenderFrame::wheelEvent (QWheelEvent* event) { - int scroll = event->delta() / 120; + QPoint pixels = event->pixelDelta(); + int scroll = pixels.isNull() ? event->angleDelta().y() / 120 : event->angleDelta().y(); for (int n = 0; n < scroll; n++) scale *= ScaleInc; for (int n = 0; n > scroll; n--) scale /= ScaleInc; update(); diff --git a/src/gui/mrview/sync/enums.h b/src/gui/mrview/sync/enums.h index 1c0508273c..476ae0599f 100644 --- a/src/gui/mrview/sync/enums.h +++ b/src/gui/mrview/sync/enums.h @@ -10,34 +10,34 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * For more details, see http://www.mrtrix.org/ -*/ -#ifndef __sync_enums_h__ -#define __sync_enums_h__ - -namespace MR -{ - namespace GUI - { - namespace MRView - { - namespace Sync - { - /** - * The type of message being sent between processes - */ - enum class MessageKey { - ConnectedID = 1, - SyncData = 2 //Data to be synced - }; - /** - * For MessageKey::SyncData. This is type of data being sent for syncronising - */ - enum class DataKey { - WindowFocus = 1 - }; - - } - } - } -} +*/ +#ifndef __sync_enums_h__ +#define __sync_enums_h__ + +namespace MR +{ + namespace GUI + { + namespace MRView + { + namespace Sync + { + /** + * The type of message being sent between processes + */ + enum class MessageKey { + ConnectedID = 1, + SyncData = 2 //Data to be synced + }; + /** + * For MessageKey::SyncData. This is type of data being sent for syncronising + */ + enum class DataKey { + WindowFocus = 1 + }; + + } + } + } +} #endif \ No newline at end of file diff --git a/src/gui/mrview/tool/connectome/matrix_list.h b/src/gui/mrview/tool/connectome/matrix_list.h index 950ccf9345..e67c598e73 100644 --- a/src/gui/mrview/tool/connectome/matrix_list.h +++ b/src/gui/mrview/tool/connectome/matrix_list.h @@ -48,18 +48,18 @@ namespace MR Matrix_list_model (Connectome* parent); QVariant data (const QModelIndex& index, int role) const override { - if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) return QVariant(); + if (!index.isValid()) return {}; + if (role != Qt::DisplayRole) return {}; return qstr (shorten (items[index.row()].get_name().toStdString(), 35, 0)); } Qt::ItemFlags flags (const QModelIndex& index) const override { - if (!index.isValid()) return 0; + if (!index.isValid()) return {}; return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QModelIndex parent (const QModelIndex&) const override { - return QModelIndex(); + return {}; } int rowCount (const QModelIndex& parent = QModelIndex()) const override { diff --git a/src/gui/mrview/tool/connectome/node_list.h b/src/gui/mrview/tool/connectome/node_list.h index 613476a299..30e2c215aa 100644 --- a/src/gui/mrview/tool/connectome/node_list.h +++ b/src/gui/mrview/tool/connectome/node_list.h @@ -52,12 +52,12 @@ namespace MR QVariant headerData (int section, Qt::Orientation orientation, int role) const override; Qt::ItemFlags flags (const QModelIndex& index) const override { - if (!index.isValid()) return 0; + if (!index.isValid()) return {}; return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QModelIndex parent (const QModelIndex&) const override { - return QModelIndex(); + return {}; } int rowCount (const QModelIndex& parent = QModelIndex()) const override; diff --git a/src/gui/mrview/tool/odf/model.h b/src/gui/mrview/tool/odf/model.h index 81a7ba4d93..5f1b5e902f 100644 --- a/src/gui/mrview/tool/odf/model.h +++ b/src/gui/mrview/tool/odf/model.h @@ -44,8 +44,8 @@ namespace MR QAbstractItemModel (parent) { } QVariant data (const QModelIndex& index, int role) const { - if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) return QVariant(); + if (!index.isValid()) return {}; + if (role != Qt::DisplayRole) return {}; return qstr (shorten (items[index.row()]->image.get_filename(), 35, 0)); } @@ -54,12 +54,12 @@ namespace MR } Qt::ItemFlags flags (const QModelIndex& index) const { - if (!index.isValid()) return 0; + if (!index.isValid()) return {}; return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QModelIndex parent (const QModelIndex&) const { - return QModelIndex(); + return {}; } int rowCount (const QModelIndex& parent = QModelIndex()) const { diff --git a/src/gui/mrview/tool/view.cpp b/src/gui/mrview/tool/view.cpp index e363a7ade6..0c233e1203 100644 --- a/src/gui/mrview/tool/view.cpp +++ b/src/gui/mrview/tool/view.cpp @@ -63,11 +63,11 @@ namespace MR QAbstractItemModel (parent) { } QVariant data (const QModelIndex& index, int role) const { - if (!index.isValid()) return QVariant(); + if (!index.isValid()) return {}; if (role == Qt::CheckStateRole) { return planes[index.row()].active ? Qt::Checked : Qt::Unchecked; } - if (role != Qt::DisplayRole) return QVariant(); + if (role != Qt::DisplayRole) return {}; return qstr (planes[index.row()].name); } @@ -81,7 +81,7 @@ namespace MR } Qt::ItemFlags flags (const QModelIndex& index) const { - if (!index.isValid()) return 0; + if (!index.isValid()) return {}; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; } @@ -91,7 +91,7 @@ namespace MR return createIndex (row, column); } - QModelIndex parent (const QModelIndex&) const { return QModelIndex(); } + QModelIndex parent (const QModelIndex&) const { return {}; } int rowCount (const QModelIndex& parent = QModelIndex()) const { @@ -292,7 +292,7 @@ namespace MR transparent_intensity = new AdjustButton (this); connect (transparent_intensity, SIGNAL (valueChanged()), this, SLOT (onSetTransparency())); - hlayout->addWidget (transparent_intensity, 0, 0); + hlayout->addWidget (transparent_intensity); opaque_intensity = new AdjustButton (this); connect (opaque_intensity, SIGNAL (valueChanged()), this, SLOT (onSetTransparency())); diff --git a/src/gui/mrview/volume.cpp b/src/gui/mrview/volume.cpp index 9c6db58e9b..eda12c3e11 100644 --- a/src/gui/mrview/volume.cpp +++ b/src/gui/mrview/volume.cpp @@ -46,12 +46,12 @@ namespace MR value_max = -std::numeric_limits::infinity(); switch (type) { - case gl::BYTE: _scale_factor = std::numeric_limits::max(); break; - case gl::UNSIGNED_BYTE: _scale_factor = std::numeric_limits::max(); break; - case gl::SHORT: _scale_factor = std::numeric_limits::max(); break; - case gl::UNSIGNED_SHORT: _scale_factor = std::numeric_limits::max(); break; - case gl::INT: _scale_factor = std::numeric_limits::max(); break; - case gl::UNSIGNED_INT: _scale_factor = std::numeric_limits::max(); break; + case gl::BYTE: _scale_factor = float (std::numeric_limits::max()); break; + case gl::UNSIGNED_BYTE: _scale_factor = float (std::numeric_limits::max()); break; + case gl::SHORT: _scale_factor = float (std::numeric_limits::max()); break; + case gl::UNSIGNED_SHORT: _scale_factor = float (std::numeric_limits::max()); break; + case gl::INT: _scale_factor = float (std::numeric_limits::max()); break; + case gl::UNSIGNED_INT: _scale_factor = float (std::numeric_limits::max()); break; default: _scale_factor = 1.0f; } } diff --git a/src/gui/mrview/window.cpp b/src/gui/mrview/window.cpp index 70f368a8c8..900a1054af 100644 --- a/src/gui/mrview/window.cpp +++ b/src/gui/mrview/window.cpp @@ -57,6 +57,9 @@ namespace MR namespace { + template inline QPoint position (Event* event) { return event->pos(); } + template <> inline QPoint position (QWheelEvent* event) { return event->position().toPoint(); } + Qt::KeyboardModifiers get_modifier (const char* key, Qt::KeyboardModifiers default_key) { std::string value = lowercase (MR::File::Config::get (key)); if (value.empty()) @@ -1622,7 +1625,7 @@ namespace MR buttons_ = event->buttons(); modifiers_ = event->modifiers() & ( FocusModifier | MoveModifier | RotateModifier ); mouse_displacement_ = QPoint (0,0); - mouse_position_ = event->pos(); + mouse_position_ = position (event); mouse_position_.setY (glarea->height() - mouse_position_.y()); } @@ -1630,7 +1633,7 @@ namespace MR template void Window::update_mouse_state (Event* event) { mouse_displacement_ = mouse_position_; - mouse_position_ = event->pos(); + mouse_position_ = position (event); mouse_position_.setY (glarea->height() - mouse_position_.y()); mouse_displacement_ = mouse_position_ - mouse_displacement_; }