]> sigrok.org Git - pulseview.git/commitdiff
pv: adjust application source code for Qt6 support
authorVesa-Pekka Palmu <redacted>
Sun, 20 Nov 2022 18:33:14 +0000 (20:33 +0200)
committerGerhard Sittig <redacted>
Wed, 30 Nov 2022 17:32:36 +0000 (18:32 +0100)
Prepare application source code (C++ programming language files) for Qt6
compatibility. Implement alternative code paths where the API has changed
compared to Qt5. This unbreaks Mac OSX 12 builds with homebrew.

This change is based on work that was submitted by Dominik Sliwa
<redacted>.

27 files changed:
pv/application.cpp
pv/data/decodesignal.cpp
pv/data/signalbase.cpp
pv/dialogs/settings.cpp
pv/globalsettings.cpp
pv/mainwindow.cpp
pv/popups/channels.cpp
pv/popups/channels.hpp
pv/toolbars/mainbar.cpp
pv/views/decoder_binary/QHexView.cpp
pv/views/decoder_binary/view.cpp
pv/views/tabular_decoder/view.cpp
pv/views/trace/analogsignal.cpp
pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp
pv/views/trace/ruler.cpp
pv/views/trace/tracegroup.cpp
pv/views/trace/view.cpp
pv/views/trace/viewport.cpp
pv/widgets/decodermenu.cpp
pv/widgets/devicetoolbutton.cpp
pv/widgets/exportmenu.cpp
pv/widgets/flowlayout.cpp
pv/widgets/importmenu.cpp
pv/widgets/popup.cpp
pv/widgets/sweeptimingwidget.cpp
pv/widgets/timestampspinbox.cpp

index 15195d067da801e594ce573ccf756a79200d4986..52cb8a01557291e3cdd41e5ffc8c831f1f37cf53 100644 (file)
@@ -106,7 +106,11 @@ void Application::switch_language(const QString& language)
                        qWarning() << "Translation resource" << resource << "not found";
 
                // Qt translations
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               QString tr_path(QLibraryInfo::path(QLibraryInfo::TranslationsPath));
+#else
                QString tr_path(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+#endif
 
                if (qt_translator_.load("qt_" + language, tr_path))
                        installTranslator(&qt_translator_);
index f4d4c7da80ed79564216efcf8fc4786914095510..9c695a1baa8247dfa09be12c8cdd9b2ee5956d34 100644 (file)
@@ -24,6 +24,9 @@
 #include <limits>
 
 #include <QDebug>
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+#include <QRegularExpression>
+#endif
 
 #include "logic.hpp"
 #include "logicsegment.hpp"
@@ -306,7 +309,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
                        continue;
 
                QString ch_name = ch.name.toLower();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               ch_name = ch_name.replace(QRegularExpression("[-_.]"), " ");
+#else
                ch_name = ch_name.replace(QRegExp("[-_.]"), " ");
+#endif
 
                shared_ptr<data::SignalBase> match;
                for (const shared_ptr<data::SignalBase>& s : session_.signalbases()) {
@@ -314,7 +321,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
                                continue;
 
                        QString s_name = s->name().toLower();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+                       s_name = s_name.replace(QRegularExpression("[-_.]"), " ");
+#else
                        s_name = s_name.replace(QRegExp("[-_.]"), " ");
+#endif
 
                        if (s->logic_data() &&
                                ((ch_name.contains(s_name)) || (s_name.contains(ch_name)))) {
@@ -747,7 +758,11 @@ void DecodeSignal::save_settings(QSettings &settings) const
        for (const shared_ptr<Decoder>& decoder : stack_) {
                settings.beginGroup("decoder" + QString::number(decoder_idx++));
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               settings.setValue("id", (const char *)decoder->get_srd_decoder()->id);
+#else
                settings.setValue("id", decoder->get_srd_decoder()->id);
+#endif
                settings.setValue("visible", decoder->visible());
 
                // Save decoder options
index 5f95ec337b16d5504000ce02736d29d31f4c924c..97f705084e91fc654c85ab7ce07cbfec64a3df50 100644 (file)
@@ -590,7 +590,12 @@ void SignalBase::restore_settings(QSettings &settings)
                QVariant value = settings.value("color");
 
                // Workaround for Qt QColor serialization bug on OSX
-               if ((QMetaType::Type)(value.type()) == QMetaType::QColor)
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               bool is_qcolor = (QMetaType::Type)(value.typeId()) == QMetaType::QColor;
+#else
+               bool is_qcolor = (QMetaType::Type)(value.type()) == QMetaType::QColor;
+#endif
+               if (is_qcolor)
                        set_color(value.value<QColor>());
                else
                        set_color(QColor::fromRgba(value.value<uint32_t>()));
index bcf32df76ec4937a52b8b3e569b5129eb997e25a..1c8a161184f34daf8a6e7e48bd379c92a6b929e6 100644 (file)
@@ -231,8 +231,13 @@ QWidget *Settings::get_general_settings_form(QWidget *parent) const
                        language_cb->setCurrentIndex(index);
                }
        }
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(language_cb, SIGNAL(currentTextChanged(const QString&)),
+               this, SLOT(on_general_language_changed(const QString&)));
+#else
        connect(language_cb, SIGNAL(currentIndexChanged(const QString&)),
                this, SLOT(on_general_language_changed(const QString&)));
+#endif
        general_layout->addRow(tr("User interface language"), language_cb);
 
        // Theme combobox
index 38017f3b14569444c8f1ab45b5d32624bac67e69..6239374778a4886af74cf2bc13f1120d17bb3dd4 100644 (file)
@@ -330,7 +330,11 @@ void GlobalSettings::store_gvariant(QSettings &settings, GVariant *v)
                g_variant_get_size(v));
 
        settings.setValue("value", var_data);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       settings.setValue("type", (const char *)var_type_str);
+#else
        settings.setValue("type", var_type_str);
+#endif
 
        g_free(var_type_str);
 }
