#ifndef CCSTEMPLATEBAND_H #define CCSTEMPLATEBAND_H #include "ccstemplatebase.h" #include "ccstemplateitem.h" #include #include namespace CCS_Report { /// /// 定义报表Band类的基类 /// 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; } /// /// 添加静态表 /// /// /// bool AddItem(const Table &item) { Table *table =new Table(item); m_listItem.append(table); return true; } /// /// 添加文本元素 /// /// void AddItem(const Text &item) { QList 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); } /// /// 添加多个文本元素 /// /// void AddRangeItem(const QList& 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); } /// /// 添加图片元素 /// /// void AddItem(Image& item) { Image *pImage = new Image(item); ImageFormat *f = dynamic_cast(item.Format()); Table* table = new Table(1,1,f->marginLeft(),f->marginRight()); //缺省图片在表格的左边 table->AddCell(0,0,*pImage,CCSFrame::FrameNothing); //把段落的左右边距赋值给表格;缺省 = 页的边距 m_listItem.append(table); } /// /// 添加段落元素 /// /// void AddItem(Paragraph& item) { ParagraphFormat *f = dynamic_cast(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); } /// /// 添加表组元素 /// /// /// bool AddItem(TableGroup &item) { TableGroup* pTable = new TableGroup(item); m_listItem.append(pTable); return true; } /// /// 添加动态表元素 /// /// /// bool AddItem(TableDynamic&item) { TableDynamic* pTable = new TableDynamic(item); m_listItem.append(pTable); return true; } /// /// 添加纵向版面的空行 /// /// 空行个数 /// 字体大小 /// 行间距 /// 是否在新的页中显示 /// 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; } /// /// 添加横向版面的空行 /// /// 空行个数 /// 字体大小 /// 行间距 /// 是否在新的页中显示 /// 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; } /// /// 添加空行 /// /// 空行个数 /// 字体大小 /// 行间距 /// 是否在新的页中显示 /// 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{ {0, 100}}, 10, 10); dynamic_cast(local_table1->Format())->SetNewPage(bNew); dynamic_cast(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 items() { return m_listItem; } bandtype itemType() const { return m_Type; } protected: BaseFormat* m_Format; ///格式定义对象 QList m_listItem; ///包含的元素列表 bandtype m_Type; ///band类型 }; } #endif // CCSTEMPLATEBAND_H