VariableModel.h
94 lines
| 3.0 KiB
| text/x-c
|
CLexer
|
r112 | #ifndef SCIQLOP_VARIABLEMODEL_H | ||
#define SCIQLOP_VARIABLEMODEL_H | ||||
|
r461 | #include "CoreGlobal.h" | ||
r228 | ||||
r512 | #include <Data/SqpRange.h> | |||
|
r112 | |||
|
r149 | #include <QAbstractTableModel> | ||
|
r112 | #include <QLoggingCategory> | ||
|
r368 | #include <Common/MetaTypes.h> | ||
r228 | #include <Common/spimpl.h> | |||
|
r112 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | ||
|
r809 | enum VariableRoles { ProgressRole = Qt::UserRole, StateRole }; | ||
r401 | ||||
|
r165 | class IDataSeries; | ||
|
r112 | class Variable; | ||
/** | ||||
* @brief The VariableModel class aims to hold the variables that have been created in SciQlop | ||||
*/ | ||||
|
r461 | class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel { | ||
r422 | Q_OBJECT | |||
|
r112 | public: | ||
|
r149 | explicit VariableModel(QObject *parent = nullptr); | ||
|
r112 | |||
|
r708 | /** | ||
* Adds an existing variable in the model. | ||||
* @param variable the variable to add. | ||||
* @remarks the variable's name is modified to avoid name duplicates | ||||
* @remarks this method does nothing if the variable already exists in the model | ||||
*/ | ||||
void addVariable(std::shared_ptr<Variable> variable) noexcept; | ||||
|
r710 | /** | ||
* Checks that a variable is contained in the model | ||||
* @param variable the variable to check | ||||
* @return true if the variable is in the model, false otherwise | ||||
*/ | ||||
bool containsVariable(std::shared_ptr<Variable> variable) const noexcept; | ||||
|
r112 | /** | ||
* Creates a new variable in the model | ||||
* @param name the name of the new variable | ||||
|
r410 | * @param metadata the metadata associated to the new variable | ||
|
r165 | * @return the pointer to the new variable | ||
|
r112 | */ | ||
r756 | std::shared_ptr<Variable> createVariable(const QString &name, | |||
|
r410 | const QVariantHash &metadata) noexcept; | ||
|
r112 | |||
|
r332 | /** | ||
* Deletes a variable from the model, if it exists | ||||
* @param variable the variable to delete | ||||
*/ | ||||
void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | ||||
r401 | ||||
|
r246 | std::shared_ptr<Variable> variable(int index) const; | ||
|
r684 | std::vector<std::shared_ptr<Variable> > variables() const; | ||
|
r246 | |||
r401 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); | |||
r422 | ||||
|
r149 | // /////////////////////////// // | ||
// QAbstractTableModel methods // | ||||
// /////////////////////////// // | ||||
r401 | ||||
|
r149 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; | ||
virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; | ||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
virtual QVariant headerData(int section, Qt::Orientation orientation, | ||||
int role = Qt::DisplayRole) const override; | ||||
r422 | ||||
void abortProgress(const QModelIndex &index); | ||||
signals: | ||||
void abortProgessRequested(std::shared_ptr<Variable> variable); | ||||
|
r112 | private: | ||
class VariableModelPrivate; | ||||
spimpl::unique_impl_ptr<VariableModelPrivate> impl; | ||||
|
r368 | |||
private slots: | ||||
/// Slot called when data of a variable has been updated | ||||
void onVariableUpdated() noexcept; | ||||
|
r112 | }; | ||
|
r368 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal | ||
SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) | ||||
|
r112 | #endif // SCIQLOP_VARIABLEMODEL_H | ||