index 34938e7364cb5d827670558d903be0f6426fe0c0..b2a130a737a048f7b259b61e8fa72a2fa79fb9b8 100644 (file)
@@ -95,7 +95,7 @@ MainWindow::~MainWindow()
 void MainWindow::show_session_error(const QString text, const QString info_text)
 {
        // TODO Emulate noquote()
-       qDebug() << "Notifying user of session error:" << info_text;
+       qDebug() << "Notifying user of session error: " << text << "; " << info_text;
 
        QMessageBox msg;
        msg.setText(text + "\n\n" + info_text);
@@ -547,10 +547,14 @@ void MainWindow::setup_ui()
        session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
        session_selector_.setTabsClosable(true);
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this, SLOT(close()));
+       close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), this, SLOT(on_close_current_tab()));
+#else
        close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
-       close_application_shortcut_->setAutoRepeat(false);
-
        close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
+#endif
+       close_application_shortcut_->setAutoRepeat(false);
 
        connect(new_session_button_, SIGNAL(clicked(bool)),
                this, SLOT(on_new_session_clicked()));
index ecdc59a35466cd82f378cd1393f5f366bb091ccf..ce2e8e98e08e0f7f3e88356b68ddce4aad1d4c66 100644 (file)
@@ -158,8 +158,13 @@ Channels::Channels(Session &session, QWidget *parent) :
        layout_.addRow(&filter_buttons_bar_);
 
        // Connect the check-box signal mapper
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&check_box_mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_channel_checked(QObject*)));
+#else
        connect(&check_box_mapper_, SIGNAL(mapped(QWidget*)),
                this, SLOT(on_channel_checked(QWidget*)));
+#endif
 }
 
 void Channels::set_all_channels(bool set)
@@ -354,7 +359,11 @@ void Channels::showEvent(QShowEvent *event)
        updating_channels_ = false;
 }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void Channels::on_channel_checked(QObject *widget)
