Mantid
Loading...
Searching...
No Matches
FindFilesThreadPoolManagerMockObjects.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11
12#include <QApplication>
13#include <QObject>
14
15#ifdef Q_OS_WIN
16#include <windows.h> // for Sleep
17#endif
18
19namespace {
20// We don't currently link QTest, so here we are just reimplementing the Qt
21// sleep function so we can predict how long threads will run for.
22void qSleep(int ms) {
23#ifdef Q_OS_WIN
24 Sleep(uint(ms));
25#else
26 struct timespec ts = {ms / 1000, (ms % 1000) * 1000 * 1000};
27 nanosleep(&ts, nullptr);
28#endif
29}
30} // namespace
31
32namespace MantidQt {
33namespace API {
34
41 Q_OBJECT
42public:
44 const FindFilesSearchResults &results = FindFilesSearchResults(), int milliseconds = 100)
45 : FindFilesWorker(parameters), m_results(results), m_milliseconds(milliseconds) {}
46
47protected:
48 void run() override {
49 qSleep(m_milliseconds);
50 QCoreApplication::processEvents();
51 emit finished(m_results);
52 }
53
54private:
57};
58
68 Q_OBJECT
69
70public:
71 FakeFileFinderWidget() : m_results(), m_finishedSignalRecieved(false) {
72 connect(this, SIGNAL(fileFindingFinished()), this, SLOT(setSignalRecieved()));
73 }
74
76 FindFilesSearchResults getResults() { return m_results; };
78 bool isFinishedSignalRecieved() { return m_finishedSignalRecieved; };
79
80public slots:
82 void inspectThreadResult(const FindFilesSearchResults &result) { m_results = result; }
83
85 void setSignalRecieved() { m_finishedSignalRecieved = true; }
86
87signals:
90
91private:
96};
97
98} // namespace API
99} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
FindFilesSearchResults m_results
Results captured from the worker thread.
bool m_finishedSignalRecieved
Whether a finished signal was recieved.
bool isFinishedSignalRecieved()
Get if the finished searching signal was recieved.
void setSignalRecieved()
Slot called when the file finding thread has finished.
void fileFindingFinished()
Signal emitted to itself when files were found.
FindFilesSearchResults getResults()
Get the captured results of a file search.
void inspectThreadResult(const FindFilesSearchResults &result)
Slot called when file finding thread has finished.
void run() override
Override parent class run().
FakeFindFilesThread(const FindFilesSearchParameters &parameters, const FindFilesSearchResults &results=FindFilesSearchResults(), int milliseconds=100)
A class to allow the asynchronous finding of files.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
POD struct to hold details about the parameters of a file search.
POD struct to hold details about the results of a file search.