2025-06-23 18:01:09 +08:00
# ifndef CCSTEMPLATEITEM_H
2025-06-23 10:41:33 +08:00
# define CCSTEMPLATEITEM_H
# include "ccstemplatebase.h"
# include <QHash>
# include <QMargins>
# include "QColor"
# include "QFont"
# include "QMap"
# include "QPen"
# include "common_types.h"
namespace CCS_Report {
/// <summary>
/// 页属性格式定义,【暂时未用】
/// </summary>
class PageFormat : public BaseFormat
{
public :
PageFormat ( ) : BaseFormat ( ) { }
PageFormat ( const QColor & color , const int & orient , const qreal & top , const qreal & bottom , const qreal & left , const qreal & right ) : BaseFormat ( )
{
m_Color = color ;
m_Orientation = orient ;
m_PageTop = top ;
m_PageBottom = bottom ;
m_PageLeft = left ;
m_PageRight = right ;
}
PageFormat ( const qreal & top , const qreal & bottom , const qreal & left , const qreal & right ) : BaseFormat ( )
{
m_Color = QColor ( Qt : : white ) ;
m_Orientation = 0 ;
m_PageTop = top ;
m_PageBottom = bottom ;
m_PageLeft = left ;
m_PageRight = right ;
}
PageFormat ( PageFormat & format ) : BaseFormat ( )
{
m_Color = format . m_Color ;
m_Orientation = format . m_Orientation ;
m_PageTop = format . m_PageTop ;
m_PageBottom = format . m_PageBottom ;
m_PageLeft = format . m_PageLeft ;
m_PageRight = format . m_PageRight ;
}
~ PageFormat ( ) { }
inline QColor color ( ) const { return m_Color ; }
inline void SetColor ( const QColor & color ) { m_Color = color ; }
qreal pagetop ( ) const { return m_PageTop ; }
qreal pagebottom ( ) const { return m_PageBottom ; }
qreal pageleft ( ) const { return m_PageLeft ; }
qreal pageright ( ) const { return m_PageRight ; }
int orientation ( ) const { return m_Orientation ; }
void SetPageTop ( qreal & top ) { m_PageTop = top ; }
void SetPageBottom ( qreal & bottom ) { m_PageBottom = bottom ; }
void SetPageLeft ( qreal & left ) { m_PageLeft = left ; }
void SetPageRight ( qreal & right ) { m_PageRight = right ; }
void SetOrientation ( int & orient ) { m_Orientation = orient ; }
private :
QColor m_Color ; //页的背景色
qreal m_PageTop ; //页边距 上,如果有页眉,在实现时,当小于页眉高度,则以页眉为准
qreal m_PageBottom ; //页边距 下;距底端距离 如果有页脚 在代码实现时 如果页脚高度大于此值,则以页脚为准
qreal m_PageLeft ; //页边距 左 跟边框没有关系
qreal m_PageRight ; //页边距 右 跟边框没有关系
QMargins m_margin ;
int m_Orientation ; //页方向;纵向、横向
} ;
/// <summary>
/// 元素页类定义
/// </summary>
class Page : public BaseItem
{
public :
Page ( ) : BaseItem ( " " )
{
m_Format = new PageFormat ( ) ;
m_Type = classtype : : Page ;
}
Page ( const qreal & top , const qreal & bottom , const qreal & left , const qreal & right , QString name = " " ) : BaseItem ( name )
{
m_Format = new PageFormat ( top , bottom , left , right ) ;
m_Type = classtype : : Page ;
}
Page ( PageFormat & format )
{
m_Format = new PageFormat ( format ) ;
m_Type = classtype : : Page ;
}
Page ( const Page & page )
{
PageFormat * pF = dynamic_cast < PageFormat * > ( page . m_Format ) ;
m_Format = new PageFormat ( * pF ) ;
m_Name = page . m_Name ;
m_Type = classtype : : Page ;
}
Page & operator = ( const Page & page ) {
PageFormat * pF = dynamic_cast < PageFormat * > ( page . m_Format ) ;
if ( m_Format ! = nullptr ) { delete m_Format ; }
m_Format = new PageFormat ( * pF ) ;
m_Name = page . m_Name ;
m_Type = page . m_Type ;
}
private :
} ;
/// <summary>
/// 文本属性类
/// </summary>
class TextFormat : public BaseFormat
{
public :
TextFormat ( ) : BaseFormat ( )
{
QFont font = QFont ( " SimSun " , 9 ) ;
font . setPixelSize ( 40 ) ;
Init ( QPen ( ) , font , Qt : : AlignVCenter , 0 , CCSTextWrapType : : Letter ) ;
}
TextFormat ( const QPen pen , const QFont font , Qt : : AlignmentFlag flag ) : BaseFormat ( )
{
Init ( pen , font , flag , 0 , CCSTextWrapType : : Letter ) ;
}
TextFormat ( const QPen pen , const QFont font , Qt : : AlignmentFlag flag , int space , CCSTextWrapType : : TextWrapFlag wrap = CCSTextWrapType : : Letter , bool group = false ) : BaseFormat ( )
{
Init ( pen , font , flag , space , wrap , group ) ;
}
void Init ( QPen pen , QFont font , Qt : : AlignmentFlag flag , int space , CCSTextWrapType : : TextWrapFlag wrap , bool group = false )
{
m_Pen = pen ;
m_Font = font ;
m_qAlignCharFormatFlag = flag ; // 字符串对齐方式 : Qt::AlignTop,Qt::AlignBottom,Qt::AlignVCenter
m_iAddFirstSpaceFlag = space ; // =0 不加空格
m_iWrapFlag = wrap ;
m_bGroup = group ;
m_qAngle = 0 ;
m_Color = Qt : : black ;
}
TextFormat ( const TextFormat & textF )
{
m_Pen = textF . m_Pen ;
m_Font = textF . m_Font ;
m_qAlignCharFormatFlag = textF . m_qAlignCharFormatFlag ; // 字符串对齐方式 : Qt::AlignTop,Qt::AlignBottom,Qt::AlignVCenter
m_iAddFirstSpaceFlag = textF . m_iAddFirstSpaceFlag ; // =0 不加空格
m_iWrapFlag = textF . m_iWrapFlag ;
m_bGroup = textF . m_bGroup ;
m_qAngle = textF . m_qAngle ;
m_Color = textF . m_Color ;
}
TextFormat & operator = ( const TextFormat & textF ) {
m_Pen = textF . m_Pen ;
m_Font = textF . m_Font ;
m_qAlignCharFormatFlag = textF . m_qAlignCharFormatFlag ; // 字符串对齐方式 : Qt::AlignTop,Qt::AlignBottom,Qt::AlignVCenter
m_iAddFirstSpaceFlag = textF . m_iAddFirstSpaceFlag ; // =0 不加空格
m_iWrapFlag = textF . m_iWrapFlag ;
m_bGroup = textF . m_bGroup ;
m_qAngle = textF . m_qAngle ;
m_Color = textF . m_Color ;
return * this ;
}
~ TextFormat ( ) { }
/// <summary>
/// 文本字体
/// </summary>
/// <returns></returns>
inline QFont font ( ) const { return m_Font ; }
inline void SetFont ( const QFont & font ) { m_Font = font ; }
inline QPen pen ( ) const { return m_Pen ; }
inline void SetPen ( const QPen & pen ) { m_Pen = pen ; }
/// <summary>
/// 字体颜色
/// </summary>
/// <returns></returns>
inline QColor color ( ) const { return m_Color ; }
inline void SetColor ( const QColor & value ) { m_Color = value ; }
/// <summary>
/// 设置上、下标标识
/// </summary>
/// <returns></returns>
inline int charformat ( ) const { return m_qAlignCharFormatFlag ; }
inline void SetCharFormat ( const int & flag ) { m_qAlignCharFormatFlag = flag ; }
/// <summary>
/// 是否加空格 【目前未实现】
/// </summary>
/// <returns></returns>
inline int spaceflag ( ) const { return m_iAddFirstSpaceFlag ; }
inline void SetSpaceFlag ( int & flag ) { m_iAddFirstSpaceFlag = flag ; }
/// <summary>
/// 文本折行标识;
/// 当文本在一个单元格中的一行显示不下时,进行换行的标识
/// </summary>
/// <returns></returns>
inline CCSTextWrapType : : TextWrapFlag wrapflag ( ) const { return m_iWrapFlag ; }
inline void SetWrapFlag ( CCSTextWrapType : : TextWrapFlag & flag ) { m_iWrapFlag = flag ; }
/// <summary>
/// 是否属于某个组 ; 缺省false; 只有在定义tablegroup元素时用到此属性
/// </summary>
/// <returns></returns>
inline bool group ( ) const { return m_bGroup ; }
inline void SetGroup ( bool & flag ) { m_bGroup = flag ; }
/// <summary>
/// 字体角度【目前只支持水印】
/// </summary>
/// <returns></returns>
inline qreal angle ( ) const { return m_qAngle ; }
inline void SetAngle ( const qreal & value ) { m_qAngle = value ; }
private :
bool m_bGroup ; //是否属于某个组 ; 缺省false; 只有在定义tablegroup时用到此属性
int m_iClose ; //标识当进行折行时向前一个粘合不能拆分还是后一个不能拆分;缺省 =0 不粘合 =-1 向左边靠近粘合 =1 向右边粘合
int m_qAlignCharFormatFlag = 0 ; // =0 noraml 字-1 下标 1 上标 符串对齐方式 : Qt::AlignTop,Qt::AlignBottom,Qt::AlignVCenter
int m_iAddFirstSpaceFlag = 1 ; // =0 不加空格
qreal m_height ; //高度
qreal m_qAngle ;
QPen m_Pen ; //包含、宽度、样式
QFont m_Font ; //字体、字体大小、加粗、斜体、上划线、下划线、删除线
QColor m_Color ; //颜色
CCSTextWrapType : : TextWrapFlag m_iWrapFlag = CCSTextWrapType : : Word ;
} ;
/// <summary>
///
/// </summary>
class Text : public BaseItem
{
public :
Text ( ) : BaseItem ( " " )
{
m_Type = classtype : : Text ;
m_Format = new TextFormat ( ) ;
m_strText = " " ;
}
Text ( const QString & content , const QFont & font = QFont ( ) , const Qt : : AlignmentFlag scriptflag = Qt : : AlignVCenter , QPen pen = QPen ( ) ,
int space = 0 , CCSTextWrapType : : TextWrapFlag wrap = CCSTextWrapType : : Letter , bool group = false , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( pen , font , scriptflag , space , wrap , group ) ;
}
/*Text(const QString& content,QString name=""):BaseItem(name)
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( ) ;
}
Text ( const QString & content , const Qt : : AlignmentFlag & scriptflag , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( ) ;
TextFormat * pF = static_cast < TextFormat * > ( m_Format ) ;
pF - > SetCharFormat ( scriptflag ) ;
}
Text ( const QString & content , const QFont & font , int pixelsize , const Qt : : AlignmentFlag scriptflag = Qt : : AlignVCenter , bool group = false , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( QPen ( ) , font , scriptflag , 0 , CCSTextWrapType : : Letter , pixelsize , group ) ;
}
Text ( const QString & content , const QFont & font , int pixelsize , const QPen & pen , const Qt : : AlignmentFlag scriptflag = Qt : : AlignVCenter , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( pen , font , scriptflag , 0 , CCSTextWrapType : : Letter , pixelsize ) ;
} */
Text ( const QString & content , const TextFormat & format , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Text ;
m_strText = content ;
m_Format = new TextFormat ( format ) ;
}
Text ( const Text & text )
{
m_Type = classtype : : Text ;
m_strText = text . m_strText ;
TextFormat * pF = dynamic_cast < TextFormat * > ( text . m_Format ) ;
m_Format = new TextFormat ( * pF ) ;
m_Name = text . m_Name ;
}
Text & operator = ( const Text & text ) {
m_Type = text . m_Type ;
m_strText = text . m_strText ;
TextFormat * pF = dynamic_cast < TextFormat * > ( text . m_Format ) ;
if ( m_Format ! = nullptr ) { delete m_Format ; }
m_Format = new TextFormat ( * pF ) ;
m_Name = text . m_Name ;
return * this ;
}
inline QString textvalue ( ) const { return m_strText ; }
inline void SetValue ( const QString & value ) { m_strText = value ; }
inline void SetFont ( const QFont & font )
{
static_cast < TextFormat * > ( m_Format ) - > SetFont ( font ) ;
}
private :
QString m_strText ;
} ;
/* 空行*/
class BlankLine : public BaseItem
{
public :
BlankLine ( ) : BaseItem ( )
{
m_Type = classtype : : BlankLine ;
m_strText = " " ;
m_Format = new TextFormat ( QPen ( ) , QFont ( ) , Qt : : AlignVCenter ) ;
m_iLineNum = 1 ;
}
BlankLine ( const QPen & pen , const QFont & font ) : BaseItem ( )
{
m_Type = classtype : : BlankLine ;
m_strText = " " ;
m_Format = new TextFormat ( pen , font , Qt : : AlignVCenter ) ;
m_iLineNum = 1 ;
}
BlankLine ( const QPen & pen , const QFont & font , int lineNum ) : BaseItem ( )
{
m_Type = classtype : : BlankLine ;
m_strText = " " ;
m_Format = new TextFormat ( pen , font , Qt : : AlignVCenter ) ;
m_iLineNum = lineNum ;
}
BlankLine ( int lineNum ) : BaseItem ( )
{
m_Type = classtype : : BlankLine ;
m_strText = " " ;
m_Format = new TextFormat ( QPen ( ) , QFont ( ) , Qt : : AlignVCenter ) ;
m_iLineNum = lineNum ;
}
BlankLine ( const BlankLine & blank )
{
m_strText = blank . m_strText ;
m_iLineNum = blank . m_iLineNum ;
m_Type = classtype : : BlankLine ;
TextFormat * pF = dynamic_cast < TextFormat * > ( blank . m_Format ) ;
m_Format = new TextFormat ( * pF ) ;
m_Name = blank . m_Name ;
}
private :
QString m_strText ;
int m_iLineNum ;
} ;
/// <summary>
/// 图片属性设置
/// </summary>
class ImageFormat : public BaseFormat
{
public :
ImageFormat ( ) : BaseFormat ( )
{
//自适应
Init ( CCSImageType : : SelfWidth , CCSImageType : : SelfHeight , 0 , 0 , 100 , 0 ) ; //缺省和页边距相同
}
ImageFormat ( const CCSImageType : : ImageWidthFlag widthmode , const CCSImageType : : ImageHeightFlag heightmode = CCSImageType : : SelfHeight , const qreal & opacity = 100 ) : BaseFormat ( )
{
Init ( widthmode , heightmode , 0 , 0 , opacity , 0 ) ;
}
void Init ( const CCSImageType : : ImageWidthFlag widthmode , const CCSImageType : : ImageHeightFlag heightmode ,
const qreal & width , const qreal & height , const qreal & opacity , const int & showmode )
{
m_eWidthMode = widthmode ;
m_iWidth = width ; //缺省和页边距相同
m_iHeigth = height ;
m_opacity = opacity ;
m_eShowMode = showmode ; //自适应
m_eHeightMode = heightmode ;
}
ImageFormat ( const ImageFormat & imageF ) : BaseFormat ( imageF )
{
m_eWidthMode = imageF . m_eWidthMode ;
m_iWidth = imageF . m_iWidth ;
m_iHeigth = imageF . m_iHeigth ;
m_opacity = imageF . m_opacity ;
m_eShowMode = imageF . m_eShowMode ;
m_eHeightMode = imageF . m_eHeightMode ;
m_qAngle = imageF . m_qAngle ;
}
ImageFormat & operator = ( const ImageFormat & imageF ) {
m_eWidthMode = imageF . m_eWidthMode ;
m_iWidth = imageF . m_iWidth ;
m_iHeigth = imageF . m_iHeigth ;
m_opacity = imageF . m_opacity ;
m_eShowMode = imageF . m_eShowMode ;
m_eHeightMode = imageF . m_eHeightMode ;
m_qAngle = imageF . m_qAngle ;
return * this ;
}
~ ImageFormat ( ) { }
// inline QFont font() const {return m_Font;}
// inline void SetFont(const QFont & font) {m_Font = font;}
// inline QColor color() const {return m_Color;}
// inline void SetColor(const QColor& color){m_Color = color;}
inline qreal width ( ) const { return m_iWidth ; }
inline void SetWidth ( const qreal & width ) { m_iWidth = width ; }
inline qreal height ( ) const { return m_iHeigth ; }
inline void SetHeight ( const qreal & height ) { m_iHeigth = height ; }
inline void SetImageSize ( const qreal & width , const qreal & height )
{
m_iWidth = width ;
m_iHeigth = height ;
}
/// <summary>
/// 透明度【暂未使用】
/// </summary>
/// <returns></returns>
inline qreal opacity ( ) const { return m_opacity ; }
inline void SetOpacity ( const qreal & opacity ) { m_opacity = opacity ; }
/// <summary>
/// 角度 【暂未实现】
/// </summary>
/// <returns></returns>
inline qreal angle ( ) const { return m_qAngle ; }
inline void SetAngle ( const qreal & value ) { m_qAngle = value ; }
/// <summary>
/// 宽度模式设置
/// </summary>
/// <returns></returns>
inline CCSImageType : : ImageWidthFlag widthmode ( ) const { return m_eWidthMode ; }
inline void SetWidthMode ( const CCSImageType : : ImageWidthFlag & flag ) { m_eWidthMode = flag ; }
/// <summary>
/// 显示模式,=0 自适应 =1 裁剪
/// </summary>
/// <returns></returns>
inline qreal showmode ( ) const { return m_eShowMode ; }
inline void SetShowMode ( const int & mode ) { m_eShowMode = mode ; }
/// <summary>
/// 高度模式设置
/// </summary>
/// <returns></returns>
inline CCSImageType : : ImageHeightFlag heightmode ( ) const { return m_eHeightMode ; }
inline void SetHeightMode ( const CCSImageType : : ImageHeightFlag & flag ) { m_eHeightMode = flag ; }
private :
// QColor m_Color;
// QFont m_Font;
int m_eShowMode ; //显示模式,=0 自适应 =1 裁剪
qreal m_iHeigth ;
qreal m_iWidth ;
qreal m_opacity ; //透明度 0~100 对应0~255; 值越大越不透明
CCSImageType : : ImageWidthFlag m_eWidthMode ; //
CCSImageType : : ImageHeightFlag m_eHeightMode ; //
qreal m_qAngle ;
} ;
/// <summary>
/// 图片元素类
/// </summary>
class Image : public BaseItem
{
public :
Image ( ) : BaseItem ( " " )
{
m_Type = classtype : : Image ;
m_Format = new ImageFormat ( ) ;
m_strPath = " " ;
}
Image ( const QString & strPath , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Image ;
m_Format = new ImageFormat ( ) ;
m_strPath = strPath ;
}
// Image(const QString& strPath,qreal& opacity,QString name=""):BaseItem(name)
// {
// m_Type = classtype::Image;
// m_strPath = strPath;
// m_Format = new ImageFormat(opacity);
// }
// Image(const QString& strPath,qreal& width,qreal& height,QString name=""):BaseItem(name)
// {
// m_Type = classtype::Image;
// m_Format = new ImageFormat(width,height);
// m_strPath = strPath;
// }
// Image(const QString& strPath,qreal& width,qreal& height,qreal& opacity,QString name=""):BaseItem(name)
// {
// m_Type = classtype::Image;
// m_Format = new ImageFormat(width,height,opacity);
// m_strPath = strPath;
// }
Image ( const QString & strPath , const ImageFormat & format , QString name = " " ) : BaseItem ( name )
{
m_Type = classtype : : Image ;
m_strPath = strPath ;
m_Format = new ImageFormat ( format ) ;
}
Image ( const Image & image )
{
m_Type = classtype : : Image ;
m_strPath = image . m_strPath ;
ImageFormat * pF = dynamic_cast < ImageFormat * > ( image . m_Format ) ;
m_Format = new ImageFormat ( * pF ) ;
m_Name = image . m_Name ;
}
Image & operator = ( const Image & image ) {
m_strPath = image . m_strPath ;
ImageFormat * pF = dynamic_cast < ImageFormat * > ( image . m_Format ) ;
if ( m_Format ! = nullptr ) { delete m_Format ; }
m_Format = new ImageFormat ( * pF ) ;
m_Name = image . m_Name ;
m_Type = image . m_Type ;
return * this ;
}
inline QString ImagePath ( ) const { return m_strPath ; }
inline void SetImagePath ( const QString path ) { m_strPath = path ; }
private :
QString m_strPath ; //图片路径
} ;
/// <summary>
/// 段落元素属性类
/// </summary>
class ParagraphFormat : public BaseFormat
{
public :
ParagraphFormat ( ) : BaseFormat ( )
{
Init ( 0 , 0 , Qt : : AlignLeft , QFont ( ) , true , 0.0 , 0.0 , 0.0 ) ;
}
ParagraphFormat ( const int grade , QFont font = QFont ( ) , qreal space = 0.0 , qreal before = 0.0 , qreal after = 0.0 , const int indent = 0 , bool bShow = true , const Qt : : Alignment alignment = Qt : : AlignLeft ) : BaseFormat ( )
{
Init ( grade , indent , alignment , font , bShow , space , before , after ) ;
}
ParagraphFormat ( qreal space , qreal before , qreal after , const Qt : : Alignment alignment = Qt : : AlignLeft , const int grade = 0 , const int indent = 0 , QFont font = QFont ( ) , bool bShow = true ) : BaseFormat ( )
{
Init ( grade , indent , alignment , font , bShow , space , before , after ) ;
}
// ParagraphFormat(const int& grade,const qreal& indent,QFont& font,int& pixelsize,qreal& space,qreal& before,qreal& after):BaseFormat()
// {
// Init(grade,indent,Qt::AlignLeft,font,pixelsize,true,space,before,after);
// }
// ParagraphFormat(const qreal& indent,qreal& space,qreal& before,qreal& after):BaseFormat()
// {
// Init(0,indent,Qt::AlignLeft,QFont(),false,space,before,after);
// }
// ParagraphFormat(const int& grade,const qreal& indent):BaseFormat()
// {
// Init(grade,indent,Qt::AlignLeft,QFont(),true,0.0,0.0,0.0);
// }
// ParagraphFormat(const qreal& indent,const Qt::Alignment alignment,const int marginLeft,const int margingRight):BaseFormat(marginLeft,-1,-1,margingRight)
// {
// Init(0,indent,alignment,QFont(),40,true,0.0,0.0,0.0);
// }
// ParagraphFormat(const int& grade,const qreal& indent,const Qt::Alignment alignment,const int marginLeft,const int margingRight):BaseFormat(marginLeft,-1,-1,margingRight)
// {
// Init(grade,indent,alignment,QFont(),40,true,0.0,0.0,0.0);
// }
ParagraphFormat ( const ParagraphFormat & paraF ) : BaseFormat ( paraF )
{
m_iGrade = paraF . m_iGrade ;
m_iIndent = paraF . m_iIndent ;
m_Alignment = paraF . m_Alignment ;
m_Font = paraF . m_Font ;
m_bShowGrade = paraF . m_bShowGrade ;
// m_FontPixelSize = paraF.m_FontPixelSize;
m_qLineSpace = paraF . m_qLineSpace ;
m_qDistanceAfter = paraF . m_qDistanceAfter ;
m_qDistanceBefore = paraF . m_qDistanceBefore ;
}
ParagraphFormat & operator = ( const ParagraphFormat & paraF ) {
m_iGrade = paraF . m_iGrade ;
m_iIndent = paraF . m_iIndent ;
m_Alignment = paraF . m_Alignment ;
m_Font = paraF . m_Font ;
m_bShowGrade = paraF . m_bShowGrade ;
//m_FontPixelSize = paraF.m_FontPixelSize;
m_qLineSpace = paraF . m_qLineSpace ;
m_qDistanceAfter = paraF . m_qDistanceAfter ;
m_qDistanceBefore = paraF . m_qDistanceBefore ;
return * this ;
}
~ ParagraphFormat ( ) { }
void Init ( const int grade , const int indent , const Qt : : Alignment alignment ,
const QFont & font , const bool & bShow ,
const qreal line , const qreal before , const qreal after )
{
m_iGrade = grade ;
m_iIndent = indent ;
m_Alignment = alignment ;
m_Font = font ;
m_bShowGrade = bShow ;
// m_FontPixelSize = size;
m_qLineSpace = line ;
m_qDistanceAfter = after ;
m_qDistanceBefore = before ;
}
/// <summary>
/// 段落级别设置 1~n
/// </summary>
/// <param name="grade"></param>
inline void SetGrade ( int & grade ) { m_iGrade = grade ; }
/// <summary>
/// 首行缩进 【暂未使用】
/// </summary>
/// <param name="indent"></param>
inline void SetIndent ( int & indent ) { m_iIndent = indent ; }
/// <summary>
/// 位置设置 居左、居右、居中
/// </summary>
/// <param name="align"></param>
inline void SetAlignment ( const Qt : : Alignment align ) { m_Alignment = align ; }
inline int grade ( ) const { return m_iGrade ; }
inline int indent ( ) const { return m_iIndent ; }
// inline int marginLeft() const {return m_iMarginLeft;}
// inline int marginRight() const {return m_iMarginRight;}
inline Qt : : Alignment alignment ( ) const { return m_Alignment ; }
/// <summary>
/// 级别字体设置
/// </summary>
/// <returns></returns>
inline QFont font ( ) const { return m_Font ; }
inline void SetFont ( const QFont font ) { m_Font = font ; }
/// <summary>
/// 是否显示级别号 true 显示
/// </summary>
/// <returns></returns>
inline bool showgrade ( ) const { return m_bShowGrade ; }
inline void SetShowGrade ( const bool bShow ) { m_bShowGrade = bShow ; }
/// <summary>
/// 行间距 以像素计
/// </summary>
/// <returns></returns>
inline qreal linespace ( ) const { return m_qLineSpace ; }
inline void SetLineSpace ( const qreal value ) { m_qLineSpace = value ; }
/// <summary>
/// 段前距离 以像素计
/// </summary>
/// <returns></returns>
inline qreal distancebefore ( ) const { return m_qDistanceBefore ; }
inline void SetDistanceBefore ( const qreal value ) { m_qDistanceBefore = value ; }
/// <summary>
/// 段后距离 以像素计
/// </summary>
/// <returns></returns>
inline qreal distanceafter ( ) const { return m_qDistanceAfter ; }
inline void SetDistanceAfter ( const qreal value ) { m_qDistanceAfter = value ; }
private :
int m_iGrade ;
int m_iIndent ; //首行缩进
Qt : : Alignment m_Alignment ;
//针对段落设置字体大小, 不针对Text设置字体, 以保证在同一段落内的字体相同
QFont m_Font ; //级别号的字体大小
// int m_FontPixelSize; //字体像素大小
bool m_bShowGrade ;
qreal m_qLineSpace ; //行间距 ; 以像素计
qreal m_qDistanceBefore ; //段前间距; 以像素计
qreal m_qDistanceAfter ; //段前间距; 以像素计
} ;
/// <summary>
/// 段落元素类;可包含多个文本类或者一个图片类
/// </summary>
/// <param name="image"></param>
/// <param name="format"></param>
/// <param name="name"></param>
/// <returns></returns>
class Paragraph : public BaseItem
{
public :
Paragraph ( ) : BaseItem ( ) {
m_Format = new ParagraphFormat ( ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const ParagraphFormat & format ) : BaseItem ( ) {
m_Format = new ParagraphFormat ( format ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const QString & text , QString name = " " ) : BaseItem ( name )
{
Text * pText = new Text ( text ) ;
m_Blocks . append ( pText ) ;
m_Format = new ParagraphFormat ( ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const QString & text , const ParagraphFormat & format , QString name = " " ) : BaseItem ( name )
{
Text * pText = new Text ( text ) ;
m_Blocks . append ( pText ) ;
m_Format = new ParagraphFormat ( format ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const Text & text , ParagraphFormat & format , QString name = " " ) : BaseItem ( name )
{
Text * pText = new Text ( text ) ;
m_Blocks . append ( pText ) ;
this - > m_Format = new ParagraphFormat ( format ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const QList < Text * > & texts , ParagraphFormat & format , QString name = " " ) : BaseItem ( name )
{
foreach ( Text * item , texts ) {
Text * text = new Text ( * item ) ;
m_Blocks . append ( text ) ;
}
this - > m_Format = new ParagraphFormat ( format ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const Image & image , ParagraphFormat & format , QString name = " " ) : BaseItem ( name )
{
Image * pImage = new Image ( image ) ;
m_Blocks . append ( pImage ) ;
this - > m_Format = new ParagraphFormat ( format ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph ( const Paragraph & para ) : BaseItem ( para )
{
for ( auto item : para . m_Blocks )
{
classtype name = item - > elementType ( ) ;
if ( name = = classtype : : Text )
{
Text * text = new Text ( * ( dynamic_cast < Text * > ( item ) ) ) ;
m_Blocks . append ( text ) ;
}
else
{
Image * image = new Image ( * ( dynamic_cast < Image * > ( item ) ) ) ;
m_Blocks . append ( image ) ;
}
}
ParagraphFormat * pF = dynamic_cast < ParagraphFormat * > ( para . m_Format ) ;
m_Format = new ParagraphFormat ( * pF ) ;
m_Type = classtype : : Paragraph ;
}
Paragraph & operator = ( const Paragraph & para ) {
for ( auto item : para . m_Blocks )
{
QString name = typeid ( item ) . name ( ) ;
if ( name . toLower ( ) . contains ( " text " ) )
{
Text * text = new Text ( * ( dynamic_cast < Text * > ( item ) ) ) ;
m_Blocks . append ( text ) ;
}
else
{
Image * image = new Image ( * ( dynamic_cast < Image * > ( item ) ) ) ;
m_Blocks . append ( image ) ;
}
}
ParagraphFormat * pF = dynamic_cast < ParagraphFormat * > ( para . m_Format ) ;
if ( m_Format ! = nullptr ) { delete m_Format ; }
m_Format = new ParagraphFormat ( * pF ) ;
m_Type = para . m_Type ;
}
~ Paragraph ( )
{
for ( auto item : m_Blocks )
{
delete item ;
}
}
/*在Paragraph中的集合只能是要么Text类型要么是Image类型
*/
inline bool AddText ( const Text & item )
{
if ( HasImageElement ( ) )
{
for ( auto item : m_Blocks )
{
delete item ;
}
}
Text * text = new Text ( item ) ;
m_Blocks . append ( text ) ;
}
inline bool AddTexts ( const QList < Text > items )
{
if ( HasImageElement ( ) )
{
for ( auto item : m_Blocks )
{
delete item ;
}
}
foreach ( Text item , items ) {
Text * text = new Text ( item ) ;
m_Blocks . append ( text ) ;
}
return true ;
}
/*在Paragraph中的集合只能是要么Text类型要么是Image类型; 如果是IMage, 只能是一张图片
*/
inline bool AddImage ( const Image & item )
{
for ( auto item : m_Blocks )
{
delete item ;
}
Image * image = new Image ( item ) ;
m_Blocks . append ( image ) ;
}
/// <summary>
/// 获取段落中的文本或者图片对象
/// </summary>
/// <returns></returns>
inline QList < BaseItem * > blocks ( ) const { return m_Blocks ; }
inline bool HasImageElement ( )
{
bool flag = false ;
for ( auto item : m_Blocks )
{
if ( item - > elementType ( ) = = classtype : : Text )
{
continue ;
}
flag = true ;
}
return flag ;
}
private :
QList < BaseItem * > m_Blocks ;
} ;
/// <summary>
/// 单元格属性类
/// </summary>
class CellFormat : public BaseFormat
{
public :
CellFormat ( ) : BaseFormat ( )
{
Init ( CCSFrame : : FrameAll , QPen ( ) , Qt : : AlignLeft , QColor ( 255 , 255 , 255 , 255 ) , 1 , 1 , 0 , 0 , 0.0 , false , false , false ) ;
}
CellFormat ( int rowIndex , int colIndex , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , qreal padding = 0 , bool dynamic = false , bool merge = false , bool tranrow = false ) : BaseFormat ( )
{
Init ( frames , QPen ( ) , alignment , QColor ( ) , rowspan , colspan , rowIndex , colIndex , padding , dynamic , merge , tranrow ) ;
}
void Init ( CCSFrame : : FrameFlags frames , QPen pen , Qt : : Alignment alignment , QColor backcolor ,
int rowspan , int colspan , int rowIndex , int colIndex , qreal padding , bool dynamic = false , bool merge = false , bool tranrow = false )
{
m_Frame = frames ;
m_FramePen = pen ;
m_Alignment = alignment ;
m_BackColor = backcolor ;
m_bBackColor = false ;
m_iRowSpan = rowspan ;
m_iColSpan = colspan ;
m_iRowIndex = rowIndex ;
m_iColumnIndex = colIndex ;
m_bDynamic = dynamic ;
m_bTranRow = tranrow ;
m_bMerge = merge ;
m_bGroup = false ;
m_bBreakRow = false ;
m_bRepeat = false ;
m_qPadding = padding ;
}
// CellFormat(int frames,QPen pen,Qt::Alignment alignment,QColor backcolor,
// int rowspan,int colspan,int rowIndex,int colIndex):BaseFormat()
// {
// m_Frame = frames;
// m_FramePen = pen;
// m_Alignment = alignment;
// m_BackColor = backcolor;
// m_bBackColor = false;
// m_qPadding = 0;
// m_qSpacing = 0;
// m_iRowSpan = rowspan;
// m_iColSpan = colspan;
// m_iRowIndex = rowIndex;
// m_iColumnIndex = colIndex;
// m_bDynamic = false;
// m_bTranRow = false;
// m_bMerge = false;
// }
CellFormat ( const CellFormat & cellF ) : BaseFormat ( cellF )
{
m_Frame = cellF . m_Frame ;
m_FramePen = cellF . m_FramePen ;
m_Alignment = cellF . m_Alignment ;
m_BackColor = cellF . m_BackColor ;
m_bBackColor = cellF . m_bBackColor ;
m_iRowSpan = cellF . m_iRowSpan ;
m_iColSpan = cellF . m_iColSpan ;
m_iRowIndex = cellF . m_iRowIndex ;
m_iColumnIndex = cellF . m_iColumnIndex ;
m_bDynamic = cellF . m_bDynamic ;
m_bTranRow = cellF . m_bTranRow ;
m_bMerge = cellF . m_bMerge ;
m_bGroup = cellF . m_bGroup ;
m_bBreakRow = cellF . m_bBreakRow ;
m_bRepeat = cellF . m_bRepeat ;
m_qPadding = cellF . m_qPadding ;
}
CellFormat & operator = ( const CellFormat & cellF ) {
m_Frame = cellF . m_Frame ;
m_FramePen = cellF . m_FramePen ;
m_Alignment = cellF . m_Alignment ;
m_BackColor = cellF . m_BackColor ;
m_bBackColor = cellF . m_bBackColor ;
m_iRowSpan = cellF . m_iRowSpan ;
m_iColSpan = cellF . m_iColSpan ;
m_iRowIndex = cellF . m_iRowIndex ;
m_iColumnIndex = cellF . m_iColumnIndex ;
m_bDynamic = cellF . m_bDynamic ;
m_bTranRow = cellF . m_bTranRow ;
m_bMerge = cellF . m_bMerge ;
m_bGroup = cellF . m_bGroup ;
m_bBreakRow = cellF . m_bBreakRow ;
m_bRepeat = cellF . m_bRepeat ;
m_qPadding = cellF . m_qPadding ;
return * this ;
}
/// <summary>
/// 是否有边框
/// </summary>
/// <param name="frame"></param>
inline void SetFrame ( const CCSFrame : : FrameFlags frame ) { m_Frame = frame ; }
inline CCSFrame : : FrameFlags frame ( ) const { return m_Frame ; }
/// <summary>
/// 边框样式
/// </summary>
/// <param name="pen"></param>
inline void SetFramePen ( const QPen & pen ) { m_FramePen = pen ; }
inline QPen framepen ( ) const { return m_FramePen ; }
/// <summary>
/// 单元格背景色
/// </summary>
/// <param name="color"></param>
inline void SetBackColor ( const QColor & color ) { m_BackColor = color ; }
inline QColor backColor ( ) const { return m_BackColor ; }
/// <summary>
/// 【未用】
/// </summary>
/// <param name="flag"></param>
inline void SetIfHasBackColor ( bool & flag ) { m_bBackColor = flag ; }
inline bool ifhasbackcolor ( ) { return m_bBackColor ; }
/// <summary>
/// 设置跨行个数
/// 此属性一般用于表格中的列头
/// </summary>
/// <param name="span"></param>
inline void SetRowSpan ( const int & span ) { m_iRowSpan = span ; }
inline int rowSpan ( ) const { return m_iRowSpan ; }
/// <summary>
/// 设置跨列个数
/// 此属性一般用于表格中的列头
/// </summary>
/// <param name="span"></param>
inline void SetColSpan ( const int & span ) { m_iColSpan = span ; }
inline int colSpan ( ) const { return m_iColSpan ; }
/// <summary>
/// 单元格内容的位置:居左、居右、居中
/// </summary>
/// <returns></returns>
inline Qt : : Alignment alignment ( ) const { return m_Alignment ; }
inline void SetAlignment ( const Qt : : Alignment align ) { m_Alignment = align ; }
/// <summary>
/// 设置行、列
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
inline void SetRowColumn ( int row , int column )
{
m_iRowIndex = row ;
m_iColumnIndex = column ;
}
/// <summary>
/// 行索引
/// </summary>
/// <returns></returns>
inline int rowIndex ( ) const { return m_iRowIndex ; }
/// <summary>
/// 列索引
/// </summary>
/// <returns></returns>
inline int colIndex ( ) const { return m_iColumnIndex ; }
/// <summary>
/// 是否为动态单元格;动态单元格是指此单元格中的数据根据用户设定的数据的多少确定,动态扩展列;
/// 此属性一般用于表格中的列头
/// </summary>
/// <param name="bDynamic"></param>
inline void SetDynamic ( const bool bDynamic ) { m_bDynamic = bDynamic ; }
inline bool dynamic ( ) const { return m_bDynamic ; }
/// <summary>
/// 当上下行内容相同时,是否合并
/// 此属性一般用于表格中的内容列
/// </summary>
/// <param name="bMerge"></param>
inline void SetMerge ( const bool bMerge ) { m_bMerge = bMerge ; }
inline bool merge ( ) const { return m_bMerge ; }
/// <summary>
/// 是否为转置单元格
/// </summary>
/// <param name="bTranRow"></param>
inline void SetTranRow ( bool bTranRow ) { m_bTranRow = bTranRow ; }
inline bool tranrow ( ) const { return m_bTranRow ; }
/// <summary>
/// 是否属于表组;【暂未使用】
/// </summary>
/// <param name="bFlag"></param>
inline void SetGroup ( bool bFlag ) { m_bGroup = bFlag ; }
inline bool group ( ) const { return m_bGroup ; }
/// <summary>
/// 折行标志 此单元格列是否为折行, 如果为true, 则折行显示
/// </summary>
/// <param name="bFlag"></param>
inline void SetBreakRow ( bool bFlag ) { m_bBreakRow = bFlag ; }
inline bool breakrow ( ) const { return m_bBreakRow ; }
/// <summary>
/// 此单元格列在折行时是否重复出现
/// 此属性一般用于表格中的列头
/// </summary>
/// <param name="bFlag"></param>
inline void SetRepeatShow ( bool bFlag ) { m_bRepeat = bFlag ; }
inline bool repeatshow ( ) const { return m_bRepeat ; }
/// <summary>
/// 单元格边距
/// </summary>
/// <param name="padding"></param>
inline void SetPadding ( const qreal & padding ) { m_qPadding = padding ; }
inline qreal padding ( ) const { return m_qPadding ; }
private :
int m_iRowIndex ; //第几行 从0行开始计
int m_iColumnIndex ; //第几列 从0列开始计
int m_iRowSpan ;
int m_iColSpan ;
bool m_bBackColor ; //考虑Table有背景色,
bool m_bDynamic ; //动态列
bool m_bTranRow ; //当表为转置表时使用; 说明转置时, 此单元格是否占一行, 还是按正常方式进行转置; 缺省false
bool m_bMerge ; //当相邻行两个相等时,是否合并,针对动态表
bool m_bGroup ; //当定义的是group时, cell的绑定数据是否为group中的循环值还是固定值; 缺省为固定值, false
bool m_bBreakRow ; //是否折行, 缺省false;
bool m_bRepeat ; //折行时,是否重复出现
qreal m_qPadding ; //单元格边距
CCSFrame : : FrameFlags m_Frame ; //边框设置 上边框、下边框、左边框、右边框
QPen m_FramePen ; //边框属性设置,颜色、宽度、样式 ;宽度是像素 大于等于1
QColor m_BackColor ; //单元格的背景色; 如果Table有背景色, 设置Table背景色, 如果此Cell有背景色, 优先Cell背景色
Qt : : Alignment m_Alignment ; //居左、居右、居中等 , 包含Paragraph时, 如果Cell未设置, 则把Paragraph的align给Cell
} ;
/// <summary>
/// 单元格元素类; 包含一个段落
/// </summary>
class Cell : public BaseItem
{
public :
Cell ( ) : BaseItem ( ) {
m_Format = new CellFormat ( ) ;
m_Type = classtype : : Cell ;
}
Cell ( const CellFormat & format ) : BaseItem ( )
{
m_Format = new CellFormat ( format ) ;
m_Type = classtype : : Cell ;
}
Cell ( const Paragraph & paras , const CellFormat & format )
{
m_Type = classtype : : Cell ;
m_Format = new CellFormat ( format ) ;
m_Paragraph = new Paragraph ( paras ) ;
}
Cell ( const QList < Text * > & texts , const CellFormat & format )
{
m_Type = classtype : : Cell ;
m_Format = new CellFormat ( format ) ;
ParagraphFormat f ;
m_Paragraph = new Paragraph ( texts , f ) ;
}
Cell ( const Text & text , const CellFormat & format )
{
m_Type = classtype : : Cell ;
m_Format = new CellFormat ( format ) ;
ParagraphFormat f ;
m_Paragraph = new Paragraph ( text , f ) ;
}
Cell ( const QString & content , const CellFormat & format )
{
m_Type = classtype : : Cell ;
m_Format = new CellFormat ( format ) ;
m_Paragraph = new Paragraph ( content ) ;
}
Cell ( const Paragraph & paras , int row , int column , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) ) : BaseItem ( )
{
m_Type = classtype : : Cell ;
m_Paragraph = new Paragraph ( paras ) ;
CellFormat * format = new CellFormat ( row , column , frames , alignment , rowspan , colspan ) ;
format - > SetBackColor ( color ) ;
this - > m_Format = format ;
}
// Cell(const Paragraph& paras,int row,int column,QPen pen,int frames=0,Qt::Alignment alignment=Qt::AlignCenter,
// int rowspan=1,int colspan = 1,QColor color = QColor(255,255,255,255)):BaseItem()
// {
// m_Paragraph =new Paragraph(paras);
// CellFormat *format = new CellFormat(frames,pen,alignment,color,rowspan,colspan,row,column);
// this->m_Format = format;
// m_Type = classtype::Cell;
// }
// Cell(QString& content,int row,int column,QPen pen,CCSFrame::FrameFlags frames=CCSFrame::FrameAll,Qt::Alignment alignment=Qt::AlignCenter,
// int rowspan=1,int colspan = 1,QColor color = QColor(255,255,255,255)):BaseItem()
// {
// m_Type = classtype::Cell;
// m_Paragraph =new Paragraph(content);
// CellFormat *format = new CellFormat(frames,pen,alignment,color,rowspan,colspan,row,column);
// this->m_Format = format;
// }
Cell ( QString & content , int row , int column , QFont font = QFont ( ) , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) ) : BaseItem ( )
{
m_Type = classtype : : Cell ;
Text text ( content , font ) ;
ParagraphFormat f = ParagraphFormat ( ) ;
m_Paragraph = new Paragraph ( text , f ) ;
CellFormat * format = new CellFormat ( row , column , frames , alignment , rowspan , colspan ) ;
format - > SetFramePen ( pen ) ;
format - > SetBackColor ( color ) ;
m_Format = format ;
}
Cell ( QList < Text * > & texts , int row , int column , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) ) : BaseItem ( )
{
m_Type = classtype : : Cell ;
ParagraphFormat f ;
m_Paragraph = new Paragraph ( texts , f ) ;
CellFormat * format = new CellFormat ( row , column , frames , alignment , rowspan , colspan ) ;
format - > SetFramePen ( pen ) ;
format - > SetBackColor ( color ) ;
m_Format = format ;
}
Cell ( const Text & text , int row , int column , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , qreal padding = 0 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) ) : BaseItem ( )
{
m_Type = classtype : : Cell ;
ParagraphFormat f ;
m_Paragraph = new Paragraph ( text , f ) ;
CellFormat * format = new CellFormat ( row , column , frames , alignment , rowspan , colspan ) ;
format - > SetPadding ( padding ) ;
format - > SetFramePen ( pen ) ;
format - > SetBackColor ( color ) ;
m_Format = format ;
}
// Cell(const Text& text,int row,int column,qreal padding,CCSFrame::FrameFlags frames=CCSFrame::FrameAll,Qt::Alignment alignment=Qt::AlignCenter,
// int rowspan=1,int colspan = 1,QColor color = QColor(255,255,255,255)):BaseItem()
// {
// ParagraphFormat f;
// m_Paragraph = new Paragraph(text,f);
// m_Format = new CellFormat(frames,QPen(),alignment,color,rowspan,colspan,row,column,padding);
// m_Type = classtype::Cell;
// }
Cell ( const Image & image , int row , int column , CCSFrame : : FrameFlags frames = CCSFrame : : FrameAll , Qt : : Alignment alignment = Qt : : AlignCenter ,
int rowspan = 1 , int colspan = 1 , qreal padding = 0 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) ) : BaseItem ( )
{
m_Type = classtype : : Cell ;
ParagraphFormat f ;
m_Paragraph = new Paragraph ( image , f ) ;
CellFormat * format = new CellFormat ( row , column , frames , alignment , rowspan , colspan ) ;
format - > SetFramePen ( pen ) ;
format - > SetBackColor ( color ) ;
m_Format = format ;
}
Cell ( const Cell & cell ) : BaseItem ( cell )
{
m_Paragraph = new Paragraph ( * ( cell . paragraph ( ) ) ) ;
CellFormat * pF = dynamic_cast < CellFormat * > ( cell . m_Format ) ;
m_Format = new CellFormat ( * pF ) ;
m_Type = classtype : : Cell ;
}
Cell & operator = ( const Cell & cell ) {
m_Paragraph = new Paragraph ( * ( cell . paragraph ( ) ) ) ;
CellFormat * pF = dynamic_cast < CellFormat * > ( cell . m_Format ) ;
if ( m_Format ! = nullptr ) { delete m_Format ; }
m_Format = new CellFormat ( * pF ) ;
m_Type = cell . m_Type ;
return * this ;
}
~ Cell ( )
{
delete m_Paragraph ;
}
void AddParagraph ( const Paragraph & para )
{
m_Paragraph = new Paragraph ( para ) ;
}
void AddText ( const Text & text )
{
//后续初始化时要填属性 format
m_Paragraph - > AddText ( text ) ;
}
void AddTexts ( QList < Text > & text )
{
m_Paragraph - > AddTexts ( text ) ;
}
/// <summary>
/// 获取包含的段落对象
/// </summary>
/// <returns></returns>
Paragraph * paragraph ( ) const
{
return m_Paragraph ;
}
inline int rowIndex ( ) const { return ( dynamic_cast < const CellFormat * > ( m_Format ) ) - > rowIndex ( ) ; }
inline int colIndex ( ) const { return ( dynamic_cast < const CellFormat * > ( m_Format ) ) - > colIndex ( ) ; }
inline void SetCellInfo ( int row , int column , QString content )
{
dynamic_cast < CellFormat * > ( m_Format ) - > SetRowColumn ( row , column ) ;
if ( m_Paragraph ! = nullptr )
{
QList < BaseItem * > item = m_Paragraph - > blocks ( ) ;
if ( item . count ( ) > 0 )
{
for ( int i = ( item . count ( ) - 1 ) ; i > 0 ; i - - )
{
delete item [ i ] ;
item . removeAt ( i ) ;
}
Text * text = static_cast < Text * > ( item [ 0 ] ) ;
text - > SetValue ( content ) ;
} else
{
m_Paragraph = new Paragraph ( content ) ;
}
//delete m_Paragraph;
}
}
inline void SetCellSapn ( int rowspan = 1 , int colspan = 1 )
{
CellFormat * tmpFormat = dynamic_cast < CellFormat * > ( m_Format ) ;
tmpFormat - > SetRowSpan ( rowspan ) ;
tmpFormat - > SetColSpan ( colspan ) ;
}
inline void SetDynamicCol ( bool bDynamic = true )
{
dynamic_cast < CellFormat * > ( m_Format ) - > SetDynamic ( bDynamic ) ;
}
inline bool dynamiccol ( ) { return ( dynamic_cast < const CellFormat * > ( m_Format ) ) - > dynamic ( ) ; }
inline void SetBreakRow ( bool bBreak = true )
{
dynamic_cast < CellFormat * > ( m_Format ) - > SetBreakRow ( bBreak ) ;
}
CellFormat * cellformat ( )
{
return dynamic_cast < CellFormat * > ( m_Format ) ;
}
private :
Paragraph * m_Paragraph ;
} ;
/// <summary>
/// 表格元素属性类
/// </summary>
class TableFormat : public BaseFormat
{
public :
TableFormat ( )
{
QMap < int , qreal > width ;
width . insert ( 0 , 100 ) ;
Init ( 1 , 1 , width ) ;
}
TableFormat ( int rownum , int colnum , int left , int right , QMap < int , qreal > width , CCSTableType : : TableBoardFlag board = CCSTableType : : Nothing , bool norecord = true ,
bool headerepeat = true , bool transpose = false ) : BaseFormat ( left , 0 , right , 0 )
{
Init ( rownum , colnum , width , " " , true , norecord , board , headerepeat , transpose , CCSTableType : : NoBreak ) ;
}
TableFormat ( int rownum , int colnum , QMap < int , qreal > width , int left = 0 , int right = 0 , CCSTableType : : TableBoardFlag board = CCSTableType : : Nothing , bool norecord = true ,
bool headerepeat = true , bool transpose = false ) : BaseFormat ( left , 0 , right , 0 )
{
Init ( rownum , colnum , width , " " , true , norecord , board , headerepeat , transpose , CCSTableType : : NoBreak ) ;
}
void Init ( int rownum , int colnum , QMap < int , qreal > width , QString DataseName = " " , bool shownoheader = true , bool norecord = true , CCSTableType : : TableBoardFlag board = CCSTableType : : Nothing ,
bool headerepeat = true , bool transpose = false , CCSTableType : : TableBreakFlag breaktype = CCSTableType : : TableBreak )
{
m_iRowCount = rownum ;
m_iColumnCount = colnum ;
m_bHeaderRepeat = headerepeat ;
QMap < int , qreal > : : iterator iter = width . begin ( ) ;
while ( iter ! = width . end ( ) )
{
m_mapColWidth . insert ( iter . key ( ) , iter . value ( ) ) ;
iter + + ;
}
m_strDatasetName = DataseName ;
//m_bSplitColumns = splitcolumns; //都放在 breaktype中说明
m_bTranspose = transpose ; //是否进行表的转置 缺省false
m_bShowNoRecord = norecord ; //当没有记录时,表是否显示,针对动态表;缺省显示列头 true
m_eBorderType = board ;
m_eBreakType = breaktype ;
m_bShowHeader = shownoheader ;
m_qRowHeight = 0 ;
m_qPadding = 0 ;
m_qSpacing = 0 ;
m_iHeaderRowCount = 1 ;
m_eWidthType = 0 ;
m_eTableType = 0 ;
m_qSpacing = 0 ;
}
TableFormat ( const TableFormat & tableF ) : BaseFormat ( tableF )
{
m_iRowCount = tableF . rowcount ( ) ; ;
m_iColumnCount = tableF . columncount ( ) ;
m_iHeaderRowCount = tableF . headerrowcount ( ) ;
m_eWidthType = 0 ;
m_eTableType = 0 ;
m_qSpacing = 0 ;
m_bHeaderRepeat = tableF . m_bHeaderRepeat ;
QMap < int , qreal > : : const_iterator iter = tableF . m_mapColWidth . begin ( ) ;
while ( iter ! = tableF . m_mapColWidth . end ( ) )
{
m_mapColWidth . insert ( iter . key ( ) , iter . value ( ) ) ;
iter + + ;
}
//m_bSplitColumns = tableF.m_bSplitColumns; //列过多时,是否折行;还是挤在一行中
m_bTranspose = tableF . m_bTranspose ; //是否进行表的转置 缺省false
m_bShowNoRecord = tableF . m_bShowNoRecord ; //当没有记录时,表是否显示,针对动态表;缺省显示列头 true
m_qRowHeight = tableF . m_qRowHeight ;
m_strDatasetName = tableF . m_strDatasetName ;
m_eBreakType = tableF . m_eBreakType ;
m_qPadding = tableF . m_qPadding ;
m_qSpacing = tableF . m_qSpacing ;
m_eBorderType = tableF . m_eBorderType ;
m_bShowHeader = tableF . m_bShowHeader ;
}
TableFormat & operator = ( const TableFormat & tableF )
{
m_iRowCount = tableF . rowcount ( ) ; ;
m_iColumnCount = tableF . columncount ( ) ;
m_iHeaderRowCount = tableF . headerrowcount ( ) ;
m_eWidthType = 0 ;
m_eTableType = 0 ;
m_qSpacing = 0 ;
m_bHeaderRepeat = tableF . m_bHeaderRepeat ;
QMap < int , qreal > : : iterator iter = tableF . colWidth ( ) . begin ( ) ;
while ( iter ! = tableF . colWidth ( ) . end ( ) )
{
m_mapColWidth . insert ( iter . key ( ) , iter . value ( ) ) ;
iter + + ;
}
//m_bSplitColumns = tableF.m_bSplitColumns; //列过多时,是否折行;还是挤在一行中
m_bTranspose = tableF . m_bTranspose ; //是否进行表的转置 缺省false
m_bShowNoRecord = tableF . m_bShowNoRecord ; //当没有记录时,表是否显示,针对动态表;缺省显示列头 true
m_qRowHeight = tableF . m_qRowHeight ;
m_strDatasetName = tableF . m_strDatasetName ;
m_eBreakType = tableF . m_eBreakType ;
m_qPadding = tableF . m_qPadding ;
m_qSpacing = tableF . m_qSpacing ;
m_eBorderType = tableF . m_eBorderType ;
m_bShowHeader = tableF . m_bShowHeader ;
return * this ;
}
/// <summary>
/// 表的行数。主要用于列头
/// </summary>
/// <param name="count"></param>
void SetRowCount ( const int & count ) { m_iRowCount = count ; }
/// <summary>
/// 表的列数
/// </summary>
/// <param name="count"></param>
void SetColumnCount ( const int & count ) { m_iColumnCount = count ; }
/// <summary>
/// 【未用】
/// </summary>
/// <param name="count"></param>
void SetHeaderRowCount ( const int & count ) { m_iHeaderRowCount = count ; }
/// <summary>
/// 【未用】
/// </summary>
/// <param name="eType"></param>
void SetTableType ( int eType ) {
m_eTableType = eType ;
}
int tabletype ( ) const { return m_eTableType ; }
int rowcount ( ) const { return m_iRowCount ; }
int columncount ( ) const { return m_iColumnCount ; }
int headerrowcount ( ) const { return m_iHeaderRowCount ; }
void SetSpacing ( const qreal & spacing ) { m_qSpacing = spacing ; }
qreal spacing ( ) const { return m_qSpacing ; }
/// <summary>
/// 列宽 ,按百分比给出
/// </summary>
/// <param name="colIndex"></param>
/// <param name="width"></param>
void SetColWidth ( int colIndex , int width ) { m_mapColWidth . insert ( colIndex , width ) ; }
void SetColWidth ( QMap < int , qreal > width )
{
m_mapColWidth . clear ( ) ;
QMap < int , qreal > : : iterator it ;
for ( it = width . begin ( ) ; it ! = width . end ( ) ; + + it ) {
m_mapColWidth . insert ( it . key ( ) , it . value ( ) ) ;
}
}
/// <summary>
/// 列宽 ,按百分比给出
/// </summary>
/// <returns></returns>
QMap < int , qreal > colWidth ( ) const { return m_mapColWidth ; }
/// <summary>
/// 表头是否显示
/// </summary>
/// <param name="bFlag"></param>
void SetShowHeader ( bool bFlag ) { m_bShowHeader = bFlag ; }
bool showheader ( ) const { return m_bShowHeader ; }
/// <summary>
/// 当没有记录时,表是否显示,针对动态表;缺省显示列头 true
/// </summary>
/// <param name="bNorecord"></param>
void SetShowNoRecord ( bool bNorecord ) { m_bShowNoRecord = bNorecord ; }
bool shownorecord ( ) const { return m_bShowNoRecord ; }
/// <summary>
/// 数据源中的对象名称
/// </summary>
/// <param name="name"></param>
void SetDatasetName ( const QString & name ) { m_strDatasetName = name ; }
QString datasetname ( ) const { return m_strDatasetName ; }
/// <summary>
/// 是否进行表的转置
/// </summary>
/// <param name="bFlag"></param>
void SetTranspose ( bool bFlag ) { m_bTranspose = bFlag ; }
bool transpose ( ) const { return m_bTranspose ; }
/// <summary>
/// 折行类型
/// </summary>
/// <param name="iType"></param>
void SetBreakType ( CCSTableType : : TableBreakFlag iType ) { m_eBreakType = iType ; }
CCSTableType : : TableBreakFlag breaktype ( ) const { return m_eBreakType ; }
/// <summary>
/// 表格边框类型
/// </summary>
/// <returns></returns>
CCSTableType : : TableBoardFlag tablebordertype ( ) const { return m_eBorderType ; }
void SetTableBorderType ( CCSTableType : : TableBoardFlag iType ) { m_eBorderType = iType ; }
inline void SetPadding ( const qreal & padding ) { m_qPadding = padding ; }
inline qreal padding ( ) const { return m_qPadding ; }
private :
int m_iRowCount ;
int m_iColumnCount ;
int m_iHeaderRowCount ;
int m_eWidthType ; //宽度类型,是按百分比还是按厘米;缺省按百分比
int m_eTableType ; //表类型 固定、动态、子表 目前应该没有用到
// int m_iMarginLeft; //左边距 在基类里体现
// int m_iMarginRight; //右边距
qreal m_qPadding ; //缺省都为0
qreal m_qSpacing ; //缺省都为0
qreal m_qRowHeight ; // 行高,先不考虑涉及到列头、表正文和表尾的行高;考虑当内容为图片的高度,如果没有设置,则为图片的原始高度
bool m_bHeaderRepeat ; //表头换页时是否重复, 缺省为true
//bool m_bSplitColumns; //列过多时,是否折行;还是挤在一行中
bool m_bTranspose ; //是否进行表的转置 缺省false
bool m_bShowNoRecord ; //当没有记录时,表是否显示,针对动态表;缺省显示列头 true
bool m_bShowHeader ; //是否显示表头
QString m_strDatasetName ; //数据源数据表的名称
CCSTableType : : TableBreakFlag m_eBreakType ; //折行类型,按记录折行还是按表折行
CCSTableType : : TableBoardFlag m_eBorderType ; //表格边框样式
QMap < int , qreal > m_mapColWidth ; //列宽
} ;
/// <summary>
/// 表格元素类 ,包含多个单元格
/// </summary>
class Table : public BaseItem
{
public : //QTextTableCellFormat
Table ( QString name = " " ) : BaseItem ( name )
{
m_Format = new TableFormat ( ) ;
m_Type = classtype : : Table ;
}
Table ( const TableFormat & format , QString name = " " ) : BaseItem ( name )
{
m_Format = new TableFormat ( format ) ;
m_Type = classtype : : Table ;
}
Table ( int row , int column , int left , int right , qreal height = 0 )
{
QMap < int , qreal > colWidth ;
qreal qCol = 100 / column ;
for ( int i = 0 ; i < column ; i + + )
{
colWidth . insert ( i , qCol ) ;
}
TableFormat * pTableF = new TableFormat ( row , column , left , right , colWidth ) ;
this - > m_Format = pTableF ;
m_Type = classtype : : Table ;
}
Table ( int row , int column , QMap < int , qreal > width , int left , int right , qreal height = 0 )
{
TableFormat * pTableF = new TableFormat ( row , column , left , right , width ) ;
this - > m_Format = pTableF ;
m_Type = classtype : : Table ;
}
//拷贝构造函数
Table ( const Table & table )
{
QMap < int , QMap < int , Cell * > > : : iterator it ;
for ( it = m_Cells . begin ( ) ; it ! = m_Cells . end ( ) ; + + it )
{
QMap < int , Cell * > : : iterator it1 ;
for ( it1 = it . value ( ) . begin ( ) ; it1 ! = it . value ( ) . end ( ) ; + + it1 )
{
delete it1 . value ( ) ;
}
}
QMap < int , QMap < int , Cell * > > : : const_iterator sourceit ;
for ( sourceit = table . m_Cells . begin ( ) ; sourceit ! = table . m_Cells . end ( ) ; + + sourceit )
{
QMap < int , Cell * > : : const_iterator sourceit1 ;
QMap < int , Cell * > tmpHash ;
for ( sourceit1 = sourceit . value ( ) . begin ( ) ; sourceit1 ! = sourceit . value ( ) . end ( ) ; + + sourceit1 )
{
Cell * cell = new Cell ( * sourceit1 . value ( ) ) ;
tmpHash . insert ( sourceit1 . key ( ) , cell ) ;
}
m_Cells . insert ( sourceit . key ( ) , tmpHash ) ;
}
TableFormat * pF = dynamic_cast < TableFormat * > ( table . m_Format ) ;
m_Format = new TableFormat ( * pF ) ;
m_Type = classtype : : Table ;
}
//赋值构造函数
Table & operator = ( const Table & table )
{
QMap < int , QMap < int , Cell * > > : : iterator it ;
for ( it = m_Cells . begin ( ) ; it ! = m_Cells . end ( ) ; + + it )
{
QMap < int , Cell * > : : iterator it1 ;
for ( it1 = it . value ( ) . begin ( ) ; it1 ! = it . value ( ) . end ( ) ; + + it1 )
{
delete it1 . value ( ) ;
}
}
m_Cells . clear ( ) ;
QMap < int , QMap < int , Cell * > > : : const_iterator sourceit ;
for ( sourceit = table . m_Cells . begin ( ) ; sourceit ! = table . m_Cells . end ( ) ; + + sourceit )
{
QMap < int , Cell * > : : const_iterator sourceit1 ;
QMap < int , Cell * > tmpHash ;
for ( sourceit1 = sourceit . value ( ) . begin ( ) ; sourceit1 ! = sourceit . value ( ) . end ( ) ; + + sourceit1 )
{
Cell * cell = new Cell ( * sourceit1 . value ( ) ) ;
tmpHash . insert ( sourceit1 . key ( ) , cell ) ;
}
m_Cells . insert ( sourceit . key ( ) , tmpHash ) ;
}
if ( m_Format ! = nullptr ) { delete m_Format ; }
TableFormat * pF = dynamic_cast < TableFormat * > ( table . m_Format ) ;
m_Format = new TableFormat ( * pF ) ;
m_Type = table . m_Type ;
return * this ;
}
virtual ~ Table ( )
{
for ( auto & items : m_Cells ) {
for ( auto item : items ) {
delete item ;
}
}
}
bool AddCell ( const Cell & cell )
{
Cell * pCell = new Cell ( cell ) ;
AddCell ( pCell ) ;
return true ;
}
bool AddCell ( int rownum , int colnum , Paragraph & para , CCSFrame : : FrameFlags frame , int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) )
{
ParagraphFormat * pF = dynamic_cast < ParagraphFormat * > ( para . Format ( ) ) ;
CellFormat cF ( rownum , colnum , frame , pF - > alignment ( ) , rowspan , colspan , 0 , false , false , false ) ;
cF . SetFramePen ( pen ) ;
cF . SetBackColor ( color ) ;
Cell * cell = new Cell ( para , cF ) ;
AddCell ( cell ) ;
return true ;
}
bool AddCell ( int rownum , int colnum , QString & content , QFont font = QFont ( ) , CCSFrame : : FrameFlags frame = CCSFrame : : FrameNothing , Qt : : Alignment align = Qt : : AlignCenter , int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) )
{
Cell * cell = new Cell ( content , rownum , colnum , font , frame , align , rowspan , colspan , pen , color ) ;
AddCell ( cell ) ;
return true ;
}
bool AddCell ( int rownum , int colnum , const Text & text , CCSFrame : : FrameFlags frame , Qt : : Alignment align = Qt : : AlignCenter , int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) )
{
Cell * cell = new Cell ( text , rownum , colnum , frame , align , rowspan , colspan , 0 , pen , color ) ;
AddCell ( cell ) ;
return true ;
}
bool AddCell ( int rownum , int colnum , const Image & image , CCSFrame : : FrameFlags frame , Qt : : Alignment align = Qt : : AlignCenter , int rowspan = 1 , int colspan = 1 , QPen pen = QPen ( ) , QColor color = QColor ( 255 , 255 , 255 , 255 ) )
{
Cell * cell = new Cell ( image , rownum , colnum , frame , align , rowspan , colspan , 0 , pen , color ) ;
AddCell ( cell ) ;
return true ;
}
bool AddCell ( int rownum , int colnum , const Cell & cell )
{
Cell * pCell = new Cell ( cell ) ;
pCell - > cellformat ( ) - > SetRowColumn ( rownum , colnum ) ;
AddCell ( pCell ) ;
return true ;
}
QMap < int , QMap < int , Cell * > > & cells ( ) { return m_Cells ; }
QMap < int , Cell * > & cell ( int i ) { return m_Cells [ i ] ; }
void SetColWidth ( int colIndex , int width )
{
dynamic_cast < TableFormat * > ( m_Format ) - > SetColWidth ( colIndex , width ) ;
}
qreal colwidth ( int colIndex )
{
return static_cast < TableFormat * > ( m_Format ) - > colWidth ( ) [ colIndex ] ;
}
protected :
bool AddCell ( Cell * cell )
{
int irowIndex = cell - > rowIndex ( ) ;
int icolIndex = cell - > colIndex ( ) ;
if ( m_Cells . contains ( icolIndex ) )
{
if ( m_Cells . value ( icolIndex ) . contains ( irowIndex ) )
{
m_Cells [ icolIndex ] . remove ( irowIndex ) ;
}
m_Cells [ icolIndex ] . insert ( irowIndex , cell ) ;
} else
{
QMap < int , Cell * > a ;
a . insert ( irowIndex , cell ) ;
// Cell* tmp = a[irowIndex];
m_Cells . insert ( icolIndex , a ) ;
}
return true ;
}
private :
//QList<QPair<int,Cell*>> m_Cells;
QMap < int , QMap < int , Cell * > > m_Cells ;
} ;
/// <summary>
///动态表格元素类;包含内容行定义、子表定义和总结行定义
/// </summary>
class TableDynamic : public Table
{
public :
TableDynamic ( QString name = " " ) : Table ( name )
{
m_bHasSubtable = false ;
m_iSubHeaderPos = 0 ;
m_Format = new TableFormat ( ) ;
m_Type = classtype : : TableDynamic ;
m_SubTable = nullptr ;
}
TableDynamic ( const TableFormat & format , QString name = " " ) : Table ( name )
{
m_bHasSubtable = false ;
m_iSubHeaderPos = 0 ;
m_Format = new TableFormat ( format ) ;
m_Type = classtype : : TableDynamic ;
m_SubTable = nullptr ;
}
//拷贝构造函数
TableDynamic ( const TableDynamic & table ) : Table ( table ) ,
m_bHasSubtable ( table . m_bHasSubtable ) ,
m_iSubHeaderPos ( table . m_iSubHeaderPos ) ,
m_strSubKeyField ( table . m_strSubKeyField )
{
if ( table . m_SubTable ) {
m_SubTable = new TableDynamic ( * ( table . m_SubTable ) ) ;
} else
{
m_SubTable = nullptr ;
}
for ( auto & item : m_ContentCells )
{
delete item ;
}
QMap < int , Cell * > : : const_iterator sourceit2 ;
for ( sourceit2 = table . m_ContentCells . begin ( ) ; sourceit2 ! = table . m_ContentCells . end ( ) ; + + sourceit2 )
{
Cell * cell = new Cell ( * sourceit2 . value ( ) ) ;
m_ContentCells . insert ( sourceit2 . key ( ) , cell ) ;
}
for ( auto & item : m_BottomCells )
{
for ( auto & item1 : item )
{
delete item1 ;
}
}
QMap < int , QMap < int , Cell * > > : : const_iterator sourceit ;
for ( sourceit = table . m_BottomCells . begin ( ) ; sourceit ! = table . m_BottomCells . end ( ) ; + + sourceit )
{
QMap < int , Cell * > : : const_iterator sourceit1 ;
QMap < int , Cell * > tmpHash ;
for ( sourceit1 = sourceit . value ( ) . begin ( ) ; sourceit1 ! = sourceit . value ( ) . end ( ) ; + + sourceit1 )
{
Cell * cell = new Cell ( * sourceit1 . value ( ) ) ;
tmpHash . insert ( sourceit1 . key ( ) , cell ) ;
}
m_BottomCells . insert ( sourceit . key ( ) , tmpHash ) ;
}
m_Type = classtype : : TableDynamic ;
}
//赋值构造函数
TableDynamic & operator = ( const TableDynamic & table )
{
if ( m_SubTable ! = nullptr ) { delete m_SubTable ; }
m_SubTable = new TableDynamic ( * ( table . m_SubTable ) ) ;
for ( auto & item : m_ContentCells )
{
delete item ;
}
QMap < int , Cell * > : : const_iterator sourceit2 ;
for ( sourceit2 = table . m_ContentCells . begin ( ) ; sourceit2 ! = table . m_ContentCells . end ( ) ; + + sourceit2 )
{
Cell * cell = new Cell ( * sourceit2 . value ( ) ) ;
m_ContentCells . insert ( sourceit2 . key ( ) , cell ) ;
}
for ( auto & item : m_BottomCells )
{
for ( auto & item1 : item )
{
delete item1 ;
}
}
QMap < int , QMap < int , Cell * > > : : const_iterator sourceit ;
for ( sourceit = table . m_BottomCells . begin ( ) ; sourceit ! = table . m_BottomCells . end ( ) ; + + sourceit )
{
QMap < int , Cell * > : : const_iterator sourceit1 ;
QMap < int , Cell * > tmpHash ;
for ( sourceit1 = sourceit . value ( ) . begin ( ) ; sourceit1 ! = sourceit . value ( ) . end ( ) ; + + sourceit1 )
{
Cell * cell = new Cell ( * sourceit1 . value ( ) ) ;
tmpHash . insert ( sourceit1 . key ( ) , cell ) ;
}
m_BottomCells . insert ( sourceit . key ( ) , tmpHash ) ;
}
Table : : operator = ( table ) ;
m_Type = table . m_Type ;
m_bHasSubtable = table . m_bHasSubtable ;
m_iSubHeaderPos = table . m_iSubHeaderPos ;
m_strSubKeyField = table . m_strSubKeyField ;
return * this ;
}
~ TableDynamic ( )
{
for ( auto & items : m_BottomCells ) {
for ( auto & item : items ) {
delete item ;
}
}
for ( auto item : m_ContentCells )
{
delete item ;
}
if ( m_SubTable ! = nullptr )
{
delete m_SubTable ;
}
}
bool AddHeaderCell ( const Cell & cell )
{
return AddCell ( cell ) ;
}
bool AddContentCell ( const Cell & cell )
{
Cell * pCell = new Cell ( cell ) ;
CellFormat * cellformat = static_cast < CellFormat * > ( cell . Format ( ) ) ;
int icolIndex = cellformat - > colIndex ( ) ;
if ( m_ContentCells . contains ( icolIndex ) )
{
m_ContentCells . remove ( icolIndex ) ;
}
m_ContentCells . insert ( icolIndex , pCell ) ;
return true ;
}
inline bool AddSubTable ( const TableDynamic & table , const QStringList & keyFields , int iSubHeaderPos = 0 )
{
TableDynamic * pDTable = new TableDynamic ( table ) ;
m_bHasSubtable = true ;
m_iSubHeaderPos = iSubHeaderPos ;
m_strSubKeyField = keyFields ;
m_SubTable = pDTable ;
return true ;
}
bool AddBottomCell ( const Cell & cell )
{
Cell * pCell = new Cell ( cell ) ;
int irowIndex = cell . rowIndex ( ) ;
int icolIndex = cell . colIndex ( ) ;
if ( m_BottomCells . contains ( icolIndex ) )
{
if ( m_BottomCells . value ( icolIndex ) . contains ( irowIndex ) )
{
m_BottomCells [ icolIndex ] . remove ( irowIndex ) ;
}
m_BottomCells [ icolIndex ] . insert ( irowIndex , pCell ) ;
} else
{
QMap < int , Cell * > hashCell ;
hashCell . insert ( irowIndex , pCell ) ;
m_BottomCells . insert ( icolIndex , hashCell ) ;
}
return true ;
}
void SetDatasetName ( const QString & name )
{
TableFormat * tableformat = static_cast < TableFormat * > ( this - > m_Format ) ;
tableformat - > SetDatasetName ( name ) ;
}
QMap < int , Cell * > dynamiccells ( ) const { return m_ContentCells ; }
bool HasSubtable ( ) const { return m_bHasSubtable ; }
/// <summary>
/// 父表和子表的关联字段
/// </summary>
/// <returns></returns>
QStringList subkeyfields ( ) const { return m_strSubKeyField ; }
/// <summary>
/// 子表的表头是否在顶级父表头中
/// </summary>
/// <returns></returns>
int SubHeaderPos ( ) const { return m_iSubHeaderPos ; }
TableDynamic * subTable ( ) const { return m_SubTable ; }
QMap < int , QMap < int , Cell * > > & bottomcells ( ) { return m_BottomCells ; }
private :
bool m_bHasSubtable ;
int m_iSubHeaderPos ; // =0 子表头 =1 在父表头
QStringList m_strSubKeyField ;
TableDynamic * m_SubTable ;
QMap < int , Cell * > m_ContentCells ;
QMap < int , QMap < int , Cell * > > m_BottomCells ;
} ;
/// <summary>
/// 表格组类,包含静态表、动态表
/// </summary>
class TableGroup : public Table
{
public :
TableGroup ( ) : Table ( )
{
m_Type = classtype : : TableGroup ;
}
TableGroup ( QStringList & tables , QStringList & keys ) : Table ( ) {
m_Type = classtype : : TableGroup ;
m_Keys = keys ;
m_Tables = tables ;
}
TableGroup ( const TableGroup & table ) : Table ( table ) , m_Keys ( table . m_Keys ) , m_Tables ( table . m_Tables )
{
m_Type = classtype : : TableGroup ;
for ( auto & item : table . m_Items )
{
//要判断是动态表还是group表还是普通表
classtype name = item - > elementType ( ) ;
if ( name = = classtype : : TableDynamic )
{
TableDynamic * td = new TableDynamic ( * ( TableDynamic * ) item ) ;
m_Items . append ( td ) ;
} else if ( name = = classtype : : TableGroup )
{
TableGroup * tg = new TableGroup ( * ( TableGroup * ) item ) ;
m_Items . append ( tg ) ;
}
else
{
Table * t = new Table ( * item ) ;
m_Items . append ( t ) ;
}
}
}
~ TableGroup ( )
{
for ( auto & item : m_Items )
{
delete item ;
}
}
bool AddItem ( const TableDynamic & table )
{
TableDynamic * pTable = new TableDynamic ( table ) ;
m_Items . append ( pTable ) ;
return true ;
}
bool AddItem ( const Table & table )
{
Table * pTable = new Table ( table ) ;
m_Items . append ( pTable ) ;
return true ;
}
bool 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_Items . append ( table ) ;
return true ;
}
bool 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_Items . append ( table ) ;
return true ;
}
bool AddItem ( const Text & item )
{
//转成Table
QList < Text * > listText ;
Text * pText = new Text ( item ) ;
listText . append ( pText ) ;
// 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_Items . append ( table ) ;
return true ;
}
bool AddItem ( const BlankLine & item )
{
// Text(const QString &content,const TextFormat &format, QString name=""):BaseItem(name)
TextFormat * format = dynamic_cast < TextFormat * > ( item . Format ( ) ) ;
Text pText ( " " , * format ) ;
Table * table = new Table ( 1 , 1 , 0 , 0 ) ;
table - > AddCell ( 0 , 0 , pText , CCSFrame : : FrameNothing ) ;
//把段落的左右边距赋值给表格;缺省 = 页的边距
m_Items . append ( table ) ;
return true ;
}
//
bool AddItem ( TableGroup & item )
{
TableGroup * pTable = new TableGroup ( item ) ;
m_Items . append ( pTable ) ;
return true ;
}
/// <summary>
/// 表组的同一关键字段【目前仅支持一个字段】
/// </summary>
/// <param name="key"></param>
void SetKeys ( const QStringList & key ) { m_Keys = key ; }
QStringList keys ( ) const { return m_Keys ; }
void SetTables ( const QStringList & name ) { m_Tables = name ; }
QStringList tables ( ) const { return m_Tables ; }
QList < Table * > items ( ) const { return m_Items ; }
private :
QStringList m_Keys ;
QStringList m_Tables ;
QList < Table * > m_Items ;
} ;
}
# endif // CCSTEMPLATEITEM_H