musredit 1.0.0
Loading...
Searching...
No Matches
PTextEdit.h
Go to the documentation of this file.
1/****************************************************************************
2
3 PTextEdit.h
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8*****************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2010-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
49
50#ifndef _PTEXTEDIT_H_
51#define _PTEXTEDIT_H_
52
53#include <memory>
54
55#include <QAction>
56#include <QMainWindow>
57#include <QString>
58#include <QStringList>
59#include <QMap>
60#include <QTimer>
61#include <QString>
62#include <QVector>
63#include <QProcess>
64#include <QFileInfo>
65#include <QByteArray>
66#include <QFileSystemWatcher>
67#include <QComboBox>
68
69#include <QtDebug>
70
71#include "PAdmin.h"
72#include "musredit.h"
73
74class PSubTextEdit;
75class PAdmin;
76class QFileSystemWatcher;
77class QAction;
78class QComboBox;
79class QTabWidget;
80class QTextEdit;
81class QMenu;
82
83//----------------------------------------------------------------------------------------------
237class PTextEdit : public QMainWindow
238{
239 Q_OBJECT
240
241public:
302 PTextEdit( QWidget *parent = nullptr );
303
316 int getEditW() { return fEditW; }
317
330 int getEditH() { return fEditH; }
331
332public slots:
354 void aboutToQuit();
355
356signals:
367 void close();
368
369private:
380 void setupFileActions();
381
391 void setupEditActions();
392
401 void setupTextActions();
402
413 void setupMusrActions();
414
423 void setupHelpActions();
424
434 void setupJumpToBlock();
435
450 void load( const QString &f, const int index=-1 );
451
463
475 void doConnections( PSubTextEdit *e );
476
487
488private slots:
489 // Block insertion slots (delegate to PSubTextEdit)
495 void insertTitle();
496
503
509 void insertTheoryBlock();
510
518 void insertTheoryFunction(QAction *a);
519
525 void insertFunctionBlock();
526
532 void insertAsymRunBlock();
533
540
547
553 void insertCommandBlock();
554
560 void insertFourierBlock();
561
567 void insertPlotBlock();
568
575
576 // File menu slots
582 void fileNew();
583
590 void fileOpen();
591
598 void fileOpenRecent();
599
605 void fileReload();
606
613 void fileOpenPrefs();
614
622 void fileSave();
623
630 void fileSaveAs();
631
637 void fileSavePrefs();
638
644 void filePrint();
645
653 void fileClose( const bool check = true );
654
660 void fileCloseAll();
661
667 void fileCloseAllOthers();
668
674 void fileExit();
675
676 // Edit menu slots
678 void editUndo();
679
681 void editRedo();
682
684 void editSelectAll();
685
687 void editCut();
688
690 void editCopy();
691
693 void editPaste();
694
700 void editFind();
701
706 void editFindNext();
707
712 void editFindPrevious();
713
719 void editFindAndReplace();
720
725 void editComment();
726
731 void editUncomment();
732
733 // Text menu slots
738 void textFamily( const QString &f );
739
744 void textSize( const QString &p );
745
746 // Musr menu slots
752 void musrWiz();
753
758 void musrCalcChisq();
759
765 void musrFit();
766
773 void musrMsr2Data();
774
779 void musrView();
780
785 void musrView2Dat();
786
791 void musrT0();
792
798 void musrFT();
799
806 void musrPrefs();
807
813 void musrSwapMsrMlog();
814
820 void musrSetSteps();
821
827 void musrDump();
828
834 void mupp();
835
836 // Help menu slots
841 void helpContents();
842
847 void helpAboutQt();
848
854 void helpAbout();
855
856 // Process exit status handlers
864 void exitStatusMusrWiz(int exitCode, QProcess::ExitStatus exitStatus);
865
873 void exitStatusMusrSetSteps(int exitCode, QProcess::ExitStatus exitStatus);
874
875 // Editor event handlers
881 void fontChanged( const QFont &f );
882
889 void textChanged(const bool forced = false);
890
897
898 // Find/replace operation handlers
904 void replace();
905
911 void replaceAndClose();
912
918 void replaceAll();
919
920 // Tab and file system handlers
927 void applyFontSettings(int);
928
935 void fileChanged(const QString &fileName);
936
944
945 // Navigation
952 void jumpToBlock(int idx);
953
954private:
955 bool fDarkMenuIcon{false};
956 bool fDarkToolBarIcon{false};
957 std::unique_ptr<PAdmin> fAdmin;
958 std::unique_ptr<QFileSystemWatcher> fFileSystemWatcher;
961 QString fLastDirInUse{QString("")};
962 QStringList fMusrFTPrevCmd;
963 int fEditW{900}, fEditH{800};
964 QStatusBar *fStatusBar{nullptr};
965
966 QMap<QString, QAction*> fActions;
967 std::unique_ptr<QAction> fMusrT0Action;
968
971
972 std::unique_ptr<QComboBox> fComboFont;
973 std::unique_ptr<QComboBox> fComboSize;
974 bool fFontChanging{false};
975 std::unique_ptr<QComboBox> fJumpToBlock;
976
977 std::unique_ptr<QTabWidget> fTabWidget;
978 QMap<PSubTextEdit*, QString> fFilenames;
979
982
995 bool getTheme();
996
1006 void fillRecentFiles();
1007
1021 QStringList getRunList(QString runListStr, bool &ok);
1022
1036 bool fileAlreadyOpen(QFileInfo &finfo, int &idx);
1037
1047 void switchMenuIcons();
1048
1058 void switchToolbarIcons();
1059};
1060
1061
1062#endif // _PTEXTEDIT_H_
Administration and configuration management for musredit.
Central administration class for musredit configuration management.
Definition PAdmin.h:209
Enhanced text editor for msr file editing with block insertion support.
void exitStatusMusrWiz(int exitCode, QProcess::ExitStatus exitStatus)
Slot: Handles exit status of musrWiz process.
void insertTheoryBlock()
Slot: Inserts a THEORY block into the current editor.
int getEditH()
Gets the configured editor height.
Definition PTextEdit.h:330
void replaceAll()
Slot: Replaces all occurrences without prompting.
QMap< QString, QAction * > fActions
Definition PTextEdit.h:966
QString fLastDirInUse
string holding the path from where the last file was loaded.
Definition PTextEdit.h:961
void setupFileActions()
Initializes File menu and toolbar actions.
std::unique_ptr< QComboBox > fComboSize
combo box for the font size
Definition PTextEdit.h:973
void musrView()
Slot: Launches musrView for viewing fit results.
PMsr2DataParam * fMsr2DataParam
structure holding the necessary input information for msr2data
Definition PTextEdit.h:969
QStringList getRunList(QString runListStr, bool &ok)
Parses a run list string into individual run numbers.
QTimer fFileSystemWatcherTimeout
timer used to re-enable file system watcher. Needed to delay the re-enabling
Definition PTextEdit.h:960
bool fileAlreadyOpen(QFileInfo &finfo, int &idx)
Checks if a file is already open in a tab.
void editUndo()
Slot: Undo last edit operation.
void fileCloseAll()
Slot: Closes all open tabs.
void editComment()
Slot: Comments out selected lines.
std::unique_ptr< QComboBox > fComboFont
combo box for the font selector
Definition PTextEdit.h:972
void musrDump()
Slot: Dumps raw histogram data from run files.
void applyFontSettings(int)
Slot: Applies font settings when tab changes.
void fileSystemWatcherActivation()
Manages file system watcher activation state.
void musrWiz()
Slot: Launches musrWiz (msr file creation wizard).
bool fFileSystemWatcherActive
flag to enable/disable the file system watcher
Definition PTextEdit.h:959
void fileSaveAs()
Slot: Saves the current file with a new name.
void close()
Signal: Emitted when the main window is closing.
void load(const QString &f, const int index=-1)
Loads a file into the editor.
void editCut()
Slot: Cut selected text to clipboard.
void fontChanged(const QFont &f)
Slot: Responds to font changes in editor.
PTextEdit(QWidget *parent=nullptr)
Constructs the main musredit window.
void setupHelpActions()
Initializes Help menu actions.
bool fFontChanging
flag needed to prevent some textChanged feature to occure when only the font changed
Definition PTextEdit.h:974
void aboutToQuit()
Slot: Cleanup handler called before application quits.
void fileSavePrefs()
Slot: Saves the preferences file.
PFindReplaceData * fFindReplaceData
structure holding the ncessary input for find/replace
Definition PTextEdit.h:970
void musrCalcChisq()
Slot: Calculates chi-square for current msr file.
void insertFunctionBlock()
Slot: Inserts a FUNCTIONS block into the current editor.
QMap< PSubTextEdit *, QString > fFilenames
mapper between tab widget object and filename
Definition PTextEdit.h:978
void fillRecentFiles()
Populates the Recent Files menu.
bool getTheme()
Detects the current system theme.
void textChanged(const bool forced=false)
Slot: Responds to text changes in editor.
void musrSetSteps()
Slot: Launches musrStep for setting fit step sizes.
std::unique_ptr< QFileSystemWatcher > fFileSystemWatcher
checks if msr-files are changing on the disk while being open in musredit.
Definition PTextEdit.h:958
void fileSave()
Slot: Saves the current file.
void musrFit()
Slot: Executes fit with current msr file.
void helpContents()
Slot: Opens online documentation.
void helpAboutQt()
Slot: Displays Qt About dialog.
QAction * fRecentFilesAction[MAX_RECENT_FILES]
array of the recent file actions
Definition PTextEdit.h:981
int getEditW()
Gets the configured editor width.
Definition PTextEdit.h:316
bool fDarkToolBarIcon
flag indicating if a dark or plain icon shall be used in the toolbar
Definition PTextEdit.h:956
QStringList fMusrFTPrevCmd
Definition PTextEdit.h:962
void fileOpenPrefs()
Slot: Opens the preferences file in a new tab.
void fileCloseAllOthers()
Slot: Closes all tabs except the current one.
void setupMusrActions()
Initializes Musr menu and toolbar actions.
void setupTextActions()
Initializes Text menu and toolbar actions.
void editUncomment()
Slot: Uncomments selected lines.
void insertTheoryFunction(QAction *a)
Slot: Inserts a specific theory function into the current editor.
void switchToolbarIcons()
Switches toolbar icons between dark and plain variants.
void editRedo()
Slot: Redo previously undone edit operation.
void insertParameterBlock()
Slot: Inserts a FITPARAMETER block into the current editor.
void insertCommandBlock()
Slot: Inserts a COMMANDS block into the current editor.
void fileChanged(const QString &fileName)
Slot: Handles file system watcher notifications.
std::unique_ptr< PAdmin > fAdmin
pointer to the xml-startup file informations. Needed for different purposes like default working- and...
Definition PTextEdit.h:957
void insertTitle()
Slot: Inserts a title block into the current editor.
void helpAbout()
Slot: Displays musredit About dialog.
void editSelectAll()
Slot: Select all text in current editor.
void fileExit()
Slot: Exits the application.
void editFindAndReplace()
Slot: Opens find and replace dialog.
void musrSwapMsrMlog()
Slot: Swaps between .msr and .mlog files.
void setFileSystemWatcherActive()
Slot: Re-enables file system watcher after delay.
PSubTextEdit * currentEditor() const
Gets the currently active editor widget.
void insertPlotBlock()
Slot: Inserts a PLOT block into the current editor.
QStatusBar * fStatusBar
Definition PTextEdit.h:964
void insertNonMusrRunBlock()
Slot: Inserts a non-µSR RUN block into the current editor.
std::unique_ptr< QComboBox > fJumpToBlock
combo box used to jump to the msr-file blocks
Definition PTextEdit.h:975
void editFindNext()
Slot: Finds next occurrence of search text.
void musrView2Dat()
Slot: Launches musrView in 2-data file mode.
void replace()
Slot: Replaces current match and finds next occurrence.
void mupp()
Slot: Launches mupp (muon parameter plot).
void textFamily(const QString &f)
Slot: Changes font family for current editor.
void setupEditActions()
Initializes Edit menu and toolbar actions.
void editFind()
Slot: Opens find dialog.
std::unique_ptr< QAction > fMusrT0Action
Definition PTextEdit.h:967
void currentCursorPosition()
Slot: Updates status bar with current cursor position.
void setupJumpToBlock()
Initializes the Jump to Block combo box.
void musrFT()
Slot: Opens Fourier transform dialog.
void fileReload()
Slot: Reloads the current file from disk.
void filePrint()
Slot: Prints the current file.
void editFindPrevious()
Slot: Finds previous occurrence of search text.
void editCopy()
Slot: Copy selected text to clipboard.
void musrPrefs()
Slot: Opens preferences dialog.
void insertAsymRunBlock()
Slot: Inserts an asymmetry RUN block into the current editor.
void fileOpen()
Slot: Opens a file dialog to load an msr file.
void insertSingleHistRunBlock()
Slot: Inserts a single histogram RUN block into the current editor.
void insertStatisticBlock()
Slot: Inserts a STATISTIC block into the current editor.
void switchMenuIcons()
Switches menu icons between dark and plain variants.
void insertFourierBlock()
Slot: Inserts a FOURIER block into the current editor.
void fileOpenRecent()
Slot: Opens a recently used file.
void textSize(const QString &p)
Slot: Changes font size for current editor.
void exitStatusMusrSetSteps(int exitCode, QProcess::ExitStatus exitStatus)
Slot: Handles exit status of musrSetSteps process.
void jumpToBlock(int idx)
Slot: Jumps cursor to selected msr file block.
void musrT0()
Slot: Opens musrT0 dialog for determining t0 timing parameter.
bool fDarkMenuIcon
flag indicating if a dark or plain icon shall be used in the menu pull-downs
Definition PTextEdit.h:955
void musrMsr2Data()
Slot: Opens msr2data conversion dialog.
std::unique_ptr< QTabWidget > fTabWidget
tab widget in which the text editor(s) are placed
Definition PTextEdit.h:977
void editPaste()
Slot: Paste text from clipboard at cursor position.
void doConnections(PSubTextEdit *e)
Establishes signal-slot connections for an editor.
void fileClose(const bool check=true)
Slot: Closes the current tab.
QMenu * fRecentFilesMenu
recent file menu
Definition PTextEdit.h:980
void fileNew()
Slot: Creates a new empty msr file in a new tab.
void replaceAndClose()
Slot: Replaces current match and closes replace dialog.
Common definitions and data structures for the musredit application.
#define MAX_RECENT_FILES
Maximum number of recently opened files to track.
Definition musredit.h:55
Configuration structure for find and replace operations.
Definition musredit.h:109
Parameter structure for msr2data tool integration.
Definition musredit.h:73