]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/updatablestateinterface.h
Fix up 2f208662cbd604f879027d3cd633a5ce59182a4f
[dolphin.git] / src / search / updatablestateinterface.h
1 /*
2 SPDX-FileCopyrightText: 2024 Felix Ernst <felixernst@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7 #ifndef UPDATABLESTATEINTERFACE_H
8 #define UPDATABLESTATEINTERFACE_H
9
10 #include <QtAssert>
11
12 #include <memory>
13
14 namespace Search
15 {
16 class DolphinQuery;
17
18 class UpdatableStateInterface
19 {
20 public:
21 inline explicit UpdatableStateInterface(std::shared_ptr<const DolphinQuery> dolphinQuery)
22 : m_searchConfiguration{std::move(dolphinQuery)} {};
23
24 virtual ~UpdatableStateInterface(){};
25
26 /**
27 * Updates this object and its child widgets so their states are correctly described by the @p dolphinQuery.
28 * This method is always initially called on the Search::Bar which in turn calls this method on its child widgets. That is because the Search::Bar is the
29 * ancestor widget of all classes implementing UpdatableStateInterface, and from Search::Bar::updateStateToMatch() the changed state represented by the
30 * @p dolphinQuery is propagated to all other UpdatableStateInterfaces through UpdatableStateInterface::updateState() calls.
31 */
32 inline void updateStateToMatch(std::shared_ptr<const DolphinQuery> dolphinQuery)
33 {
34 Q_ASSERT_X(m_searchConfiguration, "UpdatableStateInterface::updateStateToMatch()", "An UpdatableStateInterface should always have a consistent state.");
35 updateState(dolphinQuery);
36 m_searchConfiguration = std::move(dolphinQuery);
37 Q_ASSERT_X(m_searchConfiguration, "UpdatableStateInterface::updateStateToMatch()", "An UpdatableStateInterface should always have a consistent state.");
38 };
39
40 private:
41 /**
42 * Implementations of this method initialize the state of this object and its child widgets to represent the state of the @p dolphinQuery.
43 * This method is only ever called from UpdatableStateInterface::updateStateToMatch().
44 */
45 virtual void updateState(const std::shared_ptr<const DolphinQuery> &dolphinQuery) = 0;
46
47 protected:
48 /**
49 * The DolphinQuery that was used to initialize this object's state.
50 */
51 std::shared_ptr<const DolphinQuery> m_searchConfiguration;
52 };
53
54 }
55
56 #endif // UPDATABLESTATEINTERFACE_H