From 3004823f36da804a243272d52be707674f43b1be Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Mon, 2 Dec 2024 20:05:50 +0100 Subject: [PATCH] added jump to block feature. --- CMakeLists.txt | 2 +- src/musredit_qt5/musredit/PTextEdit.cpp | 46 +++++++++++++++++++++++++ src/musredit_qt5/musredit/PTextEdit.h | 4 +++ src/musredit_qt6/musredit/PTextEdit.cpp | 46 +++++++++++++++++++++++++ src/musredit_qt6/musredit/PTextEdit.h | 4 +++ 5 files changed, 101 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abf363be..6dc72763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # - musrfit --- DKS ----------------------------------------------------------- cmake_minimum_required(VERSION 3.17) -project(musrfit VERSION 1.9.5 LANGUAGES C CXX) +project(musrfit VERSION 1.9.6 LANGUAGES C CXX) #--- musrfit specific options ------------------------------------------------- option(dks "build musrfit with DKS (GPU/MIC) support" ON) diff --git a/src/musredit_qt5/musredit/PTextEdit.cpp b/src/musredit_qt5/musredit/PTextEdit.cpp index 2e57ca34..ad3d64f6 100644 --- a/src/musredit_qt5/musredit/PTextEdit.cpp +++ b/src/musredit_qt5/musredit/PTextEdit.cpp @@ -125,6 +125,7 @@ PTextEdit::PTextEdit( QWidget *parent ) setupEditActions(); setupTextActions(); setupMusrActions(); + setupJumpToBlock(); setupHelpActions(); fTabWidget = std::make_unique( this ); @@ -958,6 +959,31 @@ void PTextEdit::setupHelpActions() menu->addAction(a); } +//---------------------------------------------------------------------------------------------------- +/** + *

Setup the JumpToBlock actions. + */ +void PTextEdit::setupJumpToBlock() +{ + QToolBar *tb = new QToolBar( this ); + tb->setWindowTitle( "JumpToBlock Actions" ); + addToolBar( tb ); + + QStringList jumpToBlockStr = {"FITPARAMETER", "THEORY", "FUNCTIONS", "GLOBAL", "RUN", "COMMANDS", "PLOT", "FOURIER", "STATISTIC"}; + fJumpToBlock = std::make_unique(); + if (fJumpToBlock == nullptr) + return; + fJumpToBlock->addItems(jumpToBlockStr); + fJumpToBlock->setEditable(false); + + connect( fJumpToBlock.get(), SIGNAL( activated(int) ), this, SLOT( jumpToBlock(int) )); + + QLabel *jstr = new QLabel(" Jump to block: "); + + tb->addWidget(jstr); + tb->addWidget(fJumpToBlock.get()); +} + //---------------------------------------------------------------------------------------------------- /** *

load a msr-file. @@ -3316,6 +3342,26 @@ void PTextEdit::setFileSystemWatcherActive() fFileSystemWatcherActive = true; } +//---------------------------------------------------------------------------------------------------- +/** + *

