[LyX/master] Separate debug code so that effective only in the debug mode
Koji Yokota <[email protected]>
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 1261b40bdc489022506c8b90d810de66e1e921b6 Author: Koji Yokota <[email protected]> Date: Mon Apr 6 14:22:53 2026 +0900 Separate debug code so that effective only in the debug mode --- src/frontends/qt/GuiInputMethod.cpp | 109 ++++++++++++++++++++++++++++++++---- src/frontends/qt/GuiInputMethod.h | 2 + src/frontends/qt/GuiWorkArea.h | 2 +- 3 files changed, 100 insertions(+), 13 deletions(-) diff --git a/src/frontends/qt/GuiInputMethod.cpp b/src/frontends/qt/GuiInputMethod.cpp index c1fe0cba15..415fd37e70 100644 --- a/src/frontends/qt/GuiInputMethod.cpp +++ b/src/frontends/qt/GuiInputMethod.cpp @@ -31,7 +31,9 @@ #include "Text.h" #include "TextMetrics.h" +#ifdef _DEBUG #include "support/debug.h" +#endif #include "support/lassert.h" #include "support/qstring_helpers.h" @@ -99,9 +101,11 @@ GuiInputMethod::GuiInputMethod(GuiWorkArea *parent) d->buffer_view_ = &d->work_area_->bufferView(); d->cur_ = &d->buffer_view_->cursor(); +#ifdef _DEBUG LYXERR(Debug::DEBUG, "GuiInputMethod: Address of parent: " << parent); LYXERR(Debug::DEBUG, "GuiInputMethod: Address of buffer_view_: " << &d->work_area_->bufferView()); +#endif connect(this, &GuiInputMethod::inputMethodStateChanged, d->sys_im_, &QInputMethod::update); @@ -192,16 +196,20 @@ void GuiInputMethod::processPreedit(QInputMethodEvent* ev) Color fg(Color_foreground); d->font_color_ = d->color_cache_.get(fg); d->font_brush_.setColor(d->font_color_); +#ifdef _DEBUG LYXERR(Debug::DEBUG, "Preedit font color is set to " << d->font_color_.name()); +#endif d->locale_ = d->sys_im_->locale(); d->style_.lang_ = d->locale_; +#ifdef _DEBUG LYXERR(Debug::DEBUG, "IM locale: " << d->locale_.bcp47Name() << " preeditString: " << ev->preeditString() << " commitString: " << ev->commitString()); +#endif // output the commit string to the text if (!ev->commitString().isEmpty()) { @@ -368,7 +376,9 @@ void GuiInputMethod::setPreeditStyle( // d->seg_turnout_.clear(); +#ifdef _DEBUG LYXERR(Debug::GUI, "Start parsing attributes of the preedit"); +#endif // obtain attributes of input method for (const QInputMethodEvent::Attribute & it : attr) { switch (it.type) { @@ -424,35 +434,43 @@ void GuiInputMethod::setPreeditStyle( // however we haven't encountered use cases in QInputMethodEvent d->style_.caret_color_ = it.value.value<QColor>(); +#ifdef _DEBUG // we only prepare for finding such incoming event LYXERR(Debug::DEBUG, "QInputMethodEvent: virtual cursor position: " << std::dec << d->caret_pos_ << " caret color: " << d->style_.caret_color_.name(QColor::HexRgb)); +#endif break; // again not implemented yet? case QInputMethodEvent::Language: d->style_.lang_ = it.value.value<QLocale>(); +#ifdef _DEBUG LYXERR(Debug::DEBUG, "QInputMethodEvent::Language: " << d->style_.lang_.bcp47Name()); +#endif break; // this also seems not implemented by any input methods case QInputMethodEvent::Ruby: d->style_.ruby_ = it.value.value<QString>(); +#ifdef _DEBUG LYXERR(Debug::DEBUG, "QInputMethodEvent::Ruby: " << d->style_.ruby_); +#endif break; case QInputMethodEvent::Selection: d->anchor_pos_ = it.start; d->caret_pos_ = it.start + it.length; d->cur_->setSelection(d->cur_->realAnchor(), it.length); +#ifdef _DEBUG LYXERR(Debug::DEBUG, "QInputMethodEvent::Selection start: " << it.start << " length: " << it.length); +#endif break; #if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) case QInputMethodEvent::MimeData: @@ -466,7 +484,9 @@ void GuiInputMethod::setPreeditStyle( for (size_type i=0; i<d->seg_turnout_.size(); ++i) next_seg_pos = pickNextSegFromTurnout(next_seg_pos); if (!d->seg_turnout_.empty()) { +#ifdef _DEBUG LYXERR0("Turnouts of preedit segments have not been all swept"); +#endif LATTEST(false); } @@ -493,7 +513,9 @@ void GuiInputMethod::setPreeditStyle( || (focus_style == nullptr && d->style_.segments_.size() <= 1); if (d->im_state_.composing_mode_) { +#ifdef _DEBUG LYXERR(Debug::DEBUG, "preedit is in the composing mode"); +#endif QTextCharFormat char_format; int start = 0; size_type length = 0; @@ -512,7 +534,9 @@ void GuiInputMethod::setPreeditStyle( PreeditSegment seg = {start, length, char_format}; d->style_.segments_.push_back(seg); } else { +#ifdef _DEBUG LYXERR(Debug::DEBUG, "preedit is in the completing mode"); +#endif d->style_.caret_visible_ = false; } } @@ -523,6 +547,7 @@ pos_type GuiInputMethod::setTextFormat(const QInputMethodEvent::Attribute & it, // get LyX's color setting QTextCharFormat char_format = it.value.value<QTextCharFormat>(); +#ifdef _DEBUG LYXERR(Debug::GUI, "QInputMethodEvent::TextFormat start: " << it.start << " end: " << it.start + it.length - 1 << @@ -530,6 +555,7 @@ pos_type GuiInputMethod::setTextFormat(const QInputMethodEvent::Attribute & it, " UnderlineStyle: " << char_format.underlineStyle() << " fg: " << char_format.foreground().color().name() << " bg: " << char_format.background().color().name()); +#endif // // Fit and adjust arrived text formats @@ -568,9 +594,11 @@ pos_type GuiInputMethod::setTextFormat(const QInputMethodEvent::Attribute & it, pickNextSegFromTurnout(next_seg_pos, &char_format); if (updated_pos == next_seg_pos) { // no matching segment in the turnout +#ifdef _DEBUG LYXERR(Debug::GUI, "Pushing to preedit register: (" << it.start << ", " << it.start + it.length - 1 << ") bg color: " << char_format.background().color().name()); +#endif next_seg_pos = registerSegment(it.start, (size_type)it.length, char_format); } else @@ -578,19 +606,23 @@ pos_type GuiInputMethod::setTextFormat(const QInputMethodEvent::Attribute & it, } else { // push the constructed char format together with start and length // to the list +#ifdef _DEBUG LYXERR(Debug::GUI, "Pushing to preedit register: (" << it.start << ", " << it.start + it.length - 1 << ") fg: " << char_format.foreground().color().name() << " bg: " << char_format.background().color().name()); +#endif next_seg_pos = registerSegment(it.start, (size_type)it.length, char_format); } next_seg_pos = pickNextSegFromTurnout(next_seg_pos); } else if ((it.start > next_seg_pos || d->initial_tf_entry_) && it.length > 0) { +#ifdef _DEBUG LYXERR(Debug::GUI, "Pushing to preedit turnout: (" << it.start << ", " << it.start + it.length - 1 << ")"); +#endif PreeditSegment turnout = {it.start, (size_type)it.length, char_format}; d->seg_turnout_.push_back(turnout); d->initial_tf_entry_ = false; @@ -619,6 +651,7 @@ pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, seg = {(*past_attr).start_, (size_type)(*past_attr).length_, (*past_attr).char_format_}; +#ifdef _DEBUG LYXERR(Debug::GUI, "Pushing to preedit register: (" << (*past_attr).start_ << ", " << (*past_attr).start_ + (*past_attr).length_ - 1 @@ -626,6 +659,7 @@ pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, << (*past_attr).char_format_.foreground().color().name() << " bg: " << (*past_attr).char_format_.background().color().name()); +#endif d->style_.segments_.push_back(seg); next_seg_pos += (*past_attr).length_; if (d->seg_turnout_.size() > 1) @@ -637,15 +671,19 @@ pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, // Clear d->seg_turnout_ if (is_matched) { if (d->seg_turnout_.size() == 1) { +#ifdef _DEBUG LYXERR(Debug::GUI, "Preedit turnout clearing: (" << d->seg_turnout_.back().start_ << ", " << d->seg_turnout_.back().start_ + d->seg_turnout_.back().length_ - 1 << ")"); +#endif d->seg_turnout_.pop_back(); } else if (d->seg_turnout_.size() > 1) { +#ifdef _DEBUG LYXERR(Debug::GUI, "Preedit turnout clearing: (" << (*to_erase).start_ << ", " << (*to_erase).start_ + (*to_erase).length_ - 1 << ")"); +#endif d->seg_turnout_.erase(to_erase); } } @@ -916,16 +954,19 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) return; } +#ifdef _DEBUG docstring msg = "Responded to query " + inputMethodQueryFlagsAsString(query) + " = "; - +#endif switch (query) { // The widget accepts input method input case Qt::ImEnabled: { +#ifdef _DEBUG if (d->im_state_.enabled_) - LYXERR(Debug::DEBUG, msg << "true"); + LYXERR(Debug::DEBUG, msg << "\"true\""); else - LYXERR(Debug::DEBUG, msg << "false"); + LYXERR(Debug::DEBUG, msg << "\"false\""); +#endif Q_EMIT queryProcessed(d->im_state_.enabled_); break; } @@ -939,28 +980,39 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) // the starting point of the preedit, so respond with anchor_rect_ // that points the starting point during the editing mode rect = &d->im_state_.anchor_rect_; +#ifdef _DEBUG LYXERR(Debug::DEBUG, " (Composing mode: use anchor_rect_ for ImCursorRectangle)"); +#endif } else rect = &d->im_state_.cursor_rect_; +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << " x:" << rect->x() << " y:" << rect->y() << " w:" << rect->width() << " h:" << rect->height()); +#endif Q_EMIT queryProcessed(*rect); break; } case Qt::ImCurrentSelection: { +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << d->cur_->selectionAsString(false)); +#endif Q_EMIT queryProcessed(toqstr(d->cur_->selectionAsString(false))); break; } // plain text around the input area, for example the current paragraph case Qt::ImSurroundingText: { +#ifdef _DEBUG if (d->im_state_.surrounding_text_.empty()) LYXERR(Debug::DEBUG, msg << "\"\""); + else if (d->im_state_.surrounding_text_.length() <= 20) + LYXERR(Debug::DEBUG, msg << "\"" << + d->im_state_.surrounding_text_ << "\""); else - LYXERR(Debug::DEBUG, msg << - d->im_state_.surrounding_text_.substr(0, 20) << "..."); + LYXERR(Debug::DEBUG, msg << "\"" << + d->im_state_.surrounding_text_.substr(0, 20) << "...\""); +#endif Q_EMIT queryProcessed(toqstr(d->im_state_.surrounding_text_)); break; } @@ -969,17 +1021,24 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) // FIXME: position should be set only when there was a non-virtual // change in the document setAbsolutePosition(*d->cur_); +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << std::dec << d->abs_pos_); +#endif Q_EMIT queryProcessed((qlonglong)d->abs_pos_); break; } // plain text before the cursor case Qt::ImTextBeforeCursor: { updatePosAndSurroundingText(); +#ifdef _DEBUG if (d->im_state_.text_before_.empty()) LYXERR(Debug::DEBUG, msg << "\"\""); + else if (d->im_state_.text_before_. length() <= 20) + LYXERR(Debug::DEBUG, msg << "\"" << d->im_state_.text_before_ << "\""); else - LYXERR(Debug::DEBUG, msg << "…" << d->im_state_.text_before_); + LYXERR(Debug::DEBUG, msg << "\"..." << + d->im_state_.text_before_.substr(0, 20) << "\""); +#endif QVariant str(toqstr(d->im_state_.text_before_)); Q_EMIT queryProcessed(str); break; @@ -987,10 +1046,15 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) // plain text after the cursor case Qt::ImTextAfterCursor: { updatePosAndSurroundingText(); +#ifdef _DEBUG if (d->im_state_.text_after_.empty()) LYXERR(Debug::DEBUG, msg << "\"\""); + else if (d->im_state_.text_after_.length() <= 20) + LYXERR(Debug::DEBUG, msg << "\"" << d->im_state_.text_after_ << "\""); else - LYXERR(Debug::DEBUG, msg << d->im_state_.text_after_); + LYXERR(Debug::DEBUG, msg << "\"..." << + d->im_state_.text_after_.substr(0, 20) << "\""); +#endif QVariant str(toqstr(d->im_state_.text_after_)); Q_EMIT queryProcessed(str); break; @@ -998,14 +1062,18 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) // logical position of the cursor within the text surrounding the input area case Qt::ImCursorPosition: { updatePosAndSurroundingText(); +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << std::dec << d->cur_->pos()); +#endif Q_EMIT queryProcessed((qlonglong)d->cur_->pos()); break; } // position of the selection anchor case Qt::ImAnchorPosition: { updatePosAndSurroundingText(); +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << std::dec << (unsigned int)d->anchor_pos_); +#endif Q_EMIT queryProcessed(QVariant((unsigned int)d->anchor_pos_)); break; } @@ -1014,17 +1082,21 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) d->work_area_->viewport()->y(), d->work_area_->viewport()->width(), d->work_area_->viewport()->height()); +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << "(x,y,w,h) = " << viewport.x() << ", " << viewport.y() << ", " << viewport.width() << ", " << viewport.height() << ")"); +#endif Q_EMIT queryProcessed(viewport); break; } // hints for input method on expected input case Qt::ImHints: { +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << "0x" << std::hex << d->work_area_->inputMethodHints() << std::dec); +#endif Q_EMIT queryProcessed((qlonglong)d->work_area_->inputMethodHints()); break; } @@ -1032,7 +1104,9 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) case Qt::ImPreferredLanguage: { QLocale locale(toqstr(d->cur_->getFont().language()->code())); QString lang = locale.languageToString(locale.language()); +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << lang); +#endif Q_EMIT queryProcessed(lang); break; } @@ -1040,22 +1114,27 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query) // it seems this property is not yet used by most of input methods // as of August 2024. case Qt::ImAnchorRectangle: { +#ifdef _DEBUG LYXERR(Debug::DEBUG, msg << " x:" << d->im_state_.anchor_rect_.x() << " y:" << d->im_state_.anchor_rect_.y() << " w:" << d->im_state_.anchor_rect_.width() << " h:" << d->im_state_.anchor_rect_.height()); +#endif Q_EMIT queryProcessed(d->im_state_.anchor_rect_); break; } default: { QVariant null; +#ifdef _DEBUG LYXERR(Debug::DEBUG, "Unsupported query by LyX came in: " << inputMethodQueryFlagsAsString(query)); +#endif Q_EMIT queryProcessed(null); } } } +#ifdef _DEBUG // Returns enum Qt::InputMethodQuery constant from its value. // This is for debugging purpose only. docstring GuiInputMethod::inputMethodQueryFlagsAsString(unsigned long int query) const @@ -1083,7 +1162,7 @@ docstring GuiInputMethod::inputMethodQueryFlagsAsString(unsigned long int query) } return str; } - +#endif // // helper functions @@ -1175,6 +1254,7 @@ pos_type GuiInputMethod::initializePositions(Cursor * cur) // real_boundary, i.e. d->real_boundary_. real_boundary |= post_real_boundary; +#ifdef _DEBUG LYXERR(Debug::DEBUG, "========== BEGIN: initializePositions =========="); LYXERR(Debug::DEBUG, "cur_row_idx = " << cur_row_idx << "\treal_boundary = " << real_boundary); @@ -1193,6 +1273,7 @@ pos_type GuiInputMethod::initializePositions(Cursor * cur) LYXERR(Debug::DEBUG, "wchar width = " << horizontalAdvance(d->preedit_str_.substr(0,1))); LYXERR(Debug::DEBUG, "========== END: initializePositions =========="); +#endif return cur_row_idx; } @@ -1307,6 +1388,7 @@ GuiInputMethod::PreeditRow GuiInputMethod::getCaretInfo() } else caret_row.pos = d->cur_pos_; +#ifdef _DEBUG LYXERR(Debug::DEBUG, "============= BEGIN: getCaretInfo ==============="); LYXERR(Debug::DEBUG, "*d->cur_pos_ptr = " << d->cur_pos_); LYXERR(Debug::DEBUG, "second_row_pos = " << second_row_pos); @@ -1317,6 +1399,7 @@ GuiInputMethod::PreeditRow GuiInputMethod::getCaretInfo() LYXERR(Debug::DEBUG, "d->real_boundary_ = " << d->real_boundary_ << "\td->virtual_boundary_ = " << d->virtual_boundary_); LYXERR(Debug::DEBUG, "=============== END: getCaretInfo ==============="); +#endif return caret_row; } @@ -1351,10 +1434,12 @@ void GuiInputMethod::setSurroundingText(const Cursor & cur) d->im_state_.surrounding_text_ = partext; } - LYXERR(Debug::DEBUG, "surrounding text before cursor = " << - d->im_state_.text_before_); - LYXERR(Debug::DEBUG, "surrounding text after cursor = " << - d->im_state_.text_after_); +#ifdef _DEBUG + LYXERR(Debug::DEBUG, "surrounding text before cursor = \"" << + d->im_state_.text_before_ << "\""); + LYXERR(Debug::DEBUG, "surrounding text after cursor = \"" << + d->im_state_.text_after_ << "\""); +#endif // notify the input method about the update #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) diff --git a/src/frontends/qt/GuiInputMethod.h b/src/frontends/qt/GuiInputMethod.h index 88fd541392..0d95803f22 100644 --- a/src/frontends/qt/GuiInputMethod.h +++ b/src/frontends/qt/GuiInputMethod.h @@ -170,8 +170,10 @@ private: pos_type pickNextSegFromTurnout(pos_type next_seg_pos, QTextCharFormat * char_format = nullptr); /// Register preedit segment for final output pos_type registerSegment(pos_type start, size_type length, QTextCharFormat char_format); +#ifdef _DEBUG /// Returns enum Qt::InputMethodQuery constant from its value docstring inputMethodQueryFlagsAsString(unsigned long int query) const; +#endif /// update cursor position and surrounding text void updatePosAndSurroundingText(); diff --git a/src/frontends/qt/GuiWorkArea.h b/src/frontends/qt/GuiWorkArea.h index 1ac5b07643..84992997da 100644 --- a/src/frontends/qt/GuiWorkArea.h +++ b/src/frontends/qt/GuiWorkArea.h @@ -168,7 +168,7 @@ private: /// key press event. It also knows how to handle ShortcutOverride events to /// avoid code duplication. void keyPressEvent(QKeyEvent * ev) override; - /// IM events + /// input method event void inputMethodEvent(QInputMethodEvent * ev) override; /// IM query QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs