Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
FileCmdScript Class Reference

File that manages a command stack for regression testing of file import/open/export/close. More...

#include <FileCmdScript.h>

Collaboration diagram for FileCmdScript:
Collaboration graph

Public Member Functions

 FileCmdScript (const QString &fileCmdScriptFile)
 Single constructor. More...
 
 ~FileCmdScript ()
 
bool canRedo () const
 Returns true if there is at least one command on the stack. More...
 
void redo (MainWindow &mainWindow)
 Apply the next command. Requires non-empty stack. More...
 

Detailed Description

File that manages a command stack for regression testing of file import/open/export/close.

This command stack (with a lifetime the same as the application's) is independent of the command stack in CmdMediator (which is Document-specific)

Definition at line 20 of file FileCmdScript.h.

Constructor & Destructor Documentation

FileCmdScript::FileCmdScript ( const QString &  fileCmdScriptFile)

Single constructor.

Definition at line 19 of file FileCmdScript.cpp.

20 {
21  LOG4CPP_INFO_S ((*mainCat)) << "FileCmdScript::FileCmdScript"
22  << " curDir=" << QDir::currentPath().toLatin1().data();
23 
24  // A non-existent script file is allowed in which case nothing gets done, as a way
25  // of tracking MainWindow being in a regression test that has no command script
26  if (!fileCmdScriptFile.isEmpty ()) {
27 
28  // Read commands into stack. The file is known to exist since it was checked in parseCmdLine
29  QFile file (fileCmdScriptFile);
30 
31  QXmlStreamReader reader (&file);
32  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
33 
34  QString msg = QString ("%1 %2 %3 %4")
35  .arg (QObject::tr ("Cannot read script file"))
36  .arg (fileCmdScriptFile)
37  .arg (QObject::tr ("from directory"))
38  .arg (QDir::currentPath());
39  QMessageBox::critical (nullptr,
40  "Script File",
41  msg);
42  exit (-1);
43  }
44 
45  // Load commands
46  FileCmdFactory factory;
47  while (!reader.atEnd() && !reader.hasError()) {
48 
49  if ((loadNextFromReader (reader) == QXmlStreamReader::StartElement) &&
50  (reader.name() == FILE_CMD_SERIALIZE_CMD)) {
51 
52  // Extract and append new command to command stack
53  m_fileCmdStack.push_back (factory.createFileCmd (reader));
54  }
55  }
56  file.close();
57  }
58 }
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
FileCmdAbstract * createFileCmd(QXmlStreamReader &reader) const
Create one FileCmdAbstract from the specified xml subtree.
const QString FILE_CMD_SERIALIZE_CMD
log4cpp::Category * mainCat
Definition: Logger.cpp:14
Factory that creates FileCmds from a file cmd script file, in xml format.
FileCmdScript::~FileCmdScript ( )

Definition at line 60 of file FileCmdScript.cpp.

61 {
62 }

Member Function Documentation

bool FileCmdScript::canRedo ( ) const

Returns true if there is at least one command on the stack.

Definition at line 64 of file FileCmdScript.cpp.

65 {
66  LOG4CPP_INFO_S ((*mainCat)) << "FileCmdScript::canRedo";
67 
68  return (m_fileCmdStack.count () > 0);
69 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void FileCmdScript::redo ( MainWindow mainWindow)

Apply the next command. Requires non-empty stack.

Definition at line 71 of file FileCmdScript.cpp.

72 {
73  LOG4CPP_INFO_S ((*mainCat)) << "FileCmdScript::redo";
74 
75  m_fileCmdStack.first()->redo(mainWindow);
76  m_fileCmdStack.pop_front();
77 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

The documentation for this class was generated from the following files: