Files
qt5-legatus-legacy/Lts/Plugins/CodificationManagement/Gui/CodificationData/cod_phrase_table_model.h
T
2026-08-13 18:33:10 +02:00

152 lines
4.1 KiB
C++
Executable File

/**
* Model for phrase table
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2017-01-19
*/
#pragma once
#include <QAbstractTableModel>
#include <CodificationManagement/logger.h>
#include <CodificationManagement/cod_dtc.h>
namespace CodificationManagement
{
class PhraseTableModel final : public QAbstractTableModel
{
Q_OBJECT
public:
explicit PhraseTableModel(QWidget *parent);
~PhraseTableModel() = default;
/**
* init model internal data matrix
* @param dtc access to Data Topic Client
* @param codificationDataId id of the used codification data set
* @param isEditMode true means model used for edit, otherwise used for show only
* in edit mode non update will be done by external data change
* @return Returns true on success, otherwise false
*/
bool init(const std::shared_ptr<CodificationManagement::Interface::Dtc> &dtc,
int codificationDataId,
bool isEditMode = false);
/**
* set the 13x2 code matrix to zero
*/
void resetMatrix();
/**
* set matrix values
* @param data reference to int data set of matrix values
* @return Returns true on success, otherwise false
*/
bool setMatrixValuesCSV(const QString &csvData);
/**
* get matrix data in csv format
* @param -
* @return Returns matrix data in csv format;
*/
QString getMatrixDataCSVString() const;
/**
* set/get edit mode flag used for internal data handling
* @param isEditMode true means set edit mode
* @return Returns true if edit mode is set, otherwise false
*/
void setEditMode(bool isEditMode);
bool isEditMode() const;
/**
* get the row count (MVC-model)
* @param ModelIndex
* get vertical header in csv forma
* @return int Returns the count
*/
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* get the row column (MVC-model)
* @param ModelIndex
* @return int Returns the count
*/
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* get the header data (MVC-model)
* @param section (column)
* @param Qt::Orientation
* @param role
* @return QVariant
*/
QVariant headerData(int column, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
/**
* get the data (MVC-model)
* @param QModelIndex
* @return QVariant
*/
QVariant data(const QModelIndex &index, int role) const override;
/**
* set the data (MVC-model)
* @param QModelIndex
* @return bool Returns true if successfull, otherwise returns false
*/
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
/**
* get flags for the given QModelIndex (MVC-model)
* @param ModelIndex
* @return flags Returns the flags
*/
Qt::ItemFlags flags(const QModelIndex &index) const override;
Q_SIGNALS:
/**
* emits when data was changed (used to enable add/okay button)
*/
void dataModified();
private Q_SLOTS:
void onCodificationDataChanged(const CodificationManagement::CodificationData &data,
DataModification modType);
private:
/**
* split the 'inString' into substrings, where string in quotation marks are not split
* If 'sep' does not match anywhere in the 'inString', function returns a single-element list containing this string.
* @param sep seperator character
* @param inString input string
* @return stringlist of substrings
*/
QStringList splitQuotedString(const QChar &sep, const QString &inString);
private:
// /**
// * set the 13x2 code matrix to zero
// */
// void resetMatrix();
QString m_matrix[13][2]; ///< Hold the phrase table (without row/column select index fields)
std::shared_ptr<CodificationManagement::Interface::Dtc> m_dtc;
int m_codificationDataId; ///< Id of the used codification data set
bool m_isEditMode; ///< Hold the dialog mode setting; if true the indices in row 0 and column 0 can be modified
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
};
} //namespace CodificationManagement