74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
#include <QLabel>
|
|
#include <QGraphicsProxyWidget>
|
|
#include <QPushButton>
|
|
#include "diagramEditor/editRowData.h"
|
|
#include "diagramEditor/editItem.h"
|
|
#include "global.h"
|
|
|
|
|
|
EditRowData::EditRowData(QGraphicsItem *parent)
|
|
: EditBaseStruct(parent)
|
|
{
|
|
m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
|
|
|
|
// 添加按钮
|
|
//_btnAdd = new QPushButton("Add Item");
|
|
//QGraphicsProxyWidget* btnProxy = new QGraphicsProxyWidget(this);
|
|
//m_layout->addItem(btnProxy);
|
|
//m_layout->setAlignment(btnProxy,Qt::AlignCenter);
|
|
//btnProxy->setWidget(_btnAdd);
|
|
m_layout->addStretch();
|
|
m_layout->setSpacing(6);
|
|
|
|
//connect(_btnAdd, &QPushButton::clicked, this, &EditRowData::addItem);
|
|
setDataType(DiagramEditorStructType::rowData);
|
|
}
|
|
EditRowData::~EditRowData()
|
|
{
|
|
|
|
}
|
|
|
|
int EditRowData::addItems(int n)
|
|
{
|
|
if(n < 1)
|
|
return -1;
|
|
for(int i = 0;i < n; ++i)
|
|
{
|
|
EditItem* pItem = new EditItem(this);
|
|
pItem->setMaximumSize(g_dEditorItem_Width, g_dEditorItem_Height);
|
|
pItem->setMinimumSize(g_dEditorItem_Width, g_dEditorItem_Height);
|
|
_lstItem.append(pItem);
|
|
m_layout->insertItem(0,pItem);
|
|
m_layout->setStretchFactor(pItem,0);
|
|
}
|
|
int nWidth = calWidth();
|
|
setMinimumWidth(nWidth);
|
|
return nWidth;
|
|
}
|
|
|
|
void EditRowData::addItem()
|
|
{
|
|
EditItem* pItem = new EditItem(this);
|
|
pItem->setMaximumSize(g_dEditorItem_Width, g_dEditorItem_Height);
|
|
pItem->setMinimumSize(g_dEditorItem_Width, g_dEditorItem_Height);
|
|
|
|
int nWidth = calWidth();
|
|
setMinimumWidth(nWidth);
|
|
_lstItem.append(pItem);
|
|
m_layout->insertItem(m_layout->count()-1,pItem);
|
|
m_layout->setStretchFactor(pItem,1);
|
|
|
|
emit widthChanged(nWidth);
|
|
}
|
|
|
|
int EditRowData::calWidth()
|
|
{
|
|
int width = 0;
|
|
for(auto &pro:_lstItem)
|
|
{
|
|
width += pro->rect().width()+6;
|
|
}
|
|
//width += _btnAdd->width()+250; //100为add按钮的宽度
|
|
return width;
|
|
}
|