+#else
 void Channels::on_channel_checked(QWidget *widget)
+#endif
 {
        if (updating_channels_)
                return;
index c176eb7a95184850ca89dc1b2c90d7ce4d1d660e..66d284b00dfcefcadd003a1b7bbd73b021b6f274 100644 (file)
@@ -82,7 +82,11 @@ private:
        void showEvent(QShowEvent *event);
 
 private Q_SLOTS:
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       void on_channel_checked(QObject *widget);
+#else
        void on_channel_checked(QWidget *widget);
+#endif
 
        void enable_all_channels();
        void disable_all_channels();
index 39c290dfb2c8a2c34499928bafd600eb227a4030..cd46c063bdc8a84d78d1e42e1c616c2fc8a3b270 100644 (file)
@@ -130,7 +130,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
        action_open_->setText(tr("&Open..."));
        action_open_->setIcon(QIcon::fromTheme("document-open",
                QIcon(":/icons/document-open.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       action_open_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O));
+#else
        action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
+#endif
        connect(action_open_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionOpen_triggered()));
 
@@ -141,7 +145,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
        action_save_->setText(tr("&Save..."));
        action_save_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       action_save_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+#else
        action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+#endif
        connect(action_save_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSave_triggered()));
 
@@ -154,7 +162,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
        action_save_selection_as_->setText(tr("Save Selected &Range As..."));
        action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
+#else
        action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
+#endif
        connect(action_save_selection_as_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSaveSelectionAs_triggered()));
 
index 2c893e366d6d65cdafb8eaca9d3e021eb22f0a44..0badadc77eeb9923c8bd7d192986dd70f3bf0880 100644 (file)
@@ -497,7 +497,11 @@ void QHexView::paintEvent(QPaintEvent *event)
                                painter.setPen(palette().color(QPalette::HighlightedText));
                        }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+                       painter.drawText(x, y, QString(QChar(ch)));
+#else
                        painter.drawText(x, y, QString(ch));
+#endif
                        x += charWidth_;
                }
 
index 1e40bd1b686c315ce3f5a196b96c351b027c4cf7..6e61fa3aa1aa8bf688273ca5e8872c131435996a 100644 (file)
@@ -110,7 +110,11 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        save_action_->setText(tr("&Save..."));
        save_action_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+#else
        save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+#endif
        connect(save_action_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSave_triggered()));
 
index 7e4b3ddb414dd28887842aad9e2f4cf421e5086e..c1d7429080a221d0d3015d66b8f9fdece849ccb2 100644 (file)
@@ -202,7 +202,11 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        save_action_->setText(tr("&Save..."));
        save_action_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+#else
        save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+#endif
        connect(save_action_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSave_triggered()));
 
index 8c0dacd26fa52f9579c00efb4124a2f6f6afa9bf..d128e1c37ba354753277cac9956644136d01cd57 100644 (file)
@@ -1100,13 +1100,20 @@ void AnalogSignal::on_conv_threshold_changed(int index)
                // https://txt2re.com/index-c++.php3?s=0.1V&1&-13
                QString re1 = "([+-]?\\d*[\\.,]?\\d*)"; // Float value
                QString re2 = "([a-zA-Z]*)"; // SI unit
-               QRegExp regex(re1 + re2);
-
                const QString text = conv_threshold_cb_->currentText();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               QRegularExpression regex(re1 + re2);
+               if (!regex.match(text).hasMatch())
+                       return;  // String doesn't match the regex
+
+               QStringList tokens = regex.match(text).capturedTexts();
+#else
+               QRegExp regex(re1 + re2);
                if (!regex.exactMatch(text))
                        return;  // String doesn't match the regex
 
                QStringList tokens = regex.capturedTexts();
+#endif
 
                // For now, we simply assume that the unit is volt without modifiers
                const double thr = tokens.at(1).toDouble();
