Added model for meta-data, connected to widgets via mapper
This commit is contained in:
parent
dd28d94043
commit
8550316388
5 changed files with 84 additions and 0 deletions
|
@ -13,6 +13,7 @@ qt5_wrap_ui(UI_HEADERS
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
LogoTest.cpp
|
LogoTest.cpp
|
||||||
testdata.cpp
|
testdata.cpp
|
||||||
|
MetaDataModel.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
${UI_HEADERS}
|
${UI_HEADERS}
|
||||||
)
|
)
|
||||||
|
|
41
source/MetaDataModel.cpp
Normal file
41
source/MetaDataModel.cpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "MetaDataModel.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
MetaDataModel::MetaDataModel(QObject *parent) : QAbstractTableModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int MetaDataModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MetaDataModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant MetaDataModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||||
|
{
|
||||||
|
switch (index.column())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return m_participant;
|
||||||
|
case 1:
|
||||||
|
return m_instructor;
|
||||||
|
case 2:
|
||||||
|
return m_dateOfBirth;
|
||||||
|
case 3:
|
||||||
|
return m_dateOfTest;
|
||||||
|
case 4:
|
||||||
|
return m_remarks;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
24
source/MetaDataModel.h
Normal file
24
source/MetaDataModel.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
|
class MetaDataModel : public QAbstractTableModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_participant;
|
||||||
|
QString m_instructor;
|
||||||
|
QDate m_dateOfBirth;
|
||||||
|
QDate m_dateOfTest;
|
||||||
|
QString m_remarks;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MetaDataModel(QObject *parent);
|
||||||
|
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;
|
||||||
|
};
|
|
@ -2,10 +2,12 @@
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include "testdata.h"
|
#include "testdata.h"
|
||||||
|
#include "MetaDataModel.h"
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QDataWidgetMapper>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
@ -15,6 +17,19 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
ui->actionSave_as->setIcon(QIcon::fromTheme("document-save-as", QIcon("/usr/share/gtk-doc/html/gtk2/document-save-as.png")));
|
ui->actionSave_as->setIcon(QIcon::fromTheme("document-save-as", QIcon("/usr/share/gtk-doc/html/gtk2/document-save-as.png")));
|
||||||
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||||
|
|
||||||
|
MetaDataModel *metaDataModel = new MetaDataModel(this);
|
||||||
|
|
||||||
|
QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
|
||||||
|
mapper->setModel(metaDataModel);
|
||||||
|
mapper->addMapping(ui->lineEdit, 0);
|
||||||
|
mapper->addMapping(ui->lineEdit_2, 1);
|
||||||
|
mapper->addMapping(ui->calendarWidget, 2);
|
||||||
|
mapper->addMapping(ui->calendarWidget_2, 3);
|
||||||
|
mapper->addMapping(ui->textEdit, 4);
|
||||||
|
mapper->toFirst();
|
||||||
|
|
||||||
|
//ui->tableView->setModel(metaDataModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
|
@ -104,6 +104,9 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextEdit" name="textEdit"/>
|
<widget class="QTextEdit" name="textEdit"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="tableView"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
|
Loading…
Reference in a new issue