DataSourceItem.h
110 lines
| 3.3 KiB
| text/x-c
|
CLexer
|
r35 | #ifndef SCIQLOP_DATASOURCEITEM_H | ||
#define SCIQLOP_DATASOURCEITEM_H | ||||
|
r461 | #include "CoreGlobal.h" | ||
|
r35 | #include <Common/spimpl.h> | ||
#include <QVariant> | ||||
#include <QVector> | ||||
|
r144 | class DataSourceItemAction; | ||
|
r79 | /** | ||
* Possible types of an item | ||||
*/ | ||||
|
r344 | enum class DataSourceItemType { NODE, PRODUCT, COMPONENT }; | ||
|
r79 | |||
|
r35 | /** | ||
* @brief The DataSourceItem class aims to represent a structure element of a data source. | ||||
* A data source has a tree structure that is made up of a main DataSourceItem object (root) | ||||
* containing other DataSourceItem objects (children). | ||||
* For each DataSourceItem can be associated a set of data representing it. | ||||
*/ | ||||
|
r461 | class SCIQLOP_CORE_EXPORT DataSourceItem { | ||
|
r35 | public: | ||
|
r342 | /// Key associated with the name of the item | ||
static const QString NAME_DATA_KEY; | ||||
explicit DataSourceItem(DataSourceItemType type, const QString &name); | ||||
|
r407 | explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {}); | ||
|
r35 | |||
|
r144 | /// @return the actions of the item as a vector | ||
QVector<DataSourceItemAction *> actions() const noexcept; | ||||
/** | ||||
* Adds an action to the item. The item takes ownership of the action, and the action is | ||||
* automatically associated to the item | ||||
* @param action the action to add | ||||
*/ | ||||
void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; | ||||
|
r35 | /** | ||
* Adds a child to the item. The item takes ownership of the child. | ||||
* @param child the child to add | ||||
*/ | ||||
void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; | ||||
/** | ||||
* Returns the item's child associated to an index | ||||
* @param childIndex the index to search | ||||
* @return a pointer to the child if index is valid, nullptr otherwise | ||||
*/ | ||||
DataSourceItem *child(int childIndex) const noexcept; | ||||
int childCount() const noexcept; | ||||
/** | ||||
|
r342 | * Get the data associated to a key | ||
* @param key the key to search | ||||
* @return the data found if key is valid, default QVariant otherwise | ||||
|
r35 | */ | ||
|
r342 | QVariant data(const QString &key) const noexcept; | ||
|
r35 | |||
|
r346 | /// Gets all data | ||
|
r407 | QVariantHash data() const noexcept; | ||
|
r346 | |||
|
r345 | bool isRoot() const noexcept; | ||
|
r146 | QString name() const noexcept; | ||
|
r35 | /** | ||
* Get the item's parent | ||||
* @return a pointer to the parent if it exists, nullptr if the item is a root | ||||
*/ | ||||
DataSourceItem *parentItem() const noexcept; | ||||
|
r551 | /** | ||
* Gets the item's root | ||||
* @return the top parent, the item itself if it's the root item | ||||
*/ | ||||
const DataSourceItem &rootItem() const noexcept; | ||||
|
r347 | /** | ||
* Sets or appends a value to a key | ||||
* @param key the key | ||||
* @param value the value | ||||
* @param append if true, the value is added to the values already existing for the key, | ||||
* otherwise it replaces the existing values | ||||
*/ | ||||
void setData(const QString &key, const QVariant &value, bool append = false) noexcept; | ||||
|
r79 | DataSourceItemType type() const noexcept; | ||
r874 | /** | |||
* @brief Searches the first child matching the specified data. | ||||
* @param data The data to search. | ||||
* @param recursive So the search recursively. | ||||
* @return the item matching the data or nullptr if it was not found. | ||||
*/ | ||||
DataSourceItem *findItem(const QVariantHash &data, bool recursive); | ||||
|
r348 | bool operator==(const DataSourceItem &other); | ||
bool operator!=(const DataSourceItem &other); | ||||
|
r35 | private: | ||
class DataSourceItemPrivate; | ||||
spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; | ||||
}; | ||||
#endif // SCIQLOP_DATASOURCEITEMMODEL_H | ||||