Add ProgressInfoBlocker and add to unit tests

This commit is contained in:
Gaute Lindkvist 2019-03-22 13:16:42 +01:00
parent e40b3aa6e8
commit de2920c7c2
3 changed files with 56 additions and 13 deletions

View File

@ -35,6 +35,8 @@
#include "RifReaderSettings.h"
#include "RimEclipseResultCase.h"
#include <cafProgressInfo.h>
#include <QDebug>
#include <QDir>
@ -47,6 +49,8 @@ using namespace RiaDefines;
//--------------------------------------------------------------------------------------------------
TEST(RigReservoirTest, BasicTest10k)
{
caf::ProgressInfoBlocker progressBlocker;
QDir baseFolder(TEST_MODEL_DIR);
bool subFolderExists = baseFolder.cd("TEST10K_FLT_LGR_NNC");
EXPECT_TRUE(subFolderExists);
@ -99,6 +103,8 @@ TEST(RigReservoirTest, BasicTest10k)
TEST(RigReservoirTest, BasicTest10kRestart)
{
caf::ProgressInfoBlocker progressBlocker;
RifEclipseUnifiedRestartFileAccess unrstAccess;
QDir baseFolder(TEST_MODEL_DIR);
@ -137,6 +143,8 @@ TEST(RigReservoirTest, BasicTest10kRestart)
TEST(RigReservoirTest, BasicTest10k_NativeECL)
{
caf::ProgressInfoBlocker progressBlocker;
QDir baseFolder(TEST_MODEL_DIR);
bool subFolderExists = baseFolder.cd("TEST10K_FLT_LGR_NNC");
EXPECT_TRUE(subFolderExists);
@ -183,6 +191,8 @@ TEST(RigReservoirTest, BasicTest10k_NativeECL)
TEST(RigReservoirTest, Test10k_ReadThenWriteToECL)
{
caf::ProgressInfoBlocker progressBlocker;
QDir baseFolder(TEST_MODEL_DIR);
bool subFolderExists = baseFolder.cd("TEST10K_FLT_LGR_NNC");
EXPECT_TRUE(subFolderExists);

View File

@ -348,18 +348,6 @@ namespace caf {
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
static bool isUpdatePossible()
{
if (!qApp) return false;
if (!progressDialog()) return false;
return progressDialog()->thread() == QThread::currentThread();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -440,6 +428,23 @@ namespace caf {
}
}
//==================================================================================================
///
/// \class caf::ProgressInfoBlocker
///
/// Used to disable progress info on a temporary basis
///
//==================================================================================================
ProgressInfoBlocker::ProgressInfoBlocker()
{
ProgressInfoStatic::s_disabled = true;
}
ProgressInfoBlocker::~ProgressInfoBlocker()
{
ProgressInfoStatic::s_disabled = false;
}
//==================================================================================================
///
@ -449,6 +454,7 @@ namespace caf {
///
//==================================================================================================
bool ProgressInfoStatic::s_disabled = false;
//--------------------------------------------------------------------------------------------------
///
@ -491,7 +497,6 @@ namespace caf {
//if (progressDialog()) progressDialog()->repaint();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -636,4 +641,19 @@ namespace caf {
//if (progressDialog()) progressDialog()->repaint();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool ProgressInfoStatic::isUpdatePossible()
{
if (s_disabled) return false;
if (!qApp) return false;
if (!progressDialog()) return false;
return progressDialog()->thread() == QThread::currentThread();
}
} // namespace caf

View File

@ -69,6 +69,12 @@ public:
};
class ProgressInfoBlocker
{
public:
ProgressInfoBlocker();
~ProgressInfoBlocker();
};
class ProgressInfoStatic
{
@ -81,6 +87,13 @@ public:
static void setNextProgressIncrement(size_t nextStepSize);
static void finished();
private:
static bool isUpdatePossible();
private:
friend class ProgressInfoBlocker;
static bool s_disabled;
};
}