musredit 1.0.0
Loading...
Searching...
No Matches
PSubTextEdit.cpp
Go to the documentation of this file.
1/****************************************************************************
2
3 PSubTextEdit.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8*****************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2009-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
45
46#include <memory>
47
48#include <QAction>
49#include <QMenu>
50#include <QDateTime>
51#include <QLineEdit>
52#include <QComboBox>
53#include <QMessageBox>
54#include <QIcon>
55#include <QPixmap>
56#include <QImage>
57
58#include "PAdmin.h"
59#include "PSubTextEdit.h"
68#include "PGetPlotBlockDialog.h"
69#include "PMsrHighlighter.h"
70
71//----------------------------------------------------------------------------------------------------
101PSubTextEdit::PSubTextEdit(PAdmin *admin, QWidget *parent) :
102 QPlainTextEdit(parent),
103 fAdmin(admin)
104{
105 // Pass the current text document to the highlighter. This ensures that every
106 // time a new .msr file or tab is spawned, the document registers the parser
107 // formatting.
108 PMsrHighlighter *highlight = new PMsrHighlighter(this->document());
109}
110
111//----------------------------------------------------------------------------------------------------
165{
166 QString str = toPlainText();
167 int idx = str.indexOf("fittype");
168 if (idx == -1)
169 return -1;
170
171 bool ok;
172 for (int i=idx+7; i<str.length(); i++) {
173 if (str[i] != ' ') {
174 idx = QString(str[i]).toInt(&ok);
175 if (!ok)
176 idx = -1;
177 break;
178 }
179 }
180
181 return idx;
182}
183
184//----------------------------------------------------------------------------------------------------
220{
221 // for the time being the url's are hard coded but should be transfered to the XML startup
222 std::unique_ptr<PGetTitleBlockDialog> dlg = std::make_unique<PGetTitleBlockDialog>(fAdmin->getHelpUrl("title"));
223
224 if (dlg == nullptr)
225 return;
226
227 if (dlg->exec() == QDialog::Accepted) {
228 QString title = dlg->getTitle();
229 insertPlainText(title+"\n");
230 }
231}
232
233//----------------------------------------------------------------------------------------------------
238{
239 // for the time being the url's are hard coded but should be transfered to the XML startup
240 std::unique_ptr<PGetParameterBlockDialog> dlg = std::make_unique<PGetParameterBlockDialog>(fAdmin->getHelpUrl("parameters"));
241
242 if (dlg == nullptr)
243 return;
244
245 if (dlg->exec() == QDialog::Accepted) {
246 insertPlainText(dlg->getParams());
247 }
248}
249
250//----------------------------------------------------------------------------------------------------
306{
307 QString str = "????";
308
309 int idx = -1;
310 for (unsigned int i=0; i<fAdmin->getTheoryCounts(); i++) {
311 if (name == fAdmin->getTheoryItem(i)->label) {
312 idx = i;
313 break;
314 }
315 }
316
317 if (idx == -1)
318 return;
319
320 PTheory *theoItem = fAdmin->getTheoryItem(idx);
321 if (theoItem == 0)
322 return;
323
324 // add theory function name
325 str = theoItem->name + " ";
326 if (theoItem->name == "userFcn") {
327 str += "libMyLibrary.so TMyFunction ";
328 }
329
330 // add pseudo parameters
331 for (int i=0; i<theoItem->params; i++) {
332 str += QString("%1").arg(i+1) + " ";
333 }
334
335 // add comment
336 str += theoItem->comment;
337
338 // add newline
339 str += "\n";
340
341 insertPlainText(str);
342}
343
344//----------------------------------------------------------------------------------------------------
349{
350 // for the time being the url's are hard coded but should be transfered to the XML startup
351 std::unique_ptr<PGetTheoryBlockDialog> dlg = std::make_unique<PGetTheoryBlockDialog>(fAdmin, fAdmin->getHelpUrl("theory"));
352
353 if (dlg == nullptr)
354 return;
355
356 if (dlg->exec() == QDialog::Accepted) {
357 insertPlainText(dlg->getTheoryBlock());
358 insertPlainText("\n");
359 }
360}
361
362//----------------------------------------------------------------------------------------------------
367{
368 // for the time being the url's are hard coded but should be transfered to the XML startup
369 std::unique_ptr<PGetFunctionsBlockDialog> dlg = std::make_unique<PGetFunctionsBlockDialog>(fAdmin->getHelpUrl("functions"));
370
371 if (dlg == nullptr)
372 return;
373
374 if (dlg->exec() == QDialog::Accepted) {
375 insertPlainText(dlg->getFunctionsBlock());
376 insertPlainText("\n\n");
377 }
378}
379
380//----------------------------------------------------------------------------------------------------
385{
386 // for the time being the url's are hard coded but should be transfered to the XML startup
387 std::unique_ptr<PGetAsymmetryRunBlockDialog> dlg = std::make_unique<PGetAsymmetryRunBlockDialog>(fAdmin->getHelpUrl("run"));
388
389 if (dlg == nullptr)
390 return;
391
392 if (dlg->exec() == QDialog::Accepted) {
393 QString str, workStr;
394 bool valid = true, present = true;
395 // check if there is already a run block present, necessary because of the '####' line
396 // STILL MISSING
397
398 // add run line
399 str += dlg->getRunHeaderInfo();
400
401 // add fittype
402 str += "fittype 2 (asymmetry fit)\n";
403
404 // add alpha if present
405 workStr = dlg->getAlphaParameter(present);
406 if (present) {
407 str += workStr;
408 }
409
410 // add beta if present
411 workStr = dlg->getBetaParameter(present);
412 if (present) {
413 str += workStr;
414 }
415
416 // add map
417 workStr = dlg->getMap(valid);
418 if (valid) {
419 str += workStr;
420 } else {
421 QMessageBox::critical(this, "ERROR",
422 "Given map not valid, will add a default map line",
423 QMessageBox::Ok, QMessageBox::NoButton);
424 str += "map 0 0 0 0 0 0 0 0 0 0\n";
425 }
426
427 // add forward
428 str += dlg->getForward();
429
430 // add backward
431 str += dlg->getBackward();
432
433 // add background or backgr.fix
434 workStr = dlg->getBackground(valid);
435 str += workStr;
436 if (!valid) {
437 QMessageBox::critical(this, "ERROR",
438 "Either <b>background</b> or <b>backgr.fix</b> is needed!\nWill set <b>background</b> to 0..10, please correct!",
439 QMessageBox::Ok, QMessageBox::NoButton);
440 }
441
442 // add data
443 workStr = dlg->getData(valid);
444 if (valid) {
445 str += workStr;
446 } else {
447 QMessageBox::critical(this, "ERROR",
448 "Not all Data entries are present.Fix is needed!\nWill not set anything!",
449 QMessageBox::Ok, QMessageBox::NoButton);
450 }
451
452 // add t0 if present
453 workStr = dlg->getT0(present);
454 if (present) {
455 str += workStr;
456 } else {
457 QMessageBox::warning(this, "ERROR",
458 "T0's not given, assume that they are present in the data file!",
459 QMessageBox::Ok, QMessageBox::NoButton);
460 }
461
462 // add fit range
463 workStr = dlg->getFitRange(valid);
464 str += workStr;
465 if (!valid) {
466 QMessageBox::critical(this, "ERROR",
467 "No valid fit range is given.Fix is needed!\nWill add a default one!",
468 QMessageBox::Ok, QMessageBox::NoButton);
469 }
470
471 // add packing
472 workStr = dlg->getPacking(present);
473 str += workStr;
474 if (!present) {
475 QMessageBox::critical(this, "ERROR",
476 "No valid packing/binning is given.Fix is needed!\nWill add a default one!",
477 QMessageBox::Ok, QMessageBox::NoButton);
478 }
479
480 // insert Asymmetry Run Block at the current cursor position
481 insertPlainText(str);
482 }
483}
484
485//----------------------------------------------------------------------------------------------------
490{
491 // for the time being the url's are hard coded but should be transfered to the XML startup
492 std::unique_ptr<PGetSingleHistoRunBlockDialog> dlg = std::make_unique<PGetSingleHistoRunBlockDialog>(fAdmin->getHelpUrl("run"));
493
494 if (dlg == nullptr)
495 return;
496
497 if (dlg->exec() == QDialog::Accepted) {
498 QString str, workStr;
499 bool valid = true, present = true;
500 // check if there is already a run block present, necessary because of the '####' line
501 // STILL MISSING
502
503 // add run line
504 str += dlg->getRunHeaderInfo();
505
506 // add fittype
507 str += "fittype 0 (single histogram fit)\n";
508
509 // add map
510 workStr = dlg->getMap(valid);
511 if (valid) {
512 str += workStr;
513 } else {
514 QMessageBox::critical(this, "ERROR",
515 "Given map not valid, will add a default map line",
516 QMessageBox::Ok, QMessageBox::NoButton);
517 str += "map 0 0 0 0 0 0 0 0 0 0\n";
518 }
519
520 // add forward
521 str += dlg->getForward();
522
523 // add norm
524 str += dlg->getNorm();
525
526 // add lifetime parameter
527 workStr = dlg->getMuonLifetimeParam(present);
528 if (present) {
529 str += workStr;
530 }
531
532 // add lifetime correction flag if present
533 workStr = dlg->getLifetimeCorrection(present);
534 if (present) {
535 str += workStr;
536 }
537
538 // add background, backgr.fix or backgr.fit
539 workStr = dlg->getBackground(valid);
540 str += workStr;
541 if (!valid) {
542 QMessageBox::critical(this, "ERROR",
543 "Either <b>background</b>, <b>backgr.fix</b>, or <b>backgr.fit</b> is needed!\nWill set <b>background</b> to 0..10, please correct!",
544 QMessageBox::Ok, QMessageBox::NoButton);
545 }
546
547 // add t0 if present
548 workStr = dlg->getT0(present);
549 if (present) {
550 str += workStr;
551 } else {
552 QMessageBox::warning(this, "ERROR",
553 "T0's not given, assume that they are present in the data file!",
554 QMessageBox::Ok, QMessageBox::NoButton);
555 }
556
557 // add data
558 workStr = dlg->getData(valid);
559 if (valid) {
560 str += workStr;
561 } else {
562 QMessageBox::critical(this, "ERROR",
563 "Not all Data entries are present.Fix is needed!\nWill not set anything!",
564 QMessageBox::Ok, QMessageBox::NoButton);
565 }
566
567 // add fit range
568 workStr = dlg->getFitRange(valid);
569 str += workStr;
570 if (!valid) {
571 QMessageBox::critical(this, "ERROR",
572 "No valid fit range is given.Fix is needed!\nWill add a default one!",
573 QMessageBox::Ok, QMessageBox::NoButton);
574 }
575
576 // add packing
577 workStr = dlg->getPacking(present);
578 str += workStr;
579 if (!present) {
580 QMessageBox::critical(this, "ERROR",
581 "No valid packing/binning is given.Fix is needed!\nWill add a default one!",
582 QMessageBox::Ok, QMessageBox::NoButton);
583 }
584
585 // insert Single Histogram Run Block at the current cursor position
586 insertPlainText(str);
587 }
588}
589
590//----------------------------------------------------------------------------------------------------
595{
596 std::unique_ptr<PGetNonMusrRunBlockDialog> dlg = std::make_unique<PGetNonMusrRunBlockDialog>(fAdmin->getHelpUrl("run"));
597
598 if (dlg == nullptr)
599 return;
600
601 if (dlg->exec() == QDialog::Accepted) {
602 QString str, workStr;
603 bool valid = true;
604 // check if there is already a run block present, necessary because of the '####' line
605 // STILL MISSING
606
607 // add run line
608 str += dlg->getRunHeaderInfo();
609
610 // add fittype
611 str += "fittype 8 (non musr fit)\n";
612
613 // add map
614 workStr = dlg->getMap(valid);
615 if (valid) {
616 str += workStr;
617 } else {
618 QMessageBox::critical(this, "ERROR",
619 "Given map not valid, will add a default map line",
620 QMessageBox::Ok, QMessageBox::NoButton);
621 str += "map 0 0 0 0 0 0 0 0 0 0\n";
622 }
623
624 // add xy-data
625 workStr = dlg->getXYData(valid);
626 if (valid) {
627 str += workStr;
628 } else {
629 QMessageBox::critical(this, "ERROR",
630 "Not all xy-data entries are present.Fix is needed!\nWill not set anything!",
631 QMessageBox::Ok, QMessageBox::NoButton);
632 }
633
634 // add fit range
635 workStr = dlg->getFitRange(valid);
636 str += workStr;
637 if (!valid) {
638 QMessageBox::critical(this, "ERROR",
639 "No valid fit range is given.Fix is needed!\nWill add a default one!",
640 QMessageBox::Ok, QMessageBox::NoButton);
641 }
642
643 // add packing
644 str += "packing 1\n";
645
646 // insert NonMusr Run Block at the current cursor position
647 insertPlainText(str);
648 }
649}
650
651//----------------------------------------------------------------------------------------------------
702{
703 insertPlainText("###############################################################\n");
704 insertPlainText("COMMANDS\n");
705 insertPlainText("SET BATCH\n");
706 insertPlainText("STRATEGY 1\n");
707 insertPlainText("MINIMIZE\n");
708 insertPlainText("#MINOS\n");
709 insertPlainText("SAVE\n");
710 insertPlainText("END RETURN\n\n");
711}
712
713//----------------------------------------------------------------------------------------------------
718{
719 // for the time being the url's are hard coded but should be transfered to the XML startup
720 std::unique_ptr<PGetFourierBlockDialog> dlg = std::make_unique<PGetFourierBlockDialog>(fAdmin->getHelpUrl("fourier"));
721
722 if (dlg == nullptr)
723 return;
724
725 if (dlg->exec() == QDialog::Accepted) {
726 insertPlainText(dlg->getFourierBlock()+"\n");
727 }
728}
729
730//----------------------------------------------------------------------------------------------------
735{
736 // for the time being the url's are hard coded but should be transfered to the XML startup
737 std::unique_ptr<PGetPlotBlockDialog> dlg = std::make_unique<PGetPlotBlockDialog>(fAdmin->getHelpUrl("plot"));
738
739 if (dlg == nullptr)
740 return;
741
742 if (dlg->exec() == QDialog::Accepted) {
743 insertPlainText(dlg->getPlotBlock()+"\n");
744 }
745}
746
747//----------------------------------------------------------------------------------------------------
810{
811 QDateTime dt = QDateTime::currentDateTime();
812 insertPlainText("###############################################################\n");
813 insertPlainText("STATISTIC --- " + dt.toString("yyyy-MM-dd hh:mm:ss") + "\n");
814 insertPlainText("chisq = ????, NDF = ????, chisq/NDF = ????\n\n");
815}
816
817//----------------------------------------------------------------------------------------------------
818// END
819//----------------------------------------------------------------------------------------------------
Administration and configuration management for musredit.
Dialog for creating asymmetry RUN blocks in msr files.
Dialog for creating FOURIER blocks in msr files.
Dialog for creating FUNCTIONS blocks in msr files.
Dialog for creating non-muSR RUN blocks in msr files.
Dialog for creating FITPARAMETER blocks in msr files.
Dialog for creating PLOT blocks in msr files.
Dialog for creating single histogram RUN blocks in msr files.
Dialog for creating THEORY blocks in msr files.
Dialog for creating and editing TITLE blocks in msr files.
Definition of the PMsrHighlighter class for musredit.
Enhanced text editor widget for editing msr files in musredit.
Central administration class for musredit configuration management.
Definition PAdmin.h:209
Custom syntax highlighter for .msr (musrfit configuration) file syntax.
void insertTheoryBlock()
Slot: Inserts a THEORY block via dialog.
void insertPlotBlock()
Slot: Inserts a PLOT block via dialog.
void insertFourierBlock()
Slot: Inserts a FOURIER block via dialog.
void insertFunctionBlock()
Slot: Inserts a FUNCTIONS block via dialog.
void insertTitle()
Slot: Inserts a title block via dialog.
PAdmin * fAdmin
Pointer to administration object with theory functions, help URLs, and configuration.
void insertParameterBlock()
Slot: Inserts a FITPARAMETER block via dialog.
void insertNonMusrRunBlock()
Slot: Inserts a non-µSR RUN block via dialog.
void insertStatisticBlock()
Slot: Inserts a default STATISTIC block.
void insertTheoryFunction(QString name)
Slot: Inserts a specific theory function.
void insertCommandBlock()
Slot: Inserts a default COMMANDS block.
PSubTextEdit(PAdmin *admin=0, QWidget *parent=0)
Constructs the enhanced text editor.
int getFitType()
Retrieves the fit type from the current msr file content.
void insertSingleHistRunBlock()
Slot: Inserts a single histogram RUN block via dialog.
void insertAsymRunBlock()
Slot: Inserts an asymmetry RUN block via dialog.
Structure holding information about a musrfit theory function.
Definition PAdmin.h:90
QString name
Internal function name used in msr files (e.g., "asymmetry", "simplExpo").
Definition PAdmin.h:91
QString comment
Human-readable description of the theory function.
Definition PAdmin.h:92
int params
Number of parameters required by this theory function.
Definition PAdmin.h:96