@@ -1127,13 +1134,22 @@ void AnalogSignal::on_conv_threshold_changed(int index)
                QString re3 = "\\/"; // Forward slash, not captured
                QString re4 = "([+-]?\\d*[\\.,]?\\d*)"; // Float value
                QString re5 = "([a-zA-Z]*)"; // SI unit
+               const QString text = conv_threshold_cb_->currentText();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               QRegularExpression regex(re1 + re2 + re3 + re4 + re5);
+
+               if (!regex.match(text).hasMatch())
+                       return;  // String doesn't match the regex
+
+               QStringList tokens = regex.match(text).capturedTexts();
+#else
                QRegExp regex(re1 + re2 + re3 + re4 + re5);
 
-               const QString text = conv_threshold_cb_->currentText();
                if (!regex.exactMatch(text))
                        return;  // String doesn't match the regex
 
                QStringList tokens = regex.capturedTexts();
+#endif
 
                // For now, we simply assume that the unit is volt without modifiers
                const double low_thr = tokens.at(1).toDouble();
index 888064d09e12583cde3937eaab98fdee725e43bc..af07c9e34a23c223127a93f55929515fd69459b0 100644 (file)
@@ -186,7 +186,16 @@ DecodeTrace::DecodeTrace(pv::Session &session,
                this, SLOT(on_decode_finished()));
        connect(decode_signal_.get(), SIGNAL(channels_updated()),
                this, SLOT(on_channels_updated()));
-
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&delete_mapper_, SIGNAL(mappedInt(int)),
+               this, SLOT(on_delete_decoder(int)));
+       connect(&show_hide_mapper_, SIGNAL(mappedInt(int)),
+               this, SLOT(on_show_hide_decoder(int)));
+       connect(&row_show_hide_mapper_, SIGNAL(mappedInt(int)),
+               this, SLOT(on_show_hide_row(int)));
+       connect(&class_show_hide_mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_show_hide_class(QObject*)));
+#else
        connect(&delete_mapper_, SIGNAL(mapped(int)),
                this, SLOT(on_delete_decoder(int)));
        connect(&show_hide_mapper_, SIGNAL(mapped(int)),
@@ -195,6 +204,7 @@ DecodeTrace::DecodeTrace(pv::Session &session,
                this, SLOT(on_show_hide_row(int)));
        connect(&class_show_hide_mapper_, SIGNAL(mapped(QWidget*)),
                this, SLOT(on_show_hide_class(QWidget*)));
+#endif
 
        connect(&delayed_trace_updater_, SIGNAL(timeout()),
                this, SLOT(on_delayed_trace_update()));
@@ -667,10 +677,19 @@ void DecodeTrace::mouse_left_press_event(const QMouseEvent* event)
                        continue;
 
                unsigned int y = get_row_y(&r);
-               if ((event->x() > 0) && (event->x() <= (int)(ArrowSize + 3 + r.title_width)) &&
-                       (event->y() > (int)(y - (default_row_height_ / 2))) &&
-                       (event->y() <= (int)(y + (default_row_height_ / 2)))) {
-
+               bool need_anim = true;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+               need_anim &= event->position().x() > 0;
+               need_anim &= event->position().x() <= (int)(ArrowSize + 3 + r.title_width);
+               need_anim &= event->position().y() > (int)(y - (default_row_height_ / 2));
+               need_anim &= event->position().y() <= (int)(y + (default_row_height_ / 2));
+#else
+               need_anim &= event->x() > 0;
+               need_anim &= event->x() <= (int)(ArrowSize + 3 + r.title_width);
+               need_anim &= event->y() > (int)(y - (default_row_height_ / 2));
+               need_anim &= event->y() <= (int)(y + (default_row_height_ / 2));
+#endif
+               if (need_anim) {
                        if (r.expanded) {
                                r.collapsing = true;
                                r.expanded = false;
@@ -1249,6 +1268,19 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
        QPalette header_palette = owner_->view()->palette();
        QPalette selector_palette = owner_->view()->palette();
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       if (GlobalSettings::current_theme_is_dark()) {
+               header_palette.setColor(QPalette::Window,
+                       QColor(255, 255, 255, ExpansionAreaHeaderAlpha));
+               selector_palette.setColor(QPalette::Window,
+                       QColor(255, 255, 255, ExpansionAreaAlpha));
+       } else {
+               header_palette.setColor(QPalette::Window,
+                       QColor(0, 0, 0, ExpansionAreaHeaderAlpha));
+               selector_palette.setColor(QPalette::Window,
+                       QColor(0, 0, 0, ExpansionAreaAlpha));
+       }
+#else
        if (GlobalSettings::current_theme_is_dark()) {
                header_palette.setColor(QPalette::Background,
                        QColor(255, 255, 255, ExpansionAreaHeaderAlpha));
@@ -1260,6 +1292,7 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
                selector_palette.setColor(QPalette::Background,
                        QColor(0, 0, 0, ExpansionAreaAlpha));
        }
+#endif
 
        const int w = m.boundingRect(r->decode_row->title()).width() + RowTitleMargin;
        r->title_width = w;
@@ -1602,7 +1635,11 @@ void DecodeTrace::on_show_hide_row(int row_id)
        owner_->row_item_appearance_changed(false, true);
 }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+void DecodeTrace::on_show_hide_class(QObject* sender)
+#else
 void DecodeTrace::on_show_hide_class(QWidget* sender)
+#endif
 {
        void* ann_class_ptr = sender->property("ann_class_ptr").value<void*>();
        assert(ann_class_ptr);
index 80c9cf750b341f155fe1a6b077fe60dca6339b5a..0ba52b357c8ed80e108b25559b5aa2559716c5cc 100644 (file)
@@ -278,7 +278,11 @@ private Q_SLOTS:
 
        void on_show_hide_decoder(int index);
        void on_show_hide_row(int row_id);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       void on_show_hide_class(QObject* sender);
+#else
        void on_show_hide_class(QWidget* sender);
+#endif
        void on_show_all_classes();
        void on_hide_all_classes();
        void on_row_container_resized(QWidget* sender);
index 83ffed281b5f6768085d1a03ee77f2840a443487..64581459593a1fcc8148a4c4d2e14dee31164b64 100644 (file)
@@ -242,7 +242,11 @@ shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
 
 void Ruler::mouseDoubleClickEvent(QMouseEvent *event)
 {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       hover_item_ = view_.add_flag(get_absolute_time_from_x_pos(event->pos().x()));
+#else
        hover_item_ = view_.add_flag(get_absolute_time_from_x_pos(event->x()));
+#endif
 }
 
 void Ruler::paintEvent(QPaintEvent*)
index 3cbca90934d68a8417e17d5feb6bc70fd79bb3a6..ecc97b6ee80153671c2a1cc4512a0530a99ea9c4 100644 (file)
@@ -138,7 +138,11 @@ QMenu* TraceGroup::create_header_context_menu(QWidget *parent)
        QMenu *const menu = new QMenu(parent);
 
        QAction *const ungroup = new QAction(tr("Ungroup"), this);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       ungroup->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
+#else
        ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
+#endif
        connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup()));
        menu->addAction(ungroup);
 
index d4d0c5a81bca4c06fef1114147c3ca20d7837c1d..33d8b0a44aa7ed9530adb4b4349439d8f9cc1c49 100644 (file)
@@ -1530,7 +1530,11 @@ bool View::eventFilter(QObject *object, QEvent *event)
                else if (object == ruler_)
                        hover_point_ = mouse_event->pos();
                else if (object == header_)
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+                       hover_point_ = QPoint(0, mouse_event->pos().y());
+#else
                        hover_point_ = QPoint(0, mouse_event->y());
+#endif
                else
                        hover_point_ = QPoint(-1, -1);
 
index ff3a47db25ef25601c9213b3e6d5dfab87da98fb..e2a32aa20bdd4ec41dc6460b30b3f72a8e46f894 100644 (file)
@@ -124,12 +124,40 @@ vector< shared_ptr<ViewItem> > Viewport::items()
 
 bool Viewport::touch_event(QTouchEvent *event)
 {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       QList<QEventPoint> touchPoints = event->points();
+#else
        QList<QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
+#endif
 
        if (touchPoints.count() != 2) {
                pinch_zoom_active_ = false;
                return false;
        }
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       if (event->device()->type() == QInputDevice::DeviceType::TouchPad) {
+               return false;
+       }
+
+       const QEventPoint &touchPoint0 = touchPoints.first();
+       const QEventPoint &touchPoint1 = touchPoints.last();
+
+       if (!pinch_zoom_active_ ||
+               (event->touchPointStates() & QEventPoint::Pressed)) {
+               pinch_offset0_ = (view_.offset() + view_.scale() * touchPoint0.position().x()).convert_to<double>();
+               pinch_offset1_ = (view_.offset() + view_.scale() * touchPoint1.position().x()).convert_to<double>();
+               pinch_zoom_active_ = true;
+       }
+
+       double w = touchPoint1.position().x() - touchPoint0.position().x();
+       if (abs(w) >= 1.0) {
+               const double scale =
+                       fabs((pinch_offset1_ - pinch_offset0_) / w);
+               double offset = pinch_offset0_ - touchPoint0.position().x() * scale;
+               if (scale > 0)
+                       view_.set_scale_offset(scale, offset);
+       }
+#else
        if (event->device()->type() == QTouchDevice::TouchPad) {
                return false;
        }
@@ -152,6 +180,7 @@ bool Viewport::touch_event(QTouchEvent *event)
                if (scale > 0)
                        view_.set_scale_offset(scale, offset);
        }
+#endif
 
        if (event->touchPointStates() & Qt::TouchPointReleased) {
                pinch_zoom_active_ = false;
@@ -162,7 +191,11 @@ bool Viewport::touch_event(QTouchEvent *event)
                } else {
                        // Update the mouse down fields so that continued
                        // dragging with the primary touch will work correctly
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+                       mouse_down_point_ = touchPoint0.position().toPoint();
+#else
                        mouse_down_point_ = touchPoint0.pos().toPoint();
+#endif
                        drag();
                }
        }
@@ -215,10 +248,17 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
 {
        assert(event);
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       if (event->buttons() & Qt::LeftButton)
+               view_.zoom(2.0, event->position().x());
+       else if (event->buttons() & Qt::RightButton)
+               view_.zoom(-2.0, event->position().x());
+#else
        if (event->buttons() & Qt::LeftButton)
                view_.zoom(2.0, event->x());
        else if (event->buttons() & Qt::RightButton)
                view_.zoom(-2.0, event->x());
+#endif
 }
 
 void Viewport::wheelEvent(QWheelEvent *event)
index 34f4852c9edf4f0381fe661efe273b6debe2685e..5cf99e5212690ee18e18b2fe08195d94db7d7041 100644 (file)
@@ -57,7 +57,11 @@ DecoderMenu::DecoderMenu(QWidget *parent, const char* input, bool first_level_de
        }
        g_slist_free(li);
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&mapper_, SIGNAL(mappedObject(QObject*)), this, SLOT(on_action(QObject*)));
+#else
        connect(&mapper_, SIGNAL(mapped(QObject*)), this, SLOT(on_action(QObject*)));
