- Change the object ownership semantics to take ownership of unique_ptr's rather than references

- Add helper functions for setting up config
- Add support for dynamically updating more config options (path related ones in particular)
This commit is contained in:
Alfred Reynolds
2021-08-11 14:01:18 +12:00
parent 8ac20f4b43
commit 24a4a07593
7 changed files with 121 additions and 81 deletions

View File

@@ -9,11 +9,11 @@
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
ImageSwitcher::ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::shared_ptr<ImageSelector>& selector):
ImageSwitcher::ImageSwitcher(MainWindow& w, unsigned int timeoutMsec, std::unique_ptr<ImageSelector>& selector):
QObject::QObject(),
window(w),
timeout(timeoutMsec),
selector(selector),
selector(std::move(selector)),
timer(this),
timerNoContent(this)
{
@@ -23,7 +23,7 @@ void ImageSwitcher::updateImage()
{
if(reloadConfigIfNeeded)
{
reloadConfigIfNeeded();
reloadConfigIfNeeded(window, this, selector.get());
}
ImageDetails imageDetails = selector->getNextImage(window.getBaseOptions());
if (imageDetails.filename == "")
@@ -52,7 +52,7 @@ void ImageSwitcher::scheduleImageUpdate()
QTimer::singleShot(100, this, SLOT(updateImage()));
}
void ImageSwitcher::setConfigFileReloader(std::function<void()> reloadConfigIfNeededIn)
void ImageSwitcher::setConfigFileReloader(std::function<void(MainWindow &w, ImageSwitcher *switcher, ImageSelector *selector)> reloadConfigIfNeededIn)
{
reloadConfigIfNeeded = reloadConfigIfNeededIn;
}
@@ -62,3 +62,8 @@ void ImageSwitcher::setRotationTime(unsigned int timeoutMsecIn)
timeout = timeoutMsecIn;
timer.start(timeout);
}
void ImageSwitcher::setImageSelector(std::unique_ptr<ImageSelector>& selectorIn)
{
selector = std::move(selectorIn);
}