You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Include/iPlot/iPlotCurveT/ZxSubLegend.h

236 lines
5.8 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "Defines.h"
#include "ZxDrawHelper.h"
#include "ZxSubLegendItems.h"
class ZxObjBase;
class ZxObjCurveBase;
class ZxSubLegendTool;
class ZxSimpleTool;
class ZxSubAxisX;
class ZxSubAxisY;
// 图例
class I_PLOTCURVE_T_EXPORT ZxSubLegend
: public ZxRenderItem
{
Q_OBJECT
ZX_DECLARE_DYNAMIC
public:
ZxSubLegend();
ZxSubLegend(const QString& sName,
ZxSubAxisX *pAxisX,
ZxSubAxisY *pAxisY);
~ZxSubLegend();
// 图例位置
enum LegendPos
{
LP_LeftTop = 0, //左上
LP_LeftBottom, //左下
LP_RightTop, //右上
LP_RightBottom, //右下
LP_Free, //任意,包括用户拖拽移动
LP_Unknown
};
public:
virtual void init(const QString& sName,
ZxSubAxisX* pAxisX,
ZxSubAxisY* pAxisY);
virtual void initTools(ZxRenderView* pView);
ZxSimpleTool* getTool();
void setAxisX(ZxSubAxisX* pAxis);
void setAxisY(ZxSubAxisY* pAxis);
public slots:
// 子项管理
void slotObjItemAdded(ZxObjBase*);
void slotObjItemDeleted(ZxObjBase*);
void slotObjItemSelChanged(bool bSelected);
void slotItemLeftDoubleClicked(const QPointF& pt);
public:
// 左键双击
virtual void onLeftDoubleClick(const QPointF& pt);
public:
//////////////////////////////////
// 子项管理
void appendItem(ZxObjCurveBase* pCurve);
void removeItem(ZxObjCurveBase* pCurve);
// void removeItem(int nIndex);
void removeAllItems();
bool _addOrDel(ZxSubLegendItem* p, bool bAdd);
// 在组模式情况下,拆分名称
bool _dealwithGroup(ZxSubLegendItem* p, bool bAdd);
// 查找当前组
ZxSubLegendItems* _findOrCreateGroup(QString sNameP, bool bAdd);
// 序列化后重新关联,仅仅实现与Group的绑定
void bindItem(ZxSubLegendItem* p);
public:
//////////////////////////////////
// 布局管理
// 重置位置rtOuter是Plot的Inner
void resetPosBy(const QRectF& rtOuter);
// 布局
void onLayout();
// 根据子项字体和文字长度获取最小的长宽(不包括左侧)
QSizeF getAllItemWH();
// 如果当前bound小于w*h则重新调整bound
// 注意:内部不能调用 setBounds
bool adjustBoundInner(QRectF& bound);
// 如果当前bound越界则重新调整bound
// 注意:内部不能调用 setBounds
bool adjustBoundOuter(QRectF& bound);
// 获取高度间隔,分别:组之间、项之间(Parent, CHild)
void getIntersectH(float& fP, float& fC);
public:
virtual void paintBack(QPainter* painter, const ZxPaintParam& param);
virtual void onSerialize(ZxSerializer* ser);
virtual void onDeserialize(ZxSerializer* ser);
virtual void onLoadTempl(ZxSerializer* ser);
virtual void onSaveTempl(ZxSerializer* ser);
virtual void fillPtyPano(IxPtyPano* sheet);
public:
// 击中
virtual bool hitTest(const QPointF& pt);
// 具体击中实现的函数,单纯击中,不做选项的改变
// nOption用int是因为Rect类的击中选项不一致
// nOption为负值表示未击中此时返回false
virtual bool _runHitTest(const QPointF& pt, int& nOption, int& nSubIndex);
// 击中后ButtonUp后的处理
// pt1:鼠标Down点pt2鼠标Up点
virtual bool runMove(const QPointF& pt1, const QPointF& pt2);
public:
// 支持的分组
void setGroupNames(QStringList& list);
void appendGroupName(QString s);
// 位置
int getLegendPos();
void setLegendPos(int n);
// 边框
bool isFrameVisible(void) const;
void setFrameVisible(bool bIsShow);
QPen getFramePen(void);
void setFramePen(QPen o);
// 分组标题
QColor getGroupBackgrdClr();
void setGroupBackgrdClr(QColor clr);
int getGroupBackgrdClrAlpha();
void setGroupBackgrdClrAlpha(int nAlpha);
QFont getGroupTextFont();
void setGroupTextFont(QFont ft);
QColor getGroupTextClr();
void setGroupTextClr(QColor clr);
// 子项背景色,所有子项的通用
QColor getItemBackgrdClr();
void setItemBackgrdClr(QColor clr);
int getItemBackgrdClrAlpha();
void setItemBackgrdClrAlpha(int nAlpha);
QFont getItemTextFont();
void setItemTextFont(QFont ft);
QColor getItemTextClr();
void setItemTextClr(QColor clr);
// 边界控制
float getMarginInner();
void setMarginInner(float f);
float getMarginOuter();
void setMarginOuter(float f);
float getLeftWidth();
float getGroupHeight();
void setAxisObjectNameX(QString s);
void setAxisObjectNameY(QString s);
QString getAxisObjectNameX();
QString getAxisObjectNameY();
protected:
// 本身tool、坐标轴关联序列化后重新设置
ZxSubLegendTool* m_pTool;
ZxSubAxisX* m_pAxisX;
ZxSubAxisY* m_pAxisY;
// 分组信息
QVector<ZxSubLegendItems*> m_vecGroups; //序列化后重新设置
QStringList m_listGrouNames;
// 相对于全图Plot的位置
LegendPos m_oLdPos;
// 边框
bool m_bFrameVisible;
QPen m_oFramePen;
// 分组标题
QColor m_oGroupBackgrdClr; //背景色
QFont m_oGroupTextFont;
QColor m_oGroupTextClr;
// 子项背景色,所有子项的通用
QColor m_oItemBackgrdClr;
QColor m_oItemTextClr;
QFont m_oItemTextFont;
// 边界控制
float m_fMarginInner; //内部Margin
float m_fMarginOuter; //外部Margin
float m_fLeftWidth; //左侧符号宽度
float m_fGroupHeight;
float m_fRatio; //组间距/子项间距=3, 不参与序列化
QSizeF m_szChildText; //不参与序列化,临时
QString m_sAxisObjectNameX; //为了序列化
QString m_sAxisObjectNameY;
public:
// 选中标示,不需要序列化
RectPos m_oHitPos;
int m_nHitIndex;
};