diff --git a/.gitignore b/.gitignore index 8bf8c42..73e9f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /.gitmodules /submodules/ +/build/ +CMakeLists.txt.user diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4f1735..0656d7a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,7 @@ include(compiler) set( SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/tablemodel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tablemodel/modeldataitem.cpp ) include(qtmoc) diff --git a/src/tablemodel/modeldataitem.cpp b/src/tablemodel/modeldataitem.cpp new file mode 100644 index 0000000..966c706 --- /dev/null +++ b/src/tablemodel/modeldataitem.cpp @@ -0,0 +1,54 @@ +#include "modeldataitem.h" + +using namespace osdev::components::datamodels; + +ModelDataItem::ModelDataItem() +{ + +} + +ModelDataItem::ModelDataItem(const QHash &data_item) + : m_itemHash() +{ + for(const auto &key : data_item.keys()) + { + m_itemHash.insert(key, data_item.value(key)); + } +} + +void ModelDataItem::setData(const QString &name, const QVariant &value) +{ + if(!name.isEmpty() && !name.isNull()) + { + m_itemHash.insert(name, value); + } +} + +QVariant ModelDataItem::getData(const QString &name) const +{ + if(!name.isEmpty() && !name.isNull() && m_itemHash.contains(name)) + { + return m_itemHash.value(name); + } + else + return QVariant(); +} + +int ModelDataItem::items() +{ + return m_itemHash.count(); +} + +QString ModelDataItem::asString() +{ + QString model_data_item; + + for(const auto &key : m_itemHash.keys()) + { + model_data_item.append(key); + model_data_item.append(" : "); + model_data_item.append( m_itemHash.value(key).toString()); + model_data_item.append(" | "); + } + return model_data_item; +} diff --git a/src/tablemodel/modeldataitem.h b/src/tablemodel/modeldataitem.h new file mode 100644 index 0000000..34fd70c --- /dev/null +++ b/src/tablemodel/modeldataitem.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +namespace osdev { +namespace components { +namespace datamodels { + +class ModelDataItem +{ +public: + ModelDataItem(); + ModelDataItem(const QHash &data_item); + + void setData(const QString &name, const QVariant &value); + QVariant getData(const QString &name) const; + int items(); + QStringList getKeys() { return m_itemHash.keys(); } + + QString asString(); + +private: + QHash m_itemHash; +}; + +} // End namespace datamodels +} // End namespace components +} // End namespace osdev diff --git a/src/tablemodel/tablemodel.cpp b/src/tablemodel/tablemodel.cpp index e69de29..981e3fc 100644 --- a/src/tablemodel/tablemodel.cpp +++ b/src/tablemodel/tablemodel.cpp @@ -0,0 +1,81 @@ +#include "tablemodel.h" + +using namespace osdev::components::datamodels; + +TableModelBase::TableModelBase(QObject *parent) +{ + +} + +int TableModelBase::rowCount(const QModelIndex &parent) const +{ + +} + +int TableModelBase::columnCount(const QModelIndex &parent) const +{ + +} + +QVariant TableModelBase::headerData(int section, Qt::Orientation orientation, int role) const +{ + +} + +QVariant TableModelBase::data(const QModelIndex &index, int role) const +{ + +} + +void TableModelBase::addHeaderColumn(const QString &headerName, const QString &db_field_name) +{ + +} + +QStringList TableModelBase::getHeaderNames() +{ + +} + +QString TableModelBase::getHeaderFieldByName( const QString &headerName) const +{ + +} + +QString TableModelBase::getHeaderColumnByField( const QString &db_field_name ) const +{ + +} + +QString TableModelBase::getHeaderFieldByIndex( int index ) const +{ + +} + +QString TableModelBase::getHeaderNameByIndex( int index ) const +{ + +} + +int TableModelBase::getHeaderIndexByName( const QString &header_name ) const +{ + +} + +bool TableModelBase::setHeaderData( int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + +} + +void TableModelBase::setKeyFields( const QStringList &key_fields ) +{ + +} + +// void fillList(const &DataObject &data_object); +// void addRecord(const ModelDataItem &data_item); + +void clear(); + +QString exportDataAsString(); +QStringList exportDataAsList(); diff --git a/src/tablemodel/tablemodel.h b/src/tablemodel/tablemodel.h index e69de29..fa028e8 100644 --- a/src/tablemodel/tablemodel.h +++ b/src/tablemodel/tablemodel.h @@ -0,0 +1,62 @@ +#pragma once + +// Qt +#include + +// Local +#include "modeldataitem.h" + +namespace osdev { +namespace components { +namespace datamodels { + +/*! + * \brief The TableModelBase class is the generic way of presenting a table in memory. + * It can be attached to different view-objects in a GUI. + */ +class TableModelBase : public QAbstractTableModel +{ + Q_OBJECT + +public: + TableModelBase(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + void addHeaderColumn(const QString &headerName, const QString &db_field_name = QString()); + + QStringList getHeaderNames(); + QString getHeaderFieldByName( const QString &headerName) const; + QString getHeaderColumnByField( const QString &db_field_name ) const; + QString getHeaderFieldByIndex( int index ) const; + QString getHeaderNameByIndex( int index ) const; + int getHeaderIndexByName( const QString &header_name ) const; + + bool setHeaderData( int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole ) override; + void setKeyFields( const QStringList &key_fields ); + const QStringList& getKeyFields() { return m_keyFields; } + + // void fillList(const &DataObject &data_object); + // void addRecord(const ModelDataItem &data_item); + + void clear(); + + QString exportDataAsString(); + QStringList exportDataAsList(); + +signals: + void signalHideLoading(); + +private: // Members ( Giggity! ) + QStringList m_keyFields; + QList> m_headers; + QStringList m_keyList; + QHash m_qhModelData; + +}; + +} // End namespace datamodels +} // End namespace components +} // End namespace osdev