From: Vesa-Pekka Palmu Date: Sun, 20 Nov 2022 18:33:14 +0000 (+0200) Subject: pv: adjust application source code for Qt6 support X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1ed73ebd60336c7b12ee1807644dca719cb9835b;p=pulseview.git pv: adjust application source code for Qt6 support 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 . --- diff --git a/pv/application.cpp b/pv/application.cpp index 15195d06..52cb8a01 100644 --- a/pv/application.cpp +++ b/pv/application.cpp @@ -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_); diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index f4d4c7da..9c695a1b 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -24,6 +24,9 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif #include "logic.hpp" #include "logicsegment.hpp" @@ -306,7 +309,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr 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 match; for (const shared_ptr& s : session_.signalbases()) { @@ -314,7 +321,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr 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 : 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 diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 5f95ec33..97f70508 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -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()); else set_color(QColor::fromRgba(value.value())); diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index bcf32df7..1c8a1611 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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 diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 38017f3b..62393747 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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); } diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 34938e73..b2a130a7 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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())); diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index ecdc59a3..ce2e8e98 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -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; diff --git a/pv/popups/channels.hpp b/pv/popups/channels.hpp index c176eb7a..66d284b0 100644 --- a/pv/popups/channels.hpp +++ b/pv/popups/channels.hpp @@ -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(); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 39c290df..cd46c063 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -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())); diff --git a/pv/views/decoder_binary/QHexView.cpp b/pv/views/decoder_binary/QHexView.cpp index 2c893e36..0badadc7 100644 --- a/pv/views/decoder_binary/QHexView.cpp +++ b/pv/views/decoder_binary/QHexView.cpp @@ -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_; } diff --git a/pv/views/decoder_binary/view.cpp b/pv/views/decoder_binary/view.cpp index 1e40bd1b..6e61fa3a 100644 --- a/pv/views/decoder_binary/view.cpp +++ b/pv/views/decoder_binary/view.cpp @@ -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())); diff --git a/pv/views/tabular_decoder/view.cpp b/pv/views/tabular_decoder/view.cpp index 7e4b3ddb..c1d74290 100644 --- a/pv/views/tabular_decoder/view.cpp +++ b/pv/views/tabular_decoder/view.cpp @@ -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())); diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index 8c0dacd2..d128e1c3 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -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(); diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 888064d0..af07c9e3 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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(); assert(ann_class_ptr); diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index 80c9cf75..0ba52b35 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -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); diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 83ffed28..64581459 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -242,7 +242,11 @@ shared_ptr 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*) diff --git a/pv/views/trace/tracegroup.cpp b/pv/views/trace/tracegroup.cpp index 3cbca909..ecc97b6e 100644 --- a/pv/views/trace/tracegroup.cpp +++ b/pv/views/trace/tracegroup.cpp @@ -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); diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index d4d0c5a8..33d8b0a4 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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); diff --git a/pv/views/trace/viewport.cpp b/pv/views/trace/viewport.cpp index ff3a47db..e2a32aa2 100644 --- a/pv/views/trace/viewport.cpp +++ b/pv/views/trace/viewport.cpp @@ -124,12 +124,40 @@ vector< shared_ptr > Viewport::items() bool Viewport::touch_event(QTouchEvent *event) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QList touchPoints = event->points(); +#else QList 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(); + pinch_offset1_ = (view_.offset() + view_.scale() * touchPoint1.position().x()).convert_to(); + 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) diff --git a/pv/widgets/decodermenu.cpp b/pv/widgets/decodermenu.cpp index 34f4852c..5cf99e52 100644 --- a/pv/widgets/decodermenu.cpp +++ b/pv/widgets/decodermenu.cpp @@ -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) diff --git a/pv/widgets/devicetoolbutton.cpp b/pv/widgets/devicetoolbutton.cpp index d700b8b5..2e76f689 100644 --- a/pv/widgets/devicetoolbutton.cpp +++ b/pv/widgets/devicetoolbutton.cpp @@ -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*))); diff --git a/pv/widgets/exportmenu.cpp b/pv/widgets/exportmenu.cpp index 721affe0..bda66928 100644 --- a/pv/widgets/exportmenu.cpp +++ b/pv/widgets/exportmenu.cpp @@ -75,8 +75,13 @@ ExportMenu::ExportMenu(QWidget *parent, shared_ptr 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) diff --git a/pv/widgets/flowlayout.cpp b/pv/widgets/flowlayout.cpp index efd862f9..73916700 100644 --- a/pv/widgets/flowlayout.cpp +++ b/pv/widgets/flowlayout.cpp @@ -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; } diff --git a/pv/widgets/importmenu.cpp b/pv/widgets/importmenu.cpp index b63256cb..dcca307e 100644 --- a/pv/widgets/importmenu.cpp +++ b/pv/widgets/importmenu.cpp @@ -72,8 +72,13 @@ ImportMenu::ImportMenu(QWidget *parent, shared_ptr 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) diff --git a/pv/widgets/popup.cpp b/pv/widgets/popup.cpp index 9614701b..bcfd8753 100644 --- a/pv/widgets/popup.cpp +++ b/pv/widgets/popup.cpp @@ -21,7 +21,11 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#endif #include #include #include diff --git a/pv/widgets/sweeptimingwidget.cpp b/pv/widgets/sweeptimingwidget.cpp index e655526c..0f1eb6d9 100644 --- a/pv/widgets/sweeptimingwidget.cpp +++ b/pv/widgets/sweeptimingwidget.cpp @@ -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_); diff --git a/pv/widgets/timestampspinbox.cpp b/pv/widgets/timestampspinbox.cpp index 01424a5b..b99a640a 100644 --- a/pv/widgets/timestampspinbox.cpp +++ b/pv/widgets/timestampspinbox.cpp @@ -20,7 +20,11 @@ #include "timestampspinbox.hpp" #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#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()));