+#endif
 }
 
 int DecoderMenu::decoder_name_cmp(const void *a, const void *b)
index d700b8b57cc0bdf471452ab6a8806e787c63f19c..2e76f689a61f448b068e149e2c1886a5f67992b8 100644 (file)
@@ -55,8 +55,13 @@ DeviceToolButton::DeviceToolButton(QWidget *parent,
        setDefaultAction(connect_action_);
        setMinimumWidth(QFontMetrics(font()).averageCharWidth() * 24);
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_action(QObject*)));
+#else
        connect(&mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_action(QObject*)));
+#endif
 
        connect(&menu_, SIGNAL(hovered(QAction*)),
                this, SLOT(on_menu_hovered(QAction*)));
index 721affe058e9a359579b8caabf43485ffb99625b..bda669288f3731b9f3706fd9603de490eaee25a6 100644 (file)
@@ -75,8 +75,13 @@ ExportMenu::ExportMenu(QWidget *parent, shared_ptr<Context> context,
                connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
        }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_action(QObject*)));
+#else
        connect(&mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_action(QObject*)));
+#endif
 }
 
 void ExportMenu::on_action(QObject *action)
index efd862f97b1fb9581307fe92e920d9903b50f2dc..73916700253087617a0539a44e6caa6579043840 100644 (file)
@@ -146,7 +146,13 @@ QSize FlowLayout::minimumSize() const
                        size.setHeight(h);
        }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       int left, top, right, bottom;
