LibrePCB Developers Documentation
EditableListModel< T, TYPE > Class Template Referencefinal

A generic QAbstractTableModel subclass to view and edit list of various data types. More...

#include <editablelistmodel.h>

Inherits QAbstractTableModel.

+ Collaboration diagram for EditableListModel< T, TYPE >:

Public Types

enum  Column
 

Public Member Functions

 EditableListModel (const EditableListModel &other) noexcept=delete
 
 EditableListModel (QObject *parent=nullptr) noexcept
 
 ~EditableListModel () noexcept
 
const T & getValues () const noexcept
 
void setDefaultValue (const ValueType &value) noexcept
 
void setPlaceholderText (const QString &text) noexcept
 
void setValues (const T &values) noexcept
 
void setChoices (const T &choices) noexcept
 
void setDisplayText (const ValueType &value, const QString &text) noexcept
 
void setIcon (const ValueType &value, const QIcon &icon) noexcept
 
void addItem (const QVariant &editData) noexcept
 
void removeItem (const QVariant &editData) noexcept
 
void moveItemUp (const QVariant &editData) noexcept
 
void moveItemDown (const QVariant &editData) noexcept
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
EditableListModeloperator= (const EditableListModel &rhs) noexcept
 

Private Types

typedef T::value_type ValueType
 

Private Member Functions

QString getDisplayText (const Uuid &value) const noexcept
 
QString getDisplayText (const QUrl &value) const noexcept
 
QString getDisplayText (const QString &value) const noexcept
 
QVariant getDataForValue (const Uuid &value) const noexcept
 
QVariant getDataForValue (const QUrl &value) const noexcept
 
QVariant getDataForValue (const QString &value) const noexcept
 
tl::optional< UuidconvertInputValue (const QVariant &input, const tl::optional< Uuid > &tag) const noexcept
 
tl::optional< QString > convertInputValue (const QVariant &input, const tl::optional< QString > &tag) const noexcept
 
tl::optional< QUrl > convertInputValue (const QVariant &input, const tl::optional< QUrl > &tag) const noexcept
 
void updateComboBoxItems () noexcept
 

Private Attributes

mChoices
 
mValues
 
tl::optional< ValueTypemDefaultValue
 
tl::optional< ValueTypemNewValue
 
QString mPlaceholderText
 
QHash< ValueType, QString > mDisplayTexts
 
QHash< ValueType, QIcon > mIcons
 
ComboBoxDelegate::Items mComboBoxItems
 

Detailed Description

template<typename T, EditableListModelType TYPE = EditableListModelType::DEFAULT>
class librepcb::EditableListModel< T, TYPE >

A generic QAbstractTableModel subclass to view and edit list of various data types.

This class is similar to QStringListModel, but supports various other item types than QString.

Special Features:

  • Adds an additional column and row to allow modifying the model with librepcb::EditableTableWidget.
  • Automatic pretty printing and input validation for various data types:
    • Locales, e.g. "de_DE" -> "Deutsch (Deutschland)"
    • URLs
  • Optionally providing a QComboBox to choose from a predefined set of values (setChoices()). Values are automatically sorted by their text.
  • Support custom display text (setDisplayText()).
  • Support icons (setIcon()).
  • Duplicate values are revoked.

Member Typedef Documentation

◆ ValueType

typedef T::value_type ValueType
private

Member Enumeration Documentation

◆ Column

enum Column
Enumerator
COLUMN_TEXT 
COLUMN_ACTIONS 
_COLUMN_COUNT 

Constructor & Destructor Documentation

◆ EditableListModel() [1/2]

EditableListModel ( const EditableListModel< T, TYPE > &  other)
deletenoexcept

◆ EditableListModel() [2/2]

EditableListModel ( QObject *  parent = nullptr)
inlineexplicitnoexcept

◆ ~EditableListModel()

~EditableListModel ( )
inlinenoexcept

Member Function Documentation

