Skip to content

Commit

Permalink
[ISSUE-210][REGEX_HISTORY] Regex usage statistics issue
Browse files Browse the repository at this point in the history
Regex usage statistics are not saved to the file when changing the
regex patterns file.

There is one more use case: switching between the pattern storage
files. To avoid losing the data, the regex usage history should be also
stored in the file in such  case.

This patch applies the desired behavior.

Signed-off-by: Vladyslav Goncharuk <vladyslav_goncharuk@epam.com>
  • Loading branch information
Vladyslav Goncharuk committed Sep 9, 2024
1 parent 51c50a7 commit 1a66b24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ DMA::tSyncInitOperationResult CSettingsComponent::shutdown()
{
if(nullptr != mpSettingsManager)
{
mpSettingsManager->storeConfigs();
auto result = mpSettingsManager->storeConfigs();

if(false == result.bResult)
{
SEND_ERR(QString("Was not able to store configs due to the following error: %1").arg(result.err));
}

mpSettingsManager.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,20 @@ CSettingsManager::CSettingsManager():
clearRegexConfig();
loadRegexConfigCustomPath(regexSettingsFilePath);

QString regexUsageStatisticsFilePath = getRegexUsageStatisticsDirectory() + QDir::separator() + mSetting_SelectedRegexFile.getData();

if(true == mbInitialised)
{
auto result = storeRegexUsageStatisticsDataCustomPath(regexUsageStatisticsFilePath);

if(false == result.bResult)
{
SEND_ERR(QString("Was not able to store regex usage statistics due "
"to the following error: %1").arg(result.err));
}
}

clearRegexUsageStatisticsData();
QString regexUsageStatisticsFilePath = getRegexUsageStatisticsDirectory() + QDir::separator() + data;
loadRegexUsageStatisticsDataCustomPath(regexUsageStatisticsFilePath);

selectedRegexFileChanged(data);
Expand Down Expand Up @@ -497,7 +509,7 @@ CSettingsManager::CSettingsManager():
mUserSettingItemPtrVec(),
mPatternsSettingItemPtrVec(),
mRegexUsageStatisticsDataItemPtrVec(),
mbRootConfigInitialised(false)
mbInitialised(false)
{
/////////////// ROOT SETTINGS ///////////////
mRootSettingItemPtrVec.push_back(&mSetting_SettingsManagerVersion);
Expand Down Expand Up @@ -1473,6 +1485,7 @@ CSettingsManager::tOperationResult CSettingsManager::setUp()
if(true == result.bResult)
{
result = loadConfigs();
mbInitialised = true;
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,5 @@ class CSettingsManager : public ISettingsManager
tSettingItemsPtrVec mPatternsSettingItemPtrVec;
tSettingItemsPtrVec mRegexUsageStatisticsDataItemPtrVec;

bool mbRootConfigInitialised;
bool mbInitialised;
};

0 comments on commit 1a66b24

Please sign in to comment.