GlobalReplaceWorker

class GlobalReplaceWorker : public QObject

Public Functions

explicit GlobalReplaceWorker(QObject *parent = nullptr, QList<QString> *filesChangedUsingGlobalReplace = nullptr, QMap<QString, QString> *mapOfReplacements = nullptr, QMap<QString, QString> globalReplacementMap = {}, QMap<QPair<QString, QString>, QString> globalReplacementMapAfterCheck = {}, QMap<QString, QString> replaceInAllPages_Map = {}, QMap<QString, QString> replaceInUneditedPages_Map = {}, QString currentFileDirectory = "", QString gDirTwoLevelUp = "", QString gCurrentPageName = "", int numOfChangedWords = 0, int check = 0, int *r1 = nullptr, int *r2 = nullptr, int *x1 = nullptr, int *files = nullptr, int pairMap = 1, QString mRole = "Corrector")

This is the constructor which initializes the objects needed to be shared between the main(GUI) thread and the another thread.

Parameters:
  • parent

  • filesChangedUsingGlobalReplace

  • mapOfReplacements

  • globalReplacementMap

  • globalReplacementMapAfterCheck

  • replaceInAllPages_Map

  • replaceInUneditedPages_Map

  • currentFileDirectory

  • gDirTwoLevelUp

  • gCurrentPageName

  • numOfChangedWords

  • check

  • r1

  • r2

  • x1

  • files

  • pairMap

Public Slots

void replaceWordsInFiles()

This function traverses the user role’s dir and filters the html files and passes the required files to writeGlobalCPairsToFiles() function for replacing the required replacements.

It also emits the signal for updating progress bar.

void writeLogs()

It writes the logs in the [set-name]logs.csv file which resides in the set folder.

The format of logs is <SourceWord>,<TargetWord>,<TypeOfReplacement>,<TimeOfReplacement>,<PageName>,<SetName>

void saveBboxInfo(QString)

Saves the bbox info.

Parameters:

htmlFile

void bboxInsertion(QString)

Inserts bbox into the saved file.

Parameters:

f

Private Functions

int writeGlobalCPairsToFiles(QString file_path, QMap<QString, QString> globalReplacementMap, QTextDocument *doc)

This function writes the required replacements to the file specified.

It copies the contents of the file to a QTextDocument which is used for replacement purpose.

Parameters:
  • file_path

  • globalReplacementMap

  • doc

Returns:

Number of replaced words

bool isStringInFile(QString file_path, QString searchString)

Checks if a QString is in file at file_path.

Parameters:
  • file_path

  • searchString

Returns:

0 if not present and 1 if it is present