移除souce属性

This commit is contained in:
2026-09-10 09:20:45 +08:00
parent 5f96e8d592
commit e9d601a3e8
13 changed files with 36 additions and 131 deletions
+7 -30
View File
@@ -262,7 +262,7 @@ void TestPrintWidget::on_addButton_pressed(const SourceType type)
pPicScene->clearSelection();
textItem = new PicTextItem(0, 0, type);
pPicScene->addItem(textItem);
textItem->setSource(QString(""));
textItem->setText("");
QList<QGraphicsItem *> items = pPicScene->items();
if(pPicScene->items().count()>1){
@@ -294,7 +294,7 @@ void TestPrintWidget::onEditItemDone()
continue;
}
pTextItem->setSource(content);
pTextItem->setText(content);
if(pPicScene->items().count() == 1) {
pTextItem->setPos(pTextItem->clampItemPos(pTextItem->scenePos()));
@@ -330,7 +330,7 @@ void TestPrintWidget::getShowSelectItemText()
// 对于文本item,将它的文本显示到编辑框
if(lastSelectedTxtItem->sourceType() == SourceType::TEXT) {
ui.m_LineEdit->setEnabled(true);
m_LineEdit->setText(lastSelectedTxtItem->source().toString());
m_LineEdit->setText(lastSelectedTxtItem->text());
}
// pViewer->centerOn(lastSelectedTxtItem);
@@ -512,7 +512,6 @@ bool TestPrintWidget::cacheSelectedLayerForPaste(PicTextItem *srcItem)
if (!srcItem) return false;
m_copiedSourceType = srcItem->sourceType();
m_copiedSourceValue = srcItem->source();
m_copiedHtml = srcItem->toHtml();
m_copiedSpecialConditions = srcItem->SpecialConditions;
m_copiedCatchCnt1StartValue = srcItem->CatchCnt1StartValue;
@@ -549,33 +548,11 @@ void TestPrintWidget::pasteCopiedLayer()
pPicScene->clearSelection();
pPicScene->addItem(newItem);
newItem->setHtml(m_copiedHtml);
if (m_copiedSourceType != SourceType::UNKNOWN) {
newItem->setAttrs(m_copiedAttrs);
}
newItem->setHtml(m_copiedHtml);
// 某些类型需要显式恢复 source 才会正确重绘(如条码/二维码、图片、文本)
if (m_copiedSourceType == SourceType::TEXT ||
m_copiedSourceType == SourceType::IMAGE ||
m_copiedSourceType == SourceType::CODE) {
newItem->setSource(m_copiedSourceValue);
}
// 计数器单独恢复类型和位数,避免仅靠 attrs 导致内容不完整
if (m_copiedSourceType == SourceType::COUNTER) {
auto dstCounter = dynamic_cast<PicCounterItem*>(newItem);
if (dstCounter) {
dstCounter->setCustomFont(m_copiedCounterFontFamily);
dstCounter->setLetterSpace(m_copiedCounterLetterSpace);
int displayNum = static_cast<COUNTER_TYPE>(m_copiedCounterType) == COUNTER_TYPE_1 ? m_printSettingModel.cnt1Settings.currValue : m_printSettingModel.cnt2Settings.currValue;
dstCounter->setCounter(static_cast<COUNTER_TYPE>(m_copiedCounterType), m_copiedCounterDigitalNum, displayNum);
}
}
newItem->SpecialConditions = m_copiedSpecialConditions;
newItem->CatchCnt1StartValue = m_copiedCatchCnt1StartValue;
newItem->CatchCnt1CurrValue = m_copiedCatchCnt1CurrValue;
auto rect = newItem->boundingRect();
// 每次粘贴会往右偏移一次
@@ -706,10 +683,10 @@ void TestPrintWidget::onImageLoaderAccepted()
QString htmlImg = QString("<img src=\"%1\" />").arg(imgPath);
pPicScene->clearSelection();
PicTextItem* item = new PicImageItem(0, 0, SourceType::IMAGE);
PicImageItem* item = new PicImageItem(0, 0, SourceType::IMAGE);
item->setHtml(htmlImg);
pPicScene->addItem(item);
item->setSource(imgPath);
item->setImagePath(imgPath);
auto boundingRect = pPicScene->itemsBoundingRect();
int y = sysPara->para.canvasHeight - item->boundingRect().height();
item->setPos(x_item, y);