slot called when jumpToBlock combobox is selected + * @param idx + */ +void PTextEdit::jumpToBlock(int idx) +{ + QString str = fJumpToBlock->itemText(idx); + + QTextDocument::FindFlags flags= QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords; + + bool found = currentEditor()->find(str, flags); + if (found) + return; + + // set cursor to start + currentEditor()->moveCursor(QTextCursor::Start); + currentEditor()->find(str, flags); +} + //---------------------------------------------------------------------------------------------------- /** * @brief PTextEdit::getTheme diff --git a/src/musredit_qt5/musredit/PTextEdit.h b/src/musredit_qt5/musredit/PTextEdit.h index 680ff04b..11e8b0b4 100644 --- a/src/musredit_qt5/musredit/PTextEdit.h +++ b/src/musredit_qt5/musredit/PTextEdit.h @@ -86,6 +86,7 @@ private: void setupTextActions(); void setupMusrActions(); void setupHelpActions(); + void setupJumpToBlock(); void load( const QString &f, const int index=-1 ); PSubTextEdit *currentEditor() const; void doConnections( PSubTextEdit *e ); @@ -167,6 +168,8 @@ private slots: void fileChanged(const QString &fileName); void setFileSystemWatcherActive(); + void jumpToBlock(int idx); + private: bool fDarkMenuIcon; ///< flag indicating if a dark or plain icon shall be used in the menu pull-downs bool fDarkToolBarIcon; ///< flag indicating if a dark or plain icon shall be used in the toolbar @@ -187,6 +190,7 @@ private: std::unique_ptr fComboFont; ///< combo box for the font selector std::unique_ptr fComboSize; ///< combo box for the font size bool fFontChanging; ///< flag needed to prevent some textChanged feature to occure when only the font changed + std::unique_ptr fJumpToBlock; ///< combo box used to jump to the msr-file blocks std::unique_ptr fTabWidget; ///< tab widget in which the text editor(s) are placed QMap fFilenames; ///< mapper between tab widget object and filename diff --git a/src/musredit_qt6/musredit/PTextEdit.cpp b/src/musredit_qt6/musredit/PTextEdit.cpp index b2edbc19..e1c4a558 100644 --- a/src/musredit_qt6/musredit/PTextEdit.cpp +++ b/src/musredit_qt6/musredit/PTextEdit.cpp @@ -127,6 +127,7 @@ PTextEdit::PTextEdit( QWidget *parent ) setupEditActions(); setupTextActions(); setupMusrActions(); + setupJumpToBlock(); setupHelpActions(); fTabWidget = std::make_unique( this ); @@ -965,6 +966,31 @@ void PTextEdit::setupHelpActions() menu->addAction(a); } +//---------------------------------------------------------------------------------------------------- +/** + *

Setup the JumpToBlock actions. + */ +void PTextEdit::setupJumpToBlock() +{ + QToolBar *tb = new QToolBar( this ); + tb->setWindowTitle( "JumpToBlock Actions" ); + addToolBar( tb ); + + QStringList jumpToBlockStr = {"FITPARAMETER", "THEORY", "FUNCTIONS", "GLOBAL", "RUN", "COMMANDS", "PLOT", "FOURIER", "STATISTIC"}; + fJumpToBlock = std::make_unique(); + if (fJumpToBlock == nullptr) + return; + fJumpToBlock->addItems(jumpToBlockStr); + fJumpToBlock->setEditable(false); + + connect( fJumpToBlock.get(), SIGNAL( activated(int) ), this, SLOT( jumpToBlock(int) )); + + QLabel *jstr = new QLabel(" Jump to block: "); + + tb->addWidget(jstr); + tb->addWidget(fJumpToBlock.get()); +} + //---------------------------------------------------------------------------------------------------- /** *

load a msr-file. @@ -3291,6 +3317,26 @@ void PTextEdit::setFileSystemWatcherActive() fFileSystemWatcherActive = true; } +//---------------------------------------------------------------------------------------------------- +/** + *

slot called when jumpToBlock combobox is selected + * @param idx + */ +void PTextEdit::jumpToBlock(int idx) +{ + QString str = fJumpToBlock->itemText(idx); + + QTextDocument::FindFlags flags= QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords; + + bool found = currentEditor()->find(str, flags); + if (found) + return; + + // set cursor to start + currentEditor()->moveCursor(QTextCursor::Start); + currentEditor()->find(str, flags); +} + //---------------------------------------------------------------------------------------------------- /** * @brief PTextEdit::getTheme diff --git a/src/musredit_qt6/musredit/PTextEdit.h b/src/musredit_qt6/musredit/PTextEdit.h index 6a060146..c234dcba 100644 --- a/src/musredit_qt6/musredit/PTextEdit.h +++ b/src/musredit_qt6/musredit/PTextEdit.h @@ -86,6 +86,7 @@ private: void setupTextActions(); void setupMusrActions(); void setupHelpActions(); + void setupJumpToBlock(); void load( const QString &f, const int index=-1 ); PSubTextEdit *currentEditor() const; void doConnections( PSubTextEdit *e ); @@ -167,6 +168,8 @@ private slots: void fileChanged(const QString &fileName); void setFileSystemWatcherActive(); + void jumpToBlock(int idx); + private: bool fDarkMenuIcon; ///< flag indicating if a dark or plain icon shall be used in the menu pull-downs bool fDarkToolBarIcon; ///< flag indicating if a dark or plain icon shall be used in the toolbar @@ -187,6 +190,7 @@ private: std::unique_ptr fComboFont; ///< combo box for the font selector std::unique_ptr fComboSize; ///< combo box for the font size bool fFontChanging; ///< flag needed to prevent some textChanged feature to occure when only the font changed + std::unique_ptr fJumpToBlock; ///< combo box used to jump to the msr-file blocks std::unique_ptr fTabWidget; ///< tab widget in which the text editor(s) are placed QMap fFilenames; ///< mapper between tab widget object and filename