402 lines
12 KiB
C++
402 lines
12 KiB
C++
#include "ccsiteminterface.h"
|
||
#include "ccscell.h"
|
||
#include "common_types.h"
|
||
#include "ccsdatabind.h"
|
||
#include "QFont"
|
||
|
||
|
||
namespace CCS_Report{
|
||
|
||
CCSCell::CCSCell(int rownum,int colnum,QObject *parent):CCSItemInterface(new CCSCellPrivate(rownum,colnum),parent)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
CCSCell::CCSCell(QObject *parent):CCSItemInterface(new CCSCellPrivate,parent)
|
||
{
|
||
}
|
||
|
||
CCSCell::CCSCell(CCSCellPrivate *dd, QObject * parent)
|
||
:CCSItemInterface(dd, parent)
|
||
{
|
||
}
|
||
CCSCell::~CCSCell()
|
||
{
|
||
}
|
||
CCSBaseItemInterface *CCSCell::createInstance(QObject * parent) const
|
||
{
|
||
return new CCSCell(parent);
|
||
}
|
||
|
||
CCSBaseItemInterface *CCSCell::clone(bool withChildren, bool init) const
|
||
{
|
||
CCSCell * newCell = qobject_cast<CCSCell*>(itemClone());
|
||
//newCell->setReportCore(this->reportCore());
|
||
|
||
if (withChildren) {
|
||
foreach (CCSBaseItemInterface* item, findChildren<CCS_Report::CCSBaseItemInterface*>(QString(),Qt::FindDirectChildrenOnly)) {
|
||
if (item->parent() != this)
|
||
continue;
|
||
CCSBaseItemInterface * itemCopy = item->clone(true, false);
|
||
//itemCopy->setReportCore(item->reportCore());
|
||
itemCopy->setParent(newCell);
|
||
itemCopy->setObjectName(item->objectName());
|
||
}
|
||
}
|
||
|
||
return newCell;
|
||
}
|
||
|
||
void CCSCell::exeFunction(ReportFunPara& arg)
|
||
{
|
||
if (arg.strArgName.count()==0)
|
||
return;
|
||
|
||
foreach (CCS_Report::CCSBaseItemInterface* item, paragraphs()) {
|
||
item->exeFunction(arg);
|
||
}
|
||
|
||
}
|
||
void CCSCell::SetPostion(int row,int col)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_iRowindex = row;
|
||
d->m_iColindex = col;
|
||
}
|
||
|
||
int CCSCell::rowindex() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_iRowindex;
|
||
}
|
||
void CCSCell::SetRowindex(const int &index)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_iRowindex = index;
|
||
}
|
||
int CCSCell::colindex() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_iColindex;
|
||
}
|
||
void CCSCell::SetColindex(const int &index)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_iColindex = index;
|
||
}
|
||
|
||
int CCSCell::rowspan() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_iRowspan;
|
||
}
|
||
|
||
void CCSCell::SetRowspan(const int &span)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_iRowspan = span;
|
||
}
|
||
int CCSCell::colspan() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_iColspan;
|
||
}
|
||
void CCSCell::SetColspan(const int &span)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_iColspan = span;
|
||
}
|
||
bool CCSCell::dynamic() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_bDynamic;
|
||
}
|
||
void CCSCell::SetDynamic(const bool& dyn)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_bDynamic = dyn;
|
||
}
|
||
bool CCSCell::tranrow() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_bTranRow;
|
||
}
|
||
void CCSCell::SetTranrow(const bool& bFlag)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_bTranRow = bFlag;
|
||
}
|
||
|
||
bool CCSCell::group() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_bGroup;
|
||
}
|
||
void CCSCell::SetGroup(const bool& bFlag)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_bGroup = bFlag;
|
||
}
|
||
int CCSCell::cellframe() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_cellframe;
|
||
}
|
||
void CCSCell::SetCellFrame(const int& bFlag)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_cellframe = bFlag;
|
||
}
|
||
qreal CCSCell::padding() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return d->m_qPadding;
|
||
}
|
||
void CCSCell::SetPadding(const qreal& value)
|
||
{
|
||
Q_D(CCSCell);
|
||
d->m_qPadding = value;
|
||
}
|
||
|
||
CCS_Report::CCSBaseItemInterface* CCSCell::paragraph()
|
||
{
|
||
|
||
return findChild<CCS_Report::CCSBaseItemInterface*>(QString(),Qt::FindDirectChildrenOnly);
|
||
}
|
||
QList<CCS_Report::CCSBaseItemInterface*> CCSCell::paragraphs()
|
||
{
|
||
return findChildren<CCS_Report::CCSBaseItemInterface*>(QString(),Qt::FindDirectChildrenOnly);
|
||
}
|
||
|
||
CCSBaseItemInterface * CCSCell::itemClone() const
|
||
{
|
||
Q_D(const CCSCell);
|
||
return new CCSCell(new CCSCellPrivate(*d), parent());
|
||
// CCSCell* cell = new CCSCell();
|
||
// cell->setParent(this->parent());
|
||
// cell->setReportCore(this->reportCore());
|
||
// foreach (CCS_Report::CCSBaseItemInterface* item, findChildren<CCS_Report::CCSBaseItemInterface*>(QString(),Qt::FindDirectChildrenOnly)) {
|
||
// CCS_Report::CCSBaseItemInterface* hh = item->clone();
|
||
// hh->setParent(cell);
|
||
// }
|
||
// return cell;
|
||
// CCSBaseItemInterface * CCSCell::itemClone() const
|
||
//{
|
||
// Q_D(const CCSCell);
|
||
// return new CCSCell(new CCSCellPrivate(*d), parent());
|
||
//}
|
||
}
|
||
void CCSCell::SetValue(const QString &text,int iPos)
|
||
{
|
||
foreach (CCS_Report::CCSBaseItemInterface* item,findChildren<CCS_Report::CCSBaseItemInterface*>(QString(),Qt::FindDirectChildrenOnly))
|
||
{
|
||
item->SetValue(text);
|
||
}
|
||
}
|
||
QString CCSCell::GetFieldNameByTable(QString tablename)
|
||
{
|
||
//ReportFunPara para(FieldName);
|
||
ReportFunPara para("fieldname");
|
||
QList<QString> listpara;
|
||
if (!(tablename.isEmpty()))
|
||
listpara.append(tablename);
|
||
para.listPara = listpara;
|
||
exeFunction(para);
|
||
QString strField = para.listRtn.at(0);
|
||
return strField;
|
||
}
|
||
void CCSCell::FillDynamicCell(QList<QObject*> table, QMap<int, QMap<int, QPair<int, QString>>>& mapBindDataMergeInfo, QMap<int, bool> mapColumnMerge)
|
||
{
|
||
#ifdef Report_LOG
|
||
QLOG_INFO() <<QString("FillDynamicCell: table count:%1").arg(table.count());
|
||
#endif
|
||
|
||
//获取此cell中定义的表的字段名
|
||
QString strField = GetFieldNameByTable();
|
||
|
||
//根据字段获取此字段对应的数据
|
||
QList<QString> listBindData = CCS_Report::CCSDataBind::GetDataByFieldT(table, strField);
|
||
#ifdef Report_LOG
|
||
QLOG_INFO() <<QString("cell field: %1 ; count: %2").arg(strField,listBindData.count());
|
||
#endif
|
||
FillCell(strField,listBindData, mapBindDataMergeInfo, mapColumnMerge);
|
||
}
|
||
void CCSCell::FillDynamicCell(QList<QString> listValue, QMap<int, QMap<int, QPair<int, QString>>>& mapBindDataMergeInfo, QMap<int, bool> mapColumnMerge)
|
||
{
|
||
//获取此cell中定义的表的字段名
|
||
QString strField = GetFieldNameByTable();
|
||
#ifdef Report_LOG
|
||
QString str = "FillDynamicCell: table count:" + QString::number(listValue.count()) + " Field: " + strField;
|
||
QLOG_INFO() <<QString(str);
|
||
#endif
|
||
|
||
FillCell(strField, listValue, mapBindDataMergeInfo, mapColumnMerge);
|
||
|
||
}
|
||
void CCSCell::FillCell(QString strField, QList<QString> listBindData, QMap<int, QMap<int, QPair<int, QString>>>& mapBindDataMergeInfo, QMap<int, bool> mapColumnMerge)
|
||
{
|
||
#ifdef Report_LOG
|
||
QString str = "FillCell: data count:" + QString::number(listBindData.count()) + " Field: " + strField;
|
||
|
||
QLOG_INFO() << str;
|
||
#endif
|
||
QList<CCSCell*> listCell;
|
||
listCell.clear();
|
||
listCell.append(this);
|
||
|
||
int iColIndex = this->colindex();
|
||
QMap<int, QPair<int,QString>> mapBindData;
|
||
|
||
//判断当前的column是否为关键值列,且合并
|
||
if ((mapColumnMerge.contains(iColIndex)) && (mapColumnMerge[iColIndex] == true))
|
||
{
|
||
//查找前一列定义的关键值列和 合并标识
|
||
int iBeforeColIndex = iColIndex;
|
||
QMap<int, QPair<int, QString>> mapTempMergeInfo;
|
||
QMap<int, QMap<int, QPair<int, QString>>>::const_iterator iter;
|
||
for (iter = mapBindDataMergeInfo.cbegin(); iter != mapBindDataMergeInfo.cend(); ++iter)
|
||
{
|
||
if (iter.key() < iColIndex)
|
||
{
|
||
iBeforeColIndex = iter.key();
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
//qDebug() << "for ==number==" << iter.key() << " name==" << iter.value();
|
||
}
|
||
if (iBeforeColIndex < iColIndex)
|
||
{
|
||
mapTempMergeInfo = mapBindDataMergeInfo[iBeforeColIndex];
|
||
}
|
||
|
||
|
||
bool bEndFlag = false;
|
||
int iIndex = 0; //行索引
|
||
int iEqualCount = 1; //相同个数
|
||
QString strValue = listBindData.at(0);
|
||
|
||
if (mapTempMergeInfo.count() > 0)
|
||
{
|
||
iIndex = 0; //行索引
|
||
int iLastIndex = 1;
|
||
int iLastCount = 0;
|
||
int iTempIndex = 0;
|
||
QMap<int, QPair<int, QString>>::const_iterator iter;
|
||
for (iter = mapTempMergeInfo.cbegin(); iter != mapTempMergeInfo.cend(); ++iter)
|
||
{
|
||
bEndFlag = false;
|
||
iEqualCount = 1; //相同个数
|
||
iIndex = iTempIndex;
|
||
strValue = listBindData.at(iTempIndex );
|
||
iLastCount += iter.value().first;
|
||
for (iTempIndex = iLastIndex; iTempIndex < iLastCount; iTempIndex++)
|
||
{
|
||
if (strValue == listBindData.at(iTempIndex))
|
||
{
|
||
iEqualCount++;
|
||
bEndFlag =false;
|
||
}
|
||
else
|
||
{
|
||
QPair<int, QString> pairValue(iEqualCount,strValue);
|
||
mapBindData.insert(iIndex, pairValue);
|
||
iIndex = iTempIndex;
|
||
iEqualCount = 1;
|
||
bEndFlag = true;
|
||
strValue = listBindData.at(iTempIndex);
|
||
}
|
||
}
|
||
iLastIndex = iTempIndex +1;
|
||
QPair<int, QString> pairValue(iEqualCount, strValue);
|
||
mapBindData.insert(iIndex, pairValue);
|
||
|
||
}
|
||
mapBindDataMergeInfo.insert(iColIndex, mapBindData);
|
||
}
|
||
else
|
||
{
|
||
int i = 0;
|
||
for (i = 1; i < listBindData.count(); i++)
|
||
{
|
||
if (strValue == listBindData.at(i))
|
||
{
|
||
iEqualCount++;
|
||
bEndFlag =false;
|
||
}
|
||
else
|
||
{
|
||
QPair<int, QString> pairValue(iEqualCount,strValue);
|
||
mapBindData.insert(iIndex, pairValue);
|
||
iIndex = i;
|
||
iEqualCount = 1;
|
||
bEndFlag = true;
|
||
strValue = listBindData.at(i);
|
||
}
|
||
}
|
||
QPair<int, QString> pairValue(iEqualCount, strValue);
|
||
mapBindData.insert(iIndex, pairValue);
|
||
|
||
mapBindDataMergeInfo.insert(iColIndex, mapBindData);
|
||
|
||
}
|
||
|
||
|
||
QList<int> listRows = mapBindData.keys();
|
||
this->SetRowspan(mapBindData[listRows.at(0)].first);
|
||
//复制相同的Cell
|
||
for (int i = 1; i < listRows.count(); i++)
|
||
{
|
||
CCSCell* cell = qobject_cast<CCSCell*>(clone());
|
||
cell->SetRowindex(listRows.at(i));
|
||
cell->SetRowspan(mapBindData[listRows.at(i)].first);
|
||
listCell.append(cell);
|
||
}
|
||
//给cell中的字段赋值
|
||
ReportFunPara para;
|
||
para.strArgName = Set_Value;
|
||
QList<QPair<QString, QString>> listpairvalue;
|
||
for (int i = 0; i < listRows.count(); i++)
|
||
{
|
||
listpairvalue.clear();
|
||
QPair<QString, QString> pairvalue(strField, mapBindData[listRows.at(i)].second);
|
||
listpairvalue.append(pairvalue);
|
||
para.para = listpairvalue;
|
||
listCell.at(i)->exeFunction(para);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//复制相同的Cell
|
||
for (int i = 1; i < listBindData.count(); i++)
|
||
{
|
||
CCSCell* cell = qobject_cast<CCSCell*>(clone());
|
||
cell->SetRowindex(i);
|
||
listCell.append(cell);
|
||
}
|
||
//给cell中的字段赋值
|
||
ReportFunPara para;
|
||
para.strArgName = Set_Value;
|
||
if (listBindData.count() == listCell.count())
|
||
{
|
||
QList<QPair<QString, QString>> listpairvalue;
|
||
for (int i = 0; i < listBindData.count(); i++)
|
||
{
|
||
listpairvalue.clear();
|
||
QPair<QString, QString> pairvalue(strField, listBindData.at(i));
|
||
listpairvalue.append(pairvalue);
|
||
para.para = listpairvalue;
|
||
listCell.at(i)->exeFunction(para);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
void CCSCell::AddCellColumnIndex(int iAdd)
|
||
{
|
||
SetColindex(colindex() + iAdd);
|
||
}
|
||
}
|