◆ getValues()

const T& getValues ( ) const
inlinenoexcept

◆ setDefaultValue()

void setDefaultValue ( const ValueType value)
inlinenoexcept

◆ setPlaceholderText()

void setPlaceholderText ( const QString &  text)
inlinenoexcept

◆ setValues()

void setValues ( const T &  values)
inlinenoexcept

◆ setChoices()

void setChoices ( const T &  choices)
inlinenoexcept

◆ setDisplayText()

void setDisplayText ( const ValueType value,
const QString &  text 
)
inlinenoexcept

◆ setIcon()

void setIcon ( const ValueType value,
const QIcon &  icon 
)
inlinenoexcept

◆ addItem()

void addItem ( const QVariant &  editData)
inlinenoexcept
+ Here is the caller graph for this function:

◆ removeItem()

void removeItem ( const QVariant &  editData)
inlinenoexcept
+ Here is the caller graph for this function:

◆ moveItemUp()

void moveItemUp ( const QVariant &  editData)
inlinenoexcept
+ Here is the caller graph for this function:

◆ moveItemDown()

void moveItemDown ( const QVariant &  editData)
inlinenoexcept
+ Here is the caller graph for this function:

◆ rowCount()

int rowCount ( const QModelIndex &  parent = QModelIndex()) const
inlineoverride

◆ columnCount()

int columnCount ( const QModelIndex &  parent = QModelIndex()) const
inlineoverride

◆ data()

QVariant data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
inlineoverride

◆ headerData()

QVariant headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
inlineoverride

◆ flags()

Qt::ItemFlags flags ( const QModelIndex &  index) const
inlineoverride

◆ setData()

bool setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
inlineoverride

◆ operator=()

EditableListModel& operator= ( const EditableListModel< T, TYPE > &  rhs)
noexcept

◆ getDisplayText() [1/3]

QString getDisplayText ( const Uuid value) const
inlineprivatenoexcept

◆ getDisplayText() [2/3]

QString getDisplayText ( const QUrl &  value) const
inlineprivatenoexcept

◆ getDisplayText() [3/3]

QString getDisplayText ( const QString &  value) const
inlineprivatenoexcept
+ Here is the call graph for this function:

◆ getDataForValue() [1/3]

QVariant getDataForValue ( const Uuid value) const
inlineprivatenoexcept

◆ getDataForValue() [2/3]

QVariant getDataForValue ( const QUrl &  value) const
inlineprivatenoexcept

◆ getDataForValue() [3/3]

QVariant getDataForValue ( const QString &  value) const
inlineprivatenoexcept

◆ convertInputValue() [1/3]

tl::optional<Uuid> convertInputValue ( const QVariant &  input,
const tl::optional< Uuid > &  tag 
) const
inlineprivatenoexcept
+ Here is the call graph for this function:

◆ convertInputValue() [2/3]

tl::optional<QString> convertInputValue ( const QVariant &  input,
const tl::optional< QString > &  tag 
) const
inlineprivatenoexcept

◆ convertInputValue() [3/3]

tl::optional<QUrl> convertInputValue ( const QVariant &  input,
const tl::optional< QUrl > &  tag 
) const
inlineprivatenoexcept

◆ updateComboBoxItems()

void updateComboBoxItems ( )
inlineprivatenoexcept

Member Data Documentation

◆ mChoices

T mChoices
private

◆ mValues

T mValues
private

◆ mDefaultValue

tl::optional<ValueType> mDefaultValue
private

◆ mNewValue

tl::optional<ValueType> mNewValue
private

◆ mPlaceholderText

QString mPlaceholderText
private

◆ mDisplayTexts

QHash<ValueType, QString> mDisplayTexts
private

◆ mIcons

QHash<ValueType, QIcon> mIcons
private

◆ mComboBoxItems

ComboBoxDelegate::Items mComboBoxItems
private

The documentation for this class was generated from the following file: