added jump to block feature.

This commit is contained in:
2024-12-02 20:05:50 +01:00
parent 6f8b0a2341
commit 5c3accc6ed
5 changed files with 101 additions and 1 deletions

View File

@ -125,6 +125,7 @@ PTextEdit::PTextEdit( QWidget *parent )
setupEditActions();
setupTextActions();
setupMusrActions();
setupJumpToBlock();
setupHelpActions();
fTabWidget = std::make_unique<QTabWidget>( this );
@ -958,6 +959,31 @@ void PTextEdit::setupHelpActions()
menu->addAction(a);
}
//----------------------------------------------------------------------------------------------------
/**
* <p>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<QComboBox>();
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());
}
//----------------------------------------------------------------------------------------------------
/**
* <p>load a msr-file.
@ -3306,6 +3332,26 @@ void PTextEdit::setFileSystemWatcherActive()
fFileSystemWatcherActive = true;
}
//----------------------------------------------------------------------------------------------------
/**
* <p>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