VariableModel.h
111 lines
| 3.9 KiB
| text/x-c
|
CLexer
Alexandre Leroux
|
r112 | #ifndef SCIQLOP_VARIABLEMODEL_H | ||
#define SCIQLOP_VARIABLEMODEL_H | ||||
Alexandre Leroux
|
r461 | #include "CoreGlobal.h" | ||
r228 | ||||
r512 | #include <Data/SqpRange.h> | |||
Alexandre Leroux
|
r112 | |||
Alexandre Leroux
|
r149 | #include <QAbstractTableModel> | ||
Alexandre Leroux
|
r112 | #include <QLoggingCategory> | ||
Alexandre Leroux
|
r368 | #include <Common/MetaTypes.h> | ||
r228 | #include <Common/spimpl.h> | |||
Alexandre Leroux
|
r112 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | ||
r402 | enum VariableRoles { ProgressRole = Qt::UserRole }; | |||
r401 | ||||
Alexandre Leroux
|
r165 | class IDataSeries; | ||
Alexandre Leroux
|
r112 | class Variable; | ||
r849 | class VariableController; | |||
Alexandre Leroux
|
r112 | |||
/** | ||||
* @brief The VariableModel class aims to hold the variables that have been created in SciQlop | ||||
*/ | ||||
Alexandre Leroux
|
r461 | class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel { | ||
r422 | Q_OBJECT | |||
Alexandre Leroux
|
r112 | public: | ||
r849 | explicit VariableModel(VariableController *parent = nullptr); | |||
Alexandre Leroux
|
r112 | |||
Alexandre Leroux
|
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; | ||||
Alexandre Leroux
|
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; | ||||
Alexandre Leroux
|
r112 | /** | ||
* Creates a new variable in the model | ||||
* @param name the name of the new variable | ||||
Alexandre Leroux
|
r410 | * @param metadata the metadata associated to the new variable | ||
Alexandre Leroux
|
r165 | * @return the pointer to the new variable | ||
Alexandre Leroux
|
r112 | */ | ||
r756 | std::shared_ptr<Variable> createVariable(const QString &name, | |||
Alexandre Leroux
|
r410 | const QVariantHash &metadata) noexcept; | ||
Alexandre Leroux
|
r112 | |||
Alexandre Leroux
|
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 | ||||
Alexandre Leroux
|
r246 | std::shared_ptr<Variable> variable(int index) const; | ||
Alexandre Leroux
|
r684 | std::vector<std::shared_ptr<Variable> > variables() const; | ||
Alexandre Leroux
|
r246 | |||
r401 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); | |||
r422 | ||||
Alexandre Leroux
|
r149 | // /////////////////////////// // | ||
// QAbstractTableModel methods // | ||||
// /////////////////////////// // | ||||
r401 | ||||
Alexandre Leroux
|
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; | ||||
r849 | virtual Qt::ItemFlags flags(const QModelIndex &index) const override; | |||
// ///////////////// // | ||||
// Drag&Drop methods // | ||||
// ///////////////// // | ||||
virtual Qt::DropActions supportedDropActions() const override; | ||||
virtual Qt::DropActions supportedDragActions() const override; | ||||
virtual QStringList mimeTypes() const override; | ||||
virtual QMimeData *mimeData(const QModelIndexList &indexes) const override; | ||||
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | ||||
const QModelIndex &parent) const override; | ||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | ||||
const QModelIndex &parent) override; | ||||
r422 | ||||
void abortProgress(const QModelIndex &index); | ||||
signals: | ||||
void abortProgessRequested(std::shared_ptr<Variable> variable); | ||||
r870 | void requestVariable(const QVariantHash &productData); | |||
r933 | void requestVariableRangeUpdate(std::shared_ptr<Variable> variable, const SqpRange &range); | |||
r422 | ||||
Alexandre Leroux
|
r112 | private: | ||
class VariableModelPrivate; | ||||
spimpl::unique_impl_ptr<VariableModelPrivate> impl; | ||||
Alexandre Leroux
|
r368 | |||
private slots: | ||||
/// Slot called when data of a variable has been updated | ||||
void onVariableUpdated() noexcept; | ||||
Alexandre Leroux
|
r112 | }; | ||
Alexandre Leroux
|
r368 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal | ||
SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) | ||||
Alexandre Leroux
|
r112 | #endif // SCIQLOP_VARIABLEMODEL_H | ||