移除souce属性
This commit is contained in:
@@ -20,17 +20,6 @@ PicCounterItem::PicCounterItem(QGraphicsItem *parent, QGraphicsScene *scene, con
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicCounterItem::source()
|
|
||||||
{
|
|
||||||
return PicTextItem::source();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicCounterItem::setSource(QVariant var)
|
|
||||||
{
|
|
||||||
PicTextItem::setSource(var);
|
|
||||||
setCounter(counterType(), digitalNum(), m_displayNum);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicCounterItem::setCounter(COUNTER_TYPE type, int digitalNum, int displayNum)
|
void PicCounterItem::setCounter(COUNTER_TYPE type, int digitalNum, int displayNum)
|
||||||
{
|
{
|
||||||
if(type != COUNTER_TYPE_1 && type != COUNTER_TYPE_2) {
|
if(type != COUNTER_TYPE_1 && type != COUNTER_TYPE_2) {
|
||||||
@@ -155,5 +144,5 @@ void PicCounterItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
|||||||
|
|
||||||
void PicCounterItem::letterSpaceChanged()
|
void PicCounterItem::letterSpaceChanged()
|
||||||
{
|
{
|
||||||
setSource(source());
|
setCounter(counterType(), digitalNum(), m_displayNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ class PicCounterItem : public PicTextItem
|
|||||||
public:
|
public:
|
||||||
explicit PicCounterItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::COUNTER);
|
explicit PicCounterItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::COUNTER);
|
||||||
|
|
||||||
virtual QVariant source() override;
|
|
||||||
virtual void setSource(QVariant var) override;
|
|
||||||
|
|
||||||
void setCounter(COUNTER_TYPE type, int digitalNum, int displayNum);
|
void setCounter(COUNTER_TYPE type, int digitalNum, int displayNum);
|
||||||
|
|
||||||
COUNTER_TYPE counterType() const { return m_counterType; }
|
COUNTER_TYPE counterType() const { return m_counterType; }
|
||||||
|
|||||||
+2
-25
@@ -86,30 +86,6 @@ PicDateItem::PicDateItem(QGraphicsItem *parent, QGraphicsScene *scene, const Sou
|
|||||||
// m_timer.start();
|
// m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicDateItem::source()
|
|
||||||
{
|
|
||||||
return m_model.datetimePattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicDateItem::setSource(QVariant var)
|
|
||||||
{
|
|
||||||
m_model.datetimePattern = var.toString();
|
|
||||||
if(m_model.datetimePattern.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 重新计算最长显示尺寸(以防 font()/letterSpace 改变时未重算)
|
|
||||||
m_maxDateTimeStr = generateMaxDateTimeString(m_model, font());
|
|
||||||
if (m_maxDateTimeStr.isEmpty()) {
|
|
||||||
m_maxSize = QSize();
|
|
||||||
} else {
|
|
||||||
QFontMetrics fm(font());
|
|
||||||
m_maxSize = QSize(fm.horizontalAdvance(m_maxDateTimeStr), fm.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currDateTimeStr = ItemUtils::generateTxtFromDateItemModel(m_model, QDateTime::currentDateTime());
|
|
||||||
applyModify();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicDateItem::setModel(DateItemModel model)
|
void PicDateItem::setModel(DateItemModel model)
|
||||||
{
|
{
|
||||||
m_model = std::move(model);
|
m_model = std::move(model);
|
||||||
@@ -134,7 +110,8 @@ void PicDateItem::setModel(DateItemModel model)
|
|||||||
|
|
||||||
qDebug() << "PicDateItem::setModel timing(us): generate=" << genUs << ", fm=" << fmUs << ", total=" << (genUs + fmUs);
|
qDebug() << "PicDateItem::setModel timing(us): generate=" << genUs << ", fm=" << fmUs << ", total=" << (genUs + fmUs);
|
||||||
|
|
||||||
setSource(m_model.datetimePattern);
|
m_currDateTimeStr = ItemUtils::generateTxtFromDateItemModel(m_model, QDateTime::currentDateTime());
|
||||||
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
const DateItemModel& PicDateItem::model() const
|
const DateItemModel& PicDateItem::model() const
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ public:
|
|||||||
PicDateItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::DATETIME);
|
PicDateItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::DATETIME);
|
||||||
virtual ~PicDateItem() {}
|
virtual ~PicDateItem() {}
|
||||||
|
|
||||||
virtual QVariant source() override;
|
|
||||||
virtual void setSource(QVariant var) override;
|
|
||||||
|
|
||||||
void setModel(DateItemModel model);
|
void setModel(DateItemModel model);
|
||||||
|
|
||||||
const DateItemModel& model() const;
|
const DateItemModel& model() const;
|
||||||
|
|||||||
@@ -6,19 +6,19 @@ PicImageItem::PicImageItem(QGraphicsItem *parent, QGraphicsScene *scene, const S
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicImageItem::source()
|
QString PicImageItem::imagePath()
|
||||||
{
|
{
|
||||||
return m_imgPath;
|
return m_imgPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicImageItem::setSource(QVariant var)
|
void PicImageItem::setImagePath(const QString& path)
|
||||||
{
|
{
|
||||||
QImage img(var.toString());
|
QImage img(path);
|
||||||
if(img.isNull())
|
if(img.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_img = img;
|
m_img = img;
|
||||||
m_imgPath = var.toString();
|
m_imgPath = path;
|
||||||
applyModify();
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,12 +29,12 @@ QImage PicImageItem::itemImage()
|
|||||||
|
|
||||||
void PicImageItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
void PicImageItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
||||||
{
|
{
|
||||||
setSource(attrs.value("source").toString());
|
setImagePath(attrs.value("source").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicImageItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
void PicImageItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
||||||
{
|
{
|
||||||
attrs.append("source", source().toString());
|
attrs.append("source", imagePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicImageItem::colorReversalChanged()
|
void PicImageItem::colorReversalChanged()
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ class PicImageItem : public PicTextItem
|
|||||||
public:
|
public:
|
||||||
explicit PicImageItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::IMAGE);
|
explicit PicImageItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::IMAGE);
|
||||||
|
|
||||||
virtual QVariant source() override;
|
QString imagePath();
|
||||||
virtual void setSource(QVariant var) override;
|
void setImagePath(const QString& path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QImage itemImage() override;
|
virtual QImage itemImage() override;
|
||||||
|
|||||||
@@ -14,20 +14,6 @@ PicScheduleShiftItem::PicScheduleShiftItem(QGraphicsItem *parent, QGraphicsScene
|
|||||||
// m_updateTimer.start();
|
// m_updateTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicScheduleShiftItem::source()
|
|
||||||
{
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicScheduleShiftItem::setSource(QVariant var)
|
|
||||||
{
|
|
||||||
// 重新计算基于当前字体的最大名称像素宽度
|
|
||||||
m_maxSize = calcMaxSize();
|
|
||||||
|
|
||||||
m_currScheduleName = findScheduleName(QTime::currentTime());
|
|
||||||
applyModify();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QVector<ScheduleModel>& PicScheduleShiftItem::schedules() const
|
const QVector<ScheduleModel>& PicScheduleShiftItem::schedules() const
|
||||||
{
|
{
|
||||||
return m_schedules;
|
return m_schedules;
|
||||||
|
|||||||
@@ -24,10 +24,8 @@ class PicScheduleShiftItem : public PicTextItem
|
|||||||
public:
|
public:
|
||||||
PicScheduleShiftItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::SCHEDULE_SHIFT);
|
PicScheduleShiftItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::SCHEDULE_SHIFT);
|
||||||
|
|
||||||
virtual QVariant source();
|
|
||||||
virtual void setSource(QVariant var);
|
|
||||||
|
|
||||||
const QVector<ScheduleModel>& schedules() const;
|
const QVector<ScheduleModel>& schedules() const;
|
||||||
|
|
||||||
void setSchedules(QVector<ScheduleModel> schedules);
|
void setSchedules(QVector<ScheduleModel> schedules);
|
||||||
|
|
||||||
bool updateScheduleName();
|
bool updateScheduleName();
|
||||||
|
|||||||
@@ -24,16 +24,6 @@ PicCodeItem::~PicCodeItem()
|
|||||||
m_dateVarTimer.stop();
|
m_dateVarTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicCodeItem::source()
|
|
||||||
{
|
|
||||||
return m_currCodeTxt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicCodeItem::setSource(QVariant var)
|
|
||||||
{
|
|
||||||
applyModify();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PicCodeItem::setBarcodeViewModel(const BarcodeViewModel &vm)
|
void PicCodeItem::setBarcodeViewModel(const BarcodeViewModel &vm)
|
||||||
{
|
{
|
||||||
m_vm = vm;
|
m_vm = vm;
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ public:
|
|||||||
const SourceType type = SourceType::CODE);
|
const SourceType type = SourceType::CODE);
|
||||||
virtual ~PicCodeItem();
|
virtual ~PicCodeItem();
|
||||||
|
|
||||||
virtual QVariant source() override;
|
|
||||||
virtual void setSource(QVariant var) override;
|
|
||||||
|
|
||||||
void setBarcodeViewModel(const BarcodeViewModel& vm);
|
void setBarcodeViewModel(const BarcodeViewModel& vm);
|
||||||
BarcodeViewModel barcodeViewModel();
|
BarcodeViewModel barcodeViewModel();
|
||||||
|
|
||||||
|
|||||||
+11
-17
@@ -34,11 +34,6 @@ PicTextItem::~PicTextItem()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PicTextItem::source()
|
|
||||||
{
|
|
||||||
return m_source;
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage PicTextItem::applyImgeTranslation(QImage img)
|
QImage PicTextItem::applyImgeTranslation(QImage img)
|
||||||
{
|
{
|
||||||
auto scaledWidth = boldMultiple() * img.width();
|
auto scaledWidth = boldMultiple() * img.width();
|
||||||
@@ -92,13 +87,9 @@ QImage PicTextItem::applyImgeTranslation(QImage img)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicTextItem::setSource(QVariant var)
|
void PicTextItem::setText(const QString& txt)
|
||||||
{
|
{
|
||||||
m_source = var;
|
m_source = txt;
|
||||||
|
|
||||||
if(SourceType::TEXT != sourceType())
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_untransImage = strToImage(m_source.toString());
|
m_untransImage = strToImage(m_source.toString());
|
||||||
applyModify();
|
applyModify();
|
||||||
}
|
}
|
||||||
@@ -125,7 +116,9 @@ void PicTextItem::setCustomFont(QString name)
|
|||||||
newFont.setLetterSpacing(QFont::AbsoluteSpacing, letterSpace());
|
newFont.setLetterSpacing(QFont::AbsoluteSpacing, letterSpace());
|
||||||
newFont.setStyleStrategy(QFont::NoAntialias);
|
newFont.setStyleStrategy(QFont::NoAntialias);
|
||||||
setFont(newFont);
|
setFont(newFont);
|
||||||
setSource(source());
|
|
||||||
|
m_untransImage = strToImage(m_source.toString());
|
||||||
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PicTextItem::letterSpace()
|
int PicTextItem::letterSpace()
|
||||||
@@ -366,23 +359,24 @@ QImage PicTextItem::itemImage()
|
|||||||
|
|
||||||
void PicTextItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
void PicTextItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
||||||
{
|
{
|
||||||
auto sourceVar = attrs.value("source").toString();
|
auto txt = attrs.value("source").toString();
|
||||||
PicTextItem::setSource(sourceVar);
|
setText(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicTextItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
void PicTextItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
||||||
{
|
{
|
||||||
attrs.append("source", PicTextItem::source().toString());
|
attrs.append("source", text());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicTextItem::colorReversalChanged()
|
void PicTextItem::colorReversalChanged()
|
||||||
{
|
{
|
||||||
setSource(source());
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PicTextItem::letterSpaceChanged()
|
void PicTextItem::letterSpaceChanged()
|
||||||
{
|
{
|
||||||
setSource(source());
|
m_untransImage = strToImage(m_source.toString());
|
||||||
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage PicTextItem::strToImage(const QString &str)
|
QImage PicTextItem::strToImage(const QString &str)
|
||||||
|
|||||||
+6
-3
@@ -93,9 +93,6 @@ public:
|
|||||||
|
|
||||||
SourceType sourceType() const { return m_sourceType; }
|
SourceType sourceType() const { return m_sourceType; }
|
||||||
|
|
||||||
virtual QVariant source();
|
|
||||||
virtual void setSource(QVariant var);
|
|
||||||
|
|
||||||
// 粗体,即水平拉伸倍率, 1倍率为保持原样
|
// 粗体,即水平拉伸倍率, 1倍率为保持原样
|
||||||
int boldMultiple() { return m_boldMultiple; }
|
int boldMultiple() { return m_boldMultiple; }
|
||||||
int setBoldMultiple(int multiple);
|
int setBoldMultiple(int multiple);
|
||||||
@@ -163,6 +160,12 @@ public:
|
|||||||
|
|
||||||
QPointF clampItemPos(const QPointF& p);
|
QPointF clampItemPos(const QPointF& p);
|
||||||
|
|
||||||
|
QString text() {
|
||||||
|
return m_source.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setText(const QString& txt);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void lostFocus(PicTextItem *item);
|
void lostFocus(PicTextItem *item);
|
||||||
void selectedChange(QGraphicsItem *item);
|
void selectedChange(QGraphicsItem *item);
|
||||||
|
|||||||
+7
-30
@@ -262,7 +262,7 @@ void TestPrintWidget::on_addButton_pressed(const SourceType type)
|
|||||||
pPicScene->clearSelection();
|
pPicScene->clearSelection();
|
||||||
textItem = new PicTextItem(0, 0, type);
|
textItem = new PicTextItem(0, 0, type);
|
||||||
pPicScene->addItem(textItem);
|
pPicScene->addItem(textItem);
|
||||||
textItem->setSource(QString(""));
|
textItem->setText("");
|
||||||
|
|
||||||
QList<QGraphicsItem *> items = pPicScene->items();
|
QList<QGraphicsItem *> items = pPicScene->items();
|
||||||
if(pPicScene->items().count()>1){
|
if(pPicScene->items().count()>1){
|
||||||
@@ -294,7 +294,7 @@ void TestPrintWidget::onEditItemDone()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTextItem->setSource(content);
|
pTextItem->setText(content);
|
||||||
|
|
||||||
if(pPicScene->items().count() == 1) {
|
if(pPicScene->items().count() == 1) {
|
||||||
pTextItem->setPos(pTextItem->clampItemPos(pTextItem->scenePos()));
|
pTextItem->setPos(pTextItem->clampItemPos(pTextItem->scenePos()));
|
||||||
@@ -330,7 +330,7 @@ void TestPrintWidget::getShowSelectItemText()
|
|||||||
// 对于文本item,将它的文本显示到编辑框
|
// 对于文本item,将它的文本显示到编辑框
|
||||||
if(lastSelectedTxtItem->sourceType() == SourceType::TEXT) {
|
if(lastSelectedTxtItem->sourceType() == SourceType::TEXT) {
|
||||||
ui.m_LineEdit->setEnabled(true);
|
ui.m_LineEdit->setEnabled(true);
|
||||||
m_LineEdit->setText(lastSelectedTxtItem->source().toString());
|
m_LineEdit->setText(lastSelectedTxtItem->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pViewer->centerOn(lastSelectedTxtItem);
|
// pViewer->centerOn(lastSelectedTxtItem);
|
||||||
@@ -512,7 +512,6 @@ bool TestPrintWidget::cacheSelectedLayerForPaste(PicTextItem *srcItem)
|
|||||||
if (!srcItem) return false;
|
if (!srcItem) return false;
|
||||||
|
|
||||||
m_copiedSourceType = srcItem->sourceType();
|
m_copiedSourceType = srcItem->sourceType();
|
||||||
m_copiedSourceValue = srcItem->source();
|
|
||||||
m_copiedHtml = srcItem->toHtml();
|
m_copiedHtml = srcItem->toHtml();
|
||||||
m_copiedSpecialConditions = srcItem->SpecialConditions;
|
m_copiedSpecialConditions = srcItem->SpecialConditions;
|
||||||
m_copiedCatchCnt1StartValue = srcItem->CatchCnt1StartValue;
|
m_copiedCatchCnt1StartValue = srcItem->CatchCnt1StartValue;
|
||||||
@@ -549,33 +548,11 @@ void TestPrintWidget::pasteCopiedLayer()
|
|||||||
pPicScene->clearSelection();
|
pPicScene->clearSelection();
|
||||||
pPicScene->addItem(newItem);
|
pPicScene->addItem(newItem);
|
||||||
|
|
||||||
|
newItem->setHtml(m_copiedHtml);
|
||||||
|
|
||||||
if (m_copiedSourceType != SourceType::UNKNOWN) {
|
if (m_copiedSourceType != SourceType::UNKNOWN) {
|
||||||
newItem->setAttrs(m_copiedAttrs);
|
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();
|
auto rect = newItem->boundingRect();
|
||||||
// 每次粘贴会往右偏移一次
|
// 每次粘贴会往右偏移一次
|
||||||
@@ -706,10 +683,10 @@ void TestPrintWidget::onImageLoaderAccepted()
|
|||||||
QString htmlImg = QString("<img src=\"%1\" />").arg(imgPath);
|
QString htmlImg = QString("<img src=\"%1\" />").arg(imgPath);
|
||||||
|
|
||||||
pPicScene->clearSelection();
|
pPicScene->clearSelection();
|
||||||
PicTextItem* item = new PicImageItem(0, 0, SourceType::IMAGE);
|
PicImageItem* item = new PicImageItem(0, 0, SourceType::IMAGE);
|
||||||
item->setHtml(htmlImg);
|
item->setHtml(htmlImg);
|
||||||
pPicScene->addItem(item);
|
pPicScene->addItem(item);
|
||||||
item->setSource(imgPath);
|
item->setImagePath(imgPath);
|
||||||
auto boundingRect = pPicScene->itemsBoundingRect();
|
auto boundingRect = pPicScene->itemsBoundingRect();
|
||||||
int y = sysPara->para.canvasHeight - item->boundingRect().height();
|
int y = sysPara->para.canvasHeight - item->boundingRect().height();
|
||||||
item->setPos(x_item, y);
|
item->setPos(x_item, y);
|
||||||
|
|||||||
Reference in New Issue
Block a user