+       getContentsMargins(&left, &top, &right, &bottom);
+       size += QSize(left + right, top + bottom);
+#else
        size += QSize(2 * margin(), 2 * margin());
+#endif
 
        return size;
 }
index b63256cb923cd36edaf89962975bc4e348147cfd..dcca307ecc731bb01e6946fd9f38d4c0ec17f4ac 100644 (file)
@@ -72,8 +72,13 @@ ImportMenu::ImportMenu(QWidget *parent, shared_ptr<Context> context,
                connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
        }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_action(QObject*)));
+#else
        connect(&mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_action(QObject*)));
+#endif
 }
 
 void ImportMenu::on_action(QObject *action)
index 9614701b7a9701d9c9cb2d2d277dfb388b4295ab..bcfd8753c6b6dbe2c8e6da5a8032d75057b8bc50 100644 (file)
 #include <cassert>
 
 #include <QApplication>
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+#include <QScreen>
+#else
 #include <QDesktopWidget>
+#endif
 #include <QLineEdit>
 #include <QScrollBar>
 #include <QStyle>
index e655526c0b3f7a1a12fabb5af0c9e2383177488d..0f1eb6d9ff2595f0f484c357655b9691ebbcbf92 100644 (file)
@@ -54,7 +54,11 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
                this, SIGNAL(value_changed()));
 
        setLayout(&layout_);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       layout_.setContentsMargins(0, 0, 0, 0);
+#else
        layout_.setMargin(0);
+#endif
        layout_.addWidget(&list_);
        layout_.addWidget(&value_);
 
index 01424a5b7837654e50c36de5f3f4ce27c33ec8a1..b99a640a843055fa2d2271bcae9c67d6607f63a9 100644 (file)
 #include "timestampspinbox.hpp"
 
 #include <QLineEdit>
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+#include <QRegularExpression>
+#else
 #include <QRegExp>
+#endif
 
 namespace pv {
 namespace widgets {
@@ -93,10 +97,25 @@ void TimestampSpinBox::setValue(const pv::util::Timestamp& val)
 
 void TimestampSpinBox::on_editingFinished()
 {
-       QRegExp re(R"(\s*([-+]?)\s*([0-9]+\.?[0-9]*).*)");
+       static const auto re_pattern = R"(\s*([-+]?)\s*([0-9]+\.?[0-9]*).*)";
+
+       bool has_match;
+       QStringList captures;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       QRegularExpression re(re_pattern);
+       has_match = re.match(text()).hasMatch();
+       if (has_match) {
+               captures = re.match(text()).capturedTexts();
+       }
+#else
+       QRegExp re(re_pattern);
+       has_match = re.exactMatch(text());
+       if (has_match) {
+               captures = re.capturedTexts();
+       }
+#endif
 
-       if (re.exactMatch(text())) {
-               QStringList captures = re.capturedTexts();
+       if (has_match) {
                captures.removeFirst(); // remove entire match
                QString str = captures.join("");
                setValue(pv::util::Timestamp(str.toStdString()));