238 lines
6.9 KiB
C
238 lines
6.9 KiB
C
|
#ifndef CCSTEMPLATEBAND_H
|
|||
|
#define CCSTEMPLATEBAND_H
|
|||
|
#include "ccstemplatebase.h"
|
|||
|
#include "ccstemplateitem.h"
|
|||
|
#include <QFont>
|
|||
|
#include <QPen>
|
|||
|
|
|||
|
namespace CCS_Report {
|
|||
|
/// <summary>
|
|||
|
/// 定义报表Band类的基类
|
|||
|
/// </summary>
|
|||
|
class BaseBand:public QObject
|
|||
|
{
|
|||
|
public:
|
|||
|
enum class bandtype
|
|||
|
{
|
|||
|
Cover,
|
|||
|
Header,
|
|||
|
Footer,
|
|||
|
Directory,
|
|||
|
Content,
|
|||
|
Appendix,
|
|||
|
Page,
|
|||
|
Water
|
|||
|
};
|
|||
|
BaseBand(QObject* parent=0):QObject(parent){}
|
|||
|
BaseBand(BaseFormat& format, QObject* parent=0):QObject(parent)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
BaseBand(const BaseBand& band)
|
|||
|
{
|
|||
|
// m_Format = new BaseFormat(*band.format());
|
|||
|
// foreach (BaseItem* item,m_listItem) {
|
|||
|
// m_listItem.append(new BaseItem(*item));
|
|||
|
// }
|
|||
|
|
|||
|
}
|
|||
|
virtual ~BaseBand()
|
|||
|
{
|
|||
|
if (m_Format != nullptr)
|
|||
|
delete m_Format;
|
|||
|
for(auto& item:m_listItem)
|
|||
|
{
|
|||
|
delete item;
|
|||
|
}
|
|||
|
}
|
|||
|
bool SetPage(const Page& item)
|
|||
|
{
|
|||
|
Page *page =new Page(item);
|
|||
|
m_listItem.append(page);
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加静态表
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddItem(const Table &item)
|
|||
|
{
|
|||
|
Table *table =new Table(item);
|
|||
|
m_listItem.append(table);
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加文本元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
void AddItem(const Text &item)
|
|||
|
{
|
|||
|
QList<Text*> listText;
|
|||
|
Text *pText = new Text(item);
|
|||
|
listText.append(pText);
|
|||
|
ParagraphFormat *pFormat = new ParagraphFormat(0);
|
|||
|
|
|||
|
// Paragraph para(listText,pFormat);
|
|||
|
TableFormat tableF;
|
|||
|
tableF.SetNewPage(item.Format()->newpage());
|
|||
|
Table* table = new Table(1,1,0,0);
|
|||
|
table->AddCell(0,0,item,CCSFrame::FrameNothing);
|
|||
|
//把段落的左右边距赋值给表格;缺省 = 页的边距
|
|||
|
m_listItem.append(table);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加多个文本元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
void AddRangeItem(const QList<Text>& item)
|
|||
|
{
|
|||
|
if (item.count() == 0) return;
|
|||
|
ParagraphFormat pFormat(0);
|
|||
|
|
|||
|
Paragraph para(pFormat);
|
|||
|
para.AddTexts(item);
|
|||
|
|
|||
|
TableFormat tableF;
|
|||
|
tableF.SetNewPage(item.at(0).Format()->newpage());
|
|||
|
Table* table = new Table(1,1,0,0);
|
|||
|
table->AddCell(0,0,para,CCSFrame::FrameNothing);
|
|||
|
//把段落的左右边距赋值给表格;缺省 = 页的边距
|
|||
|
m_listItem.append(table);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加图片元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
void AddItem(Image& item)
|
|||
|
{
|
|||
|
Image *pImage = new Image(item);
|
|||
|
ImageFormat *f = dynamic_cast<ImageFormat*>(item.Format());
|
|||
|
Table* table = new Table(1,1,f->marginLeft(),f->marginRight()); //缺省图片在表格的左边
|
|||
|
table->AddCell(0,0,*pImage,CCSFrame::FrameNothing);
|
|||
|
//把段落的左右边距赋值给表格;缺省 = 页的边距
|
|||
|
m_listItem.append(table);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加段落元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
void AddItem(Paragraph& item)
|
|||
|
{
|
|||
|
ParagraphFormat *f = dynamic_cast<ParagraphFormat*>(item.Format());
|
|||
|
Cell cell(item,0,0,CCSFrame::FrameNothing,f->alignment());
|
|||
|
Table* table = new Table(1,1,0,0);
|
|||
|
table->AddCell(cell);
|
|||
|
m_listItem.append(table);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 添加表组元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddItem(TableGroup &item)
|
|||
|
{
|
|||
|
TableGroup* pTable = new TableGroup(item);
|
|||
|
m_listItem.append(pTable);
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加动态表元素
|
|||
|
/// </summary>
|
|||
|
/// <param name="item"></param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddItem(TableDynamic&item)
|
|||
|
{
|
|||
|
TableDynamic* pTable = new TableDynamic(item);
|
|||
|
m_listItem.append(pTable);
|
|||
|
return true;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加纵向版面的空行
|
|||
|
/// </summary>
|
|||
|
/// <param name="num">空行个数</param>
|
|||
|
/// <param name="fontpixelsize">字体大小</param>
|
|||
|
/// <param name="linespace">行间距</param>
|
|||
|
/// <param name="bNew">是否在新的页中显示</param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddBlankLine(int num = 1, int fontpixelsize = 20, int linespace = 0,bool bNew=false)
|
|||
|
{
|
|||
|
bool bSuccess = AddBlankTable(num, fontpixelsize, linespace, bNew, CCSReportType::OrientationFlag::Portrait);
|
|||
|
return bSuccess;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加横向版面的空行
|
|||
|
/// </summary>
|
|||
|
/// <param name="num">空行个数</param>
|
|||
|
/// <param name="fontpixelsize">字体大小</param>
|
|||
|
/// <param name="linespace">行间距</param>
|
|||
|
/// <param name="bNew">是否在新的页中显示</param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddLandscapeBlankLine(int num = 1, int fontpixelsize = 20, int linespace = 0, bool bNew = false)
|
|||
|
{
|
|||
|
bool bSuccess = AddBlankTable(num, fontpixelsize, linespace, bNew, CCSReportType::OrientationFlag::Landscape);
|
|||
|
return bSuccess;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 添加空行
|
|||
|
/// </summary>
|
|||
|
/// <param name="num">空行个数</param>
|
|||
|
/// <param name="fontpixelsize">字体大小</param>
|
|||
|
/// <param name="linespace">行间距</param>
|
|||
|
/// <param name="bNew">是否在新的页中显示</param>
|
|||
|
/// <returns></returns>
|
|||
|
bool AddBlankTable(int num , int fontpixelsize, int linespace, bool bNew, CCSReportType::OrientationFlag enumOrient)
|
|||
|
{
|
|||
|
|
|||
|
int before = 0;
|
|||
|
QFont font;
|
|||
|
|
|||
|
font.setPixelSize(fontpixelsize);
|
|||
|
CCS_Report::Table* local_table1 = new CCS_Report::Table(num, 1, QMap<int, qreal>{ {0, 100}}, 10, 10);
|
|||
|
|
|||
|
dynamic_cast<TableFormat*>(local_table1->Format())->SetNewPage(bNew);
|
|||
|
dynamic_cast<TableFormat*>(local_table1->Format())->SetOrient(enumOrient);
|
|||
|
CCS_Report::Text textxh(" ", font, Qt::AlignCenter);
|
|||
|
|
|||
|
CCS_Report::ParagraphFormat formath(linespace, before, before);
|
|||
|
CCS_Report::Paragraph parah(textxh, formath);
|
|||
|
|
|||
|
CCS_Report::Cell cell11(parah, 0, 0, CCS_Report::CCSFrame::FrameNothing, Qt::AlignCenter);
|
|||
|
|
|||
|
local_table1->AddCell(cell11);
|
|||
|
for (int i = 1; i < num; i++)
|
|||
|
{
|
|||
|
cell11.SetCellInfo(i, 0, " ");
|
|||
|
local_table1->AddCell(cell11);
|
|||
|
}
|
|||
|
|
|||
|
m_listItem.append(local_table1);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
BaseFormat* format() const
|
|||
|
{
|
|||
|
return m_Format;
|
|||
|
}
|
|||
|
virtual BaseFormat* Format()
|
|||
|
{
|
|||
|
return m_Format;
|
|||
|
}
|
|||
|
QList<BaseItem*> items()
|
|||
|
{
|
|||
|
return m_listItem;
|
|||
|
}
|
|||
|
bandtype itemType() const
|
|||
|
{
|
|||
|
return m_Type;
|
|||
|
}
|
|||
|
protected:
|
|||
|
BaseFormat* m_Format; ///格式定义对象
|
|||
|
QList<BaseItem*> m_listItem; ///包含的元素列表
|
|||
|
bandtype m_Type; ///band类型
|
|||
|
};
|
|||
|
|
|||
|
}
|
|||
|
#endif // CCSTEMPLATEBAND_H
|