mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
refs #139, added a class describing a single column, allowing to set certain columns as editable
This commit is contained in:
@@ -11,11 +11,71 @@
|
||||
#define BLACKGUI_COLUMNS_H
|
||||
|
||||
#include "blackmisc/valueobject.h" // for qHash overload, include before Qt stuff due GCC issue
|
||||
#include "blackmisc/collection.h"
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
/*!
|
||||
* \brief Single column
|
||||
*/
|
||||
class CColumn
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param headerName
|
||||
* \param propertyIndex as in CValueObject::propertyByIndex
|
||||
* \param alignment Qt::Alignment
|
||||
* \param editable
|
||||
*/
|
||||
CColumn(const QString &headerName, int propertyIndex, int alignment = -1, bool editable = false);
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param headerName
|
||||
* \param propertyIndex
|
||||
* \param editable
|
||||
*/
|
||||
CColumn(const QString &headerName, int propertyIndex, bool editable);
|
||||
|
||||
//! \brief Alignment for this column?
|
||||
bool hasAlignment() const
|
||||
{
|
||||
return this->m_alignment >= 0;
|
||||
}
|
||||
|
||||
//! \brief Editable?
|
||||
bool isEditable() const
|
||||
{
|
||||
return this->m_editable;
|
||||
}
|
||||
|
||||
//! \brief Aligment as QVariant
|
||||
QVariant aligmentAsQVariant() const;
|
||||
|
||||
//! \brief Column name
|
||||
QString getColumnName(bool i18n = false) const;
|
||||
|
||||
//! \brief Property index
|
||||
int getPropertyIndex() const { return this->m_propertyIndex;}
|
||||
|
||||
//! \brief Translation context
|
||||
void setTranslationContext(const QString &translationContext)
|
||||
{
|
||||
this->m_translationContext = translationContext;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_translationContext;
|
||||
QString m_columnName;
|
||||
int m_alignment;
|
||||
int m_propertyIndex; // property index
|
||||
bool m_editable;
|
||||
const char *getTranslationContextChar() const;
|
||||
const char *getColumnNameChar() const;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Header data for a table
|
||||
@@ -30,25 +90,14 @@ namespace BlackGui
|
||||
*/
|
||||
CColumns(const QString &translationContext, QObject *parent = nullptr);
|
||||
|
||||
/*!
|
||||
* \brief Add a column name
|
||||
* \param propertyIndex
|
||||
* \param name
|
||||
* \param alignment
|
||||
*/
|
||||
void addColumn(int propertyIndex, const QString &name, int alignment = -1);
|
||||
//! \brief Add a column
|
||||
void addColumn(CColumn column);
|
||||
|
||||
/*!
|
||||
* \brief Property index to name
|
||||
* \param propertyIndex
|
||||
*/
|
||||
QString propertyIndexToName(int propertyIndex) const;
|
||||
//! \brief Property index to name
|
||||
QString propertyIndexToColumnName(int propertyIndex, bool i18n = false) const;
|
||||
|
||||
/*!
|
||||
* \brief Column index to name
|
||||
* \param column
|
||||
*/
|
||||
QString columnToName(int column) const;
|
||||
//! \brief Column index to name
|
||||
QString columnToName(int column, bool i18n = false) const;
|
||||
|
||||
//! \brief Column to property index
|
||||
int columnToPropertyIndex(int column) const;
|
||||
@@ -65,31 +114,25 @@ namespace BlackGui
|
||||
//! \brief Size (number of columns)
|
||||
int size() const;
|
||||
|
||||
/*!
|
||||
* \brief Alignment for this column?
|
||||
* \param index
|
||||
* \return
|
||||
*/
|
||||
//! \brief Alignment for this column?
|
||||
bool hasAlignment(const QModelIndex &index) const;
|
||||
|
||||
/*!
|
||||
* \brief Aligment as QVariant
|
||||
* \param index
|
||||
* \return
|
||||
*/
|
||||
//! \brief Is this column editable?
|
||||
bool isEditable(const QModelIndex &index) const;
|
||||
|
||||
//! \brief Aligment as QVariant
|
||||
QVariant aligmentAsQVariant(const QModelIndex &index) const;
|
||||
|
||||
/*!
|
||||
* \brief Translation context
|
||||
* \return
|
||||
*/
|
||||
const char *getTranslationContext() const;
|
||||
//! \brief Column at position
|
||||
const CColumn &at(int columnNumber) const
|
||||
{
|
||||
return this->m_columns.at(columnNumber);
|
||||
}
|
||||
|
||||
private:
|
||||
QList<CColumn> m_columns;
|
||||
QString m_translationContext;
|
||||
QList<QString> m_headerNames;
|
||||
QList<int> m_propertyIndexes; // column to property index
|
||||
QList<int> m_alignments;
|
||||
const char *getTranslationContextChar() const;
|
||||
};
|
||||
|
||||
} // namespace BlackGui
|
||||
|
||||
Reference in New Issue
Block a user