Use central table format for printing
This commit is contained in:
parent
a718113747
commit
6eb585b08c
@ -36,6 +36,7 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS
|
|||||||
add_executable(${PROJECT_NAME} WIN32
|
add_executable(${PROJECT_NAME} WIN32
|
||||||
ESGRAF48.cpp
|
ESGRAF48.cpp
|
||||||
DataModel.cpp
|
DataModel.cpp
|
||||||
|
PrintableModel.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
${LOGO_TEST_UI}
|
${LOGO_TEST_UI}
|
||||||
${LOGO_TEST_QRC}
|
${LOGO_TEST_QRC}
|
||||||
|
@ -134,9 +134,7 @@ void CheckableTestModel::printTo(QTextCursor &cursor) const
|
|||||||
|
|
||||||
void CheckableTestModel::printTableTo(QTextCursor &cursor) const
|
void CheckableTestModel::printTableTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
||||||
QTextLength(QTextLength::PercentageLength, 9),
|
QTextLength(QTextLength::PercentageLength, 9),
|
||||||
@ -180,9 +178,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const
|
|||||||
|
|
||||||
void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const
|
void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76),
|
||||||
QTextLength(QTextLength::PercentageLength, 20),
|
QTextLength(QTextLength::PercentageLength, 20),
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../PrintableModel.h"
|
||||||
#include "CheckableTest.h"
|
#include "CheckableTest.h"
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
||||||
class CheckableTestModel : public QAbstractTableModel
|
class CheckableTestModel : public QAbstractTableModel, protected PrintableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ public:
|
|||||||
|
|
||||||
unsigned int getPoints() const;
|
unsigned int getPoints() const;
|
||||||
|
|
||||||
virtual void printTo(QTextCursor &cursor) const;
|
void printTo(QTextCursor &cursor) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool isValidIndex(const QModelIndex &index) const;
|
virtual bool isValidIndex(const QModelIndex &index) const;
|
||||||
|
@ -36,34 +36,12 @@ public:
|
|||||||
DataModel(QObject *parent);
|
DataModel(QObject *parent);
|
||||||
|
|
||||||
void printTo(QTextCursor &cursor) const;
|
void printTo(QTextCursor &cursor) const;
|
||||||
|
|
||||||
void write(std::ostream &outStream) const;
|
void write(std::ostream &outStream) const;
|
||||||
void read(std::istream &inStream);
|
void read(std::istream &inStream);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
|
|
||||||
private:
|
|
||||||
template <class ModelType>
|
|
||||||
void write(
|
|
||||||
const ModelType &model, QJsonObject &target, const char *name) const
|
|
||||||
{
|
|
||||||
QJsonObject jsonObject;
|
|
||||||
model.write(jsonObject);
|
|
||||||
target[name] = jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ModelType>
|
|
||||||
void read(
|
|
||||||
ModelType &model, const QJsonObject &source, const char *name) const
|
|
||||||
{
|
|
||||||
const auto &jsonObject = source[name];
|
|
||||||
if (jsonObject.isObject())
|
|
||||||
{
|
|
||||||
model.read(jsonObject.toObject());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void pluralModelChanged();
|
void pluralModelChanged();
|
||||||
void metaDataChanged();
|
void metaDataChanged();
|
||||||
|
@ -135,10 +135,8 @@ void MetaDataModel::printTo(QTextCursor &cursor) const
|
|||||||
{
|
{
|
||||||
cursor.insertBlock();
|
cursor.insertBlock();
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None);
|
tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None);
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 25),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 25),
|
||||||
QTextLength(QTextLength::PercentageLength, 25),
|
QTextLength(QTextLength::PercentageLength, 25),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../PrintableModel.h"
|
||||||
#include "Age.h"
|
#include "Age.h"
|
||||||
|
|
||||||
#include "MetaDataModel.pb.h"
|
#include "MetaDataModel.pb.h"
|
||||||
@ -10,7 +11,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
||||||
class MetaDataModel : public QAbstractTableModel
|
class MetaDataModel : public QAbstractTableModel, protected PrintableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -25,16 +26,14 @@ public:
|
|||||||
MetaDataModel(QObject *parent);
|
MetaDataModel(QObject *parent);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value,
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
int role = Qt::EditRole) override;
|
|
||||||
|
|
||||||
void read(const ESGRAF48::MetaDataModel &model);
|
void read(const ESGRAF48::MetaDataModel &model);
|
||||||
void write(ESGRAF48::MetaDataModel &model) const;
|
void write(ESGRAF48::MetaDataModel &model) const;
|
||||||
|
|
||||||
void printTo(QTextCursor &cursor) const;
|
void printTo(QTextCursor &cursor) const override;
|
||||||
|
|
||||||
Age getAge() const
|
Age getAge() const
|
||||||
{
|
{
|
||||||
|
11
source/PrintableModel.cpp
Normal file
11
source/PrintableModel.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "PrintableModel.h"
|
||||||
|
|
||||||
|
QTextTableFormat PrintableModel::defaultTableFormat()
|
||||||
|
{
|
||||||
|
QTextTableFormat tableFormat;
|
||||||
|
tableFormat.setCellPadding(2);
|
||||||
|
tableFormat.setCellSpacing(0);
|
||||||
|
|
||||||
|
return tableFormat;
|
||||||
|
}
|
||||||
|
|
12
source/PrintableModel.h
Normal file
12
source/PrintableModel.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QTextTableFormat>
|
||||||
|
|
||||||
|
class PrintableModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void printTo(QTextCursor &cursor) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static QTextTableFormat defaultTableFormat();
|
||||||
|
};
|
@ -217,9 +217,7 @@ void ResultModel::printTo(QTextCursor &cursor) const
|
|||||||
cursor.insertBlock();
|
cursor.insertBlock();
|
||||||
cursor.insertText("\nProzentränge (PR)");
|
cursor.insertText("\nProzentränge (PR)");
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
const unsigned int columnCount = 10;
|
const unsigned int columnCount = 10;
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../PrintableModel.h"
|
||||||
#include "Age.h"
|
#include "Age.h"
|
||||||
#include "TestResult.h"
|
#include "TestResult.h"
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
||||||
class ResultModel : public QAbstractTableModel
|
class ResultModel : public QAbstractTableModel, protected PrintableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -36,5 +37,5 @@ public:
|
|||||||
void setPassivResult(unsigned int points);
|
void setPassivResult(unsigned int points);
|
||||||
void setGenitivResult(unsigned int points);
|
void setGenitivResult(unsigned int points);
|
||||||
|
|
||||||
void printTo(QTextCursor &cursor) const;
|
void printTo(QTextCursor &cursor) const override;
|
||||||
};
|
};
|
||||||
|
@ -11,9 +11,7 @@ LateSkillsModel::LateSkillsModel(QObject *parent)
|
|||||||
|
|
||||||
void LateSkillsModel::printTableTo(QTextCursor &cursor) const
|
void LateSkillsModel::printTableTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
||||||
QTextLength(QTextLength::PercentageLength, 5),
|
QTextLength(QTextLength::PercentageLength, 5),
|
||||||
|
@ -63,9 +63,7 @@ std::string PluralModel::getName() const
|
|||||||
|
|
||||||
void PluralModel::printTableTo(QTextCursor &cursor) const
|
void PluralModel::printTableTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10),
|
||||||
QTextLength(QTextLength::PercentageLength, 10),
|
QTextLength(QTextLength::PercentageLength, 10),
|
||||||
|
@ -209,9 +209,7 @@ std::string V2SvkModel::getName() const
|
|||||||
|
|
||||||
void V2SvkModel::printTableTo(QTextCursor &cursor) const
|
void V2SvkModel::printTableTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat12;
|
QTextTableFormat tableFormat12 = defaultTableFormat();
|
||||||
tableFormat12.setCellPadding(2);
|
|
||||||
tableFormat12.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat12.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
tableFormat12.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
||||||
QTextLength(QTextLength::PercentageLength, 5),
|
QTextLength(QTextLength::PercentageLength, 5),
|
||||||
@ -231,9 +229,7 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const
|
|||||||
QTextLength(QTextLength::PercentageLength, 1),
|
QTextLength(QTextLength::PercentageLength, 1),
|
||||||
QTextLength(QTextLength::PercentageLength, 3)});
|
QTextLength(QTextLength::PercentageLength, 3)});
|
||||||
|
|
||||||
QTextTableFormat tableFormat6;
|
QTextTableFormat tableFormat6 = defaultTableFormat();
|
||||||
tableFormat6.setCellPadding(2);
|
|
||||||
tableFormat6.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
|
||||||
QTextLength(QTextLength::PercentageLength, 10),
|
QTextLength(QTextLength::PercentageLength, 10),
|
||||||
@ -329,9 +325,7 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const
|
|||||||
|
|
||||||
void V2SvkModel::printSummaryTo(QTextCursor &cursor) const
|
void V2SvkModel::printSummaryTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72),
|
||||||
QTextLength(QTextLength::PercentageLength, 20),
|
QTextLength(QTextLength::PercentageLength, 20),
|
||||||
|
@ -131,9 +131,7 @@ std::string VerbEndModel::getName() const
|
|||||||
|
|
||||||
void VerbEndModel::printSummaryTo(QTextCursor &cursor) const
|
void VerbEndModel::printSummaryTo(QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat = defaultTableFormat();
|
||||||
tableFormat.setCellPadding(2);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
|
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 46),
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 46),
|
||||||
QTextLength(QTextLength::PercentageLength, 25),
|
QTextLength(QTextLength::PercentageLength, 25),
|
||||||
|
Reference in New Issue
Block a user