修复状态机的部分异常、计数器编辑与预览更新、修复时间、轮班图元的高度多一行的问题
This commit is contained in:
@@ -8,9 +8,6 @@ CounterEditor::CounterEditor(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->checkBoxResetCnt2CurrValue, &QCheckBox::toggled,
|
||||
this, &CounterEditor::onEditCurrValueToggled);
|
||||
|
||||
connect(ui->cbBoxCounterType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CounterEditor::onCounterTypeChanged);
|
||||
connect(ui->cbBoxDigitalNum, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CounterEditor::onDigitalNumChanged);
|
||||
|
||||
@@ -20,9 +17,6 @@ CounterEditor::CounterEditor(QWidget *parent) :
|
||||
connect(ui->spinBoxCnt2StepValue, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int) {fetchCounterConfigFromView();} );
|
||||
connect(ui->spinBoxCnt2CurrValue, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int) {fetchCounterConfigFromView();} );
|
||||
|
||||
connect(ui->checkBoxResetCnt2CurrValue, &QCheckBox::clicked, this, [this](bool) {fetchCounterConfigFromView();} );
|
||||
connect(ui->eleCNT2IncEn, &QCheckBox::clicked, this, [this](bool) {fetchCounterConfigFromView();} );
|
||||
|
||||
setViewModel(m_vm);
|
||||
}
|
||||
|
||||
@@ -63,15 +57,6 @@ void CounterEditor::setViewModel(CounterEditorVM vm)
|
||||
ui->spinBoxCnt2CurrValue->setValue(cnt.currValue);
|
||||
ui->spinBoxCnt2CurrValue->blockSignals(b);
|
||||
|
||||
b = ui->checkBoxResetCnt2CurrValue->blockSignals(true);
|
||||
ui->checkBoxResetCnt2CurrValue->setChecked(cnt.editCurrValue);
|
||||
ui->checkBoxResetCnt2CurrValue->blockSignals(b);
|
||||
|
||||
b = ui->eleCNT2IncEn->blockSignals(true);
|
||||
ui->eleCNT2IncEn->setChecked(cnt.eleEyeIncEn);
|
||||
ui->eleCNT2IncEn->blockSignals(b);
|
||||
|
||||
ui->spinBoxCnt2CurrValue->setEnabled(cnt.editCurrValue);
|
||||
ui->labelCnt2CurrValue->setText(QString::number(cnt.currValue));
|
||||
|
||||
b = ui->cbBoxCounterType->blockSignals(true);
|
||||
@@ -124,8 +109,6 @@ void CounterEditor::fetchCounterConfigFromView()
|
||||
cnt.repeatValue = ui->spinBoxCnt2RepeateCnt->value();
|
||||
cnt.stepValue = ui->spinBoxCnt2StepValue->value();
|
||||
cnt.currValue = ui->spinBoxCnt2CurrValue->value();
|
||||
cnt.editCurrValue = ui->checkBoxResetCnt2CurrValue->isChecked();
|
||||
cnt.eleEyeIncEn = ui->eleCNT2IncEn->isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,5 +117,4 @@ void CounterEditor::fetchCounterConfigFromView()
|
||||
*/
|
||||
void CounterEditor::onEditCurrValueToggled()
|
||||
{
|
||||
ui->spinBoxCnt2CurrValue->setEnabled(ui->checkBoxResetCnt2CurrValue->isChecked());
|
||||
}
|
||||
@@ -24,7 +24,6 @@ struct CounterEditorVM {
|
||||
int repeatValue = 1;
|
||||
int stepValue = 1;
|
||||
int currValue = 1;
|
||||
bool editCurrValue = false; // 对应 checkBoxResetCnt2CurrValue:勾选才允许重置/编辑当前值
|
||||
bool eleEyeIncEn = false; // 对应 eleCNT2IncEn:电眼触发使计数器+1
|
||||
};
|
||||
|
||||
|
||||
+47
-148
@@ -238,6 +238,9 @@
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999999</number>
|
||||
</property>
|
||||
@@ -309,6 +312,9 @@
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@@ -343,6 +349,9 @@
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-49999999</number>
|
||||
</property>
|
||||
@@ -462,6 +471,9 @@
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>999999</number>
|
||||
</property>
|
||||
@@ -536,6 +548,9 @@
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::NoButtons</enum>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -546,154 +561,6 @@
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>179</y>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxResetCnt2CurrValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton::indicator {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>当前值: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>56</x>
|
||||
<y>179</y>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="eleCNT2IncEn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton::indicator {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>增量值: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@@ -790,6 +657,38 @@ height: 25px;
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>180</y>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>当前值: </string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>180</y>
|
||||
<width>100</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>增量值: </string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QString>
|
||||
#include <QHash>
|
||||
#include <QPainter>
|
||||
|
||||
QHash<QString, int> defCharWidthMap;
|
||||
|
||||
@@ -27,10 +28,10 @@ QVariant PicCounterItem::source()
|
||||
void PicCounterItem::setSource(QVariant var)
|
||||
{
|
||||
PicTextItem::setSource(var);
|
||||
setCounter(counterType(), digitalNum());
|
||||
setCounter(counterType(), digitalNum(), m_displayNum);
|
||||
}
|
||||
|
||||
void PicCounterItem::setCounter(COUNTER_TYPE type, int digitalNum)
|
||||
void PicCounterItem::setCounter(COUNTER_TYPE type, int digitalNum, int displayNum)
|
||||
{
|
||||
if(type != COUNTER_TYPE_1 && type != COUNTER_TYPE_2) {
|
||||
qWarning() << "Missing counter type: " << type;
|
||||
@@ -63,9 +64,30 @@ void PicCounterItem::setCounter(COUNTER_TYPE type, int digitalNum)
|
||||
int height = font.pixelSize();
|
||||
width += letterSpace();
|
||||
|
||||
// 计算像素长度最长的数字 0 - 9
|
||||
int digital = 0;
|
||||
int digitalWidth = 0;
|
||||
for(int i = 0; i <= 9; ++i) {
|
||||
auto w = fontMetrics.horizontalAdvance(QString::number(i));
|
||||
if(w > digitalWidth) {
|
||||
digitalWidth = w;
|
||||
digital = i;
|
||||
}
|
||||
}
|
||||
|
||||
m_counterType = type;
|
||||
m_digitalNum = qBound(1, digitalNum, 8);
|
||||
m_digitalImg = strToImage(QString("8").repeated(m_digitalNum));
|
||||
m_digitalImg = strToImage(QString::number(digital).repeated(m_digitalNum));
|
||||
m_displayNum = displayNum;
|
||||
|
||||
// 临时使用这种手法显示当前值吧
|
||||
m_digitalImg.fill(0x00000000);
|
||||
auto displayNumImage = strToImage(QString::number(displayNum).rightJustified(m_digitalNum, '0').right(m_digitalNum));
|
||||
QPainter p;
|
||||
p.begin(&m_digitalImg);
|
||||
p.drawImage(QPoint(0, 0), displayNumImage);
|
||||
p.end();
|
||||
|
||||
applyModify();
|
||||
|
||||
qInfo() << "Counter item set to " << type ;
|
||||
@@ -84,7 +106,7 @@ int PicCounterItem::charWidth()
|
||||
void PicCounterItem::setCharWidth(int width)
|
||||
{
|
||||
m_charWidthMap[font().family()] = width;
|
||||
setCounter(counterType(), digitalNum());
|
||||
setCounter(counterType(), digitalNum(), m_displayNum);
|
||||
}
|
||||
|
||||
QImage PicCounterItem::itemImage()
|
||||
@@ -96,6 +118,7 @@ void PicCounterItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
||||
{
|
||||
auto typeRef = attrs.value("counter_type");
|
||||
auto digitalNumRef = attrs.value("digital_num");
|
||||
auto displayNumRef = attrs.value("display_num");
|
||||
|
||||
bool ok = false;
|
||||
int counterType = typeRef.toInt(&ok);
|
||||
@@ -111,7 +134,14 @@ void PicCounterItem::setCustomAttrs(const QXmlStreamAttributes &attrs)
|
||||
return;
|
||||
}
|
||||
|
||||
setCounter(static_cast<COUNTER_TYPE>(counterType), digitalNum);
|
||||
ok = false;
|
||||
int displayNum = displayNumRef.toInt(&ok);
|
||||
if(!ok || displayNum <= 0) {
|
||||
qWarning() << "Invalied counter display number: " << displayNum;
|
||||
return;
|
||||
}
|
||||
|
||||
setCounter(static_cast<COUNTER_TYPE>(counterType), digitalNum, displayNum);
|
||||
qInfo() << "Loaded attrs from xml: " << " counter type: " << counterType << ", digitalNum: " << digitalNum;
|
||||
}
|
||||
|
||||
@@ -119,6 +149,7 @@ void PicCounterItem::saveCustomAttrs(QXmlStreamAttributes &attrs)
|
||||
{
|
||||
attrs.append("counter_type", QString::number(counterType()));
|
||||
attrs.append("digital_num", QString::number(digitalNum()));
|
||||
attrs.append("display_num", QString::number(m_displayNum));
|
||||
qInfo() << "Set attrs to xml: " << " counter type: " << counterType() << ", digitalNum: " << digitalNum();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
virtual QVariant source() override;
|
||||
virtual void setSource(QVariant var) override;
|
||||
|
||||
void setCounter(COUNTER_TYPE type, int digitalNum);
|
||||
void setCounter(COUNTER_TYPE type, int digitalNum, int displayNum);
|
||||
|
||||
COUNTER_TYPE counterType() const { return m_counterType; }
|
||||
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
int m_digitalNum;
|
||||
QImage m_digitalImg;
|
||||
QHash<QString, int> m_charWidthMap;
|
||||
int m_displayNum = 0;
|
||||
};
|
||||
|
||||
#endif // _PIC_COUNTER_ITEM_H_
|
||||
|
||||
+14
-12
@@ -191,7 +191,7 @@ QImage PicDateItem::itemImage()
|
||||
return currImg;
|
||||
|
||||
int width = qMax(currImg.width(), m_maxSize.width());
|
||||
int height = qMax(currImg.height(), m_maxSize.height());
|
||||
int height = currImg.height();
|
||||
|
||||
QImage img(width, height, QImage::Format_ARGB32);
|
||||
img.fill(QColor(0,0,0,0).rgba());
|
||||
@@ -206,17 +206,19 @@ QImage PicDateItem::itemImage()
|
||||
|
||||
QRectF PicDateItem::boundingRect() const
|
||||
{
|
||||
// 优先使用已经应用变换后的 m_itemImage(与 PicTextItem 保持一致)
|
||||
if (!m_itemImage.isNull()) {
|
||||
return QRectF(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
}
|
||||
return PicTextItem::boundingRect();
|
||||
|
||||
// 否则基于缓存的最大像素尺寸和粗体倍数估算
|
||||
int w = m_maxSize.width();
|
||||
int h = m_maxSize.height();
|
||||
if (w <= 0 || h <= 0)
|
||||
return QGraphicsTextItem::boundingRect();
|
||||
// // 优先使用已经应用变换后的 m_itemImage(与 PicTextItem 保持一致)
|
||||
// if (!m_itemImage.isNull()) {
|
||||
// return QRectF(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
// }
|
||||
|
||||
qreal bw = qreal(w) * qMax(1, m_boldMultiple);
|
||||
return QRectF(0, 0, bw, qreal(h));
|
||||
// // 否则基于缓存的最大像素尺寸和粗体倍数估算
|
||||
// int w = m_maxSize.width();
|
||||
// int h = m_maxSize.height();
|
||||
// if (w <= 0 || h <= 0)
|
||||
// return QGraphicsTextItem::boundingRect();
|
||||
|
||||
// qreal bw = qreal(w) * qMax(1, m_boldMultiple);
|
||||
// return QRectF(0, 0, bw, qreal(h));
|
||||
}
|
||||
@@ -104,7 +104,16 @@ QImage PicScheduleShiftItem::itemImage()
|
||||
if(str.isEmpty()) {
|
||||
return QImage();
|
||||
}
|
||||
return strToImage(str);
|
||||
auto forceImg = strToImage(str);
|
||||
QImage backgroundImg(m_maxSize.width(), forceImg.height(), QImage::Format_ARGB32);
|
||||
backgroundImg.fill(0x00000000);
|
||||
|
||||
QPainter p;
|
||||
p.begin(&backgroundImg);
|
||||
p.drawImage(QPoint(0, 0), forceImg);
|
||||
p.end();
|
||||
|
||||
return backgroundImg;
|
||||
}
|
||||
|
||||
QSize PicScheduleShiftItem::calcMaxSize()
|
||||
@@ -123,6 +132,10 @@ QSize PicScheduleShiftItem::calcMaxSize()
|
||||
|
||||
QRectF PicScheduleShiftItem::boundingRect() const
|
||||
{
|
||||
auto r = PicTextItem::boundingRect();
|
||||
r.setWidth(m_maxSize.width());
|
||||
return r;
|
||||
|
||||
if (!m_itemImage.isNull()) {
|
||||
return QRectF(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user