调用特权函数的父实现(calling parent implementations of privileged functions)
我有两个JavaScript类1之间的继承关系
RealTimeChart = function(chartAttributes) { var chart = new FusionCharts(chartAttributes); this.appendData = function(data) { chart.feedData(data); } }; RealTimeGauge = function(chartAttributes) { chartAttributes.type = 'AngularGauge'; // call parent constructor RealTimeChart.call(this, chartAttributes); }; // inherit from RealTimeChart RealTimeGauge.prototype = Object.create(RealTimeChart.prototype);
在
RealTimeGauge
我想覆盖appendData()
。 在RealTimeGauge
执行此函数需要调用父实现,这可能吗?如果我将
appendData
更改为原型函数,则执行此操作相对简单,例如// parent class RealTimeChart.prototype.appendData = function(data) { this.chart.feedData(data); }; // child class RealTimeGauge.prototype.appendData = function(data) { console.log("doing custom stuff..."); // call the parent function to add the data to the chart RealTimeChart.prototype.appendData.call(this, data); };
但是,如果我使
appendData
成为原型函数而不是特权函数,我还必须将chart
设为公共属性,我宁愿不这样做。 如果它是特权函数,是否可以调用appendData
表单RealTimeGauge
的父实现?
- 我知道他们不是真正的课程,但我不知道他们有更好的名字
I have an inheritance relationship between two JavaScript classes1
RealTimeChart = function(chartAttributes) { var chart = new FusionCharts(chartAttributes); this.appendData = function(data) { chart.feedData(data); } }; RealTimeGauge = function(chartAttributes) { chartAttributes.type = 'AngularGauge'; // call parent constructor RealTimeChart.call(this, chartAttributes); }; // inherit from RealTimeChart RealTimeGauge.prototype = Object.create(RealTimeChart.prototype);
In
RealTimeGauge
I would like to overrideappendData()
. The implementation of this function inRealTimeGauge
needs to call the parent implementation, is this possible?It's relatively straightforward to do this if I change
appendData
to a prototype function, e.g.// parent class RealTimeChart.prototype.appendData = function(data) { this.chart.feedData(data); }; // child class RealTimeGauge.prototype.appendData = function(data) { console.log("doing custom stuff..."); // call the parent function to add the data to the chart RealTimeChart.prototype.appendData.call(this, data); };
However, if I make
appendData
a prototype function rather than a privileged function, I also have to makechart
a public property, which I'd rather not do. Is it possible to call the parent implementation ofappendData
formRealTimeGauge
if it's a privileged function?
- I know they're not really classes, but I don't know of a better name for them
原文:https://stackoverflow.com/questions/25384213
最满意答案
您正在使用的
drawLines()
重载(来自Qt5文档):QPainter::drawLines (const QPointF* pointPairs, int lineCount)
我可以提请您注意第二个参数。 它被称为
lineCount
,而不是点数,所以你必须传递HALF的点数:assert (0 == horizontalAxis.size () % 2); p.drawLines (&horizontalAxis[0], static_cast<int> (horizontalAxis.size () / 2));
The
drawLines()
overload you are using is (from the Qt5 docs):QPainter::drawLines (const QPointF* pointPairs, int lineCount)
May I draw your attention to the second parameter. It's called
lineCount
, not point-count, so you have to pass HALF the number of points:assert (0 == horizontalAxis.size () % 2); p.drawLines (&horizontalAxis[0], static_cast<int> (horizontalAxis.size () / 2));
相关问答
更多-
Canvas.drawLines显示不连贯的片断[复制](Canvas.drawLines displaying disjointed segments [duplicate])[2023-05-12]
你得到的正是在drawLines文档中指定的内容。 做你想做的一种方法是从这些数据构建一个Path ,并使用drawPath而不是drawLines 。 就像是: Path _path = new Path(); _path.moveTo(_data[0], _data[1]); for (int i=2; i<_data.length; i+=2) { _path.lineTo(_data[i], _data[i+1]); } 然后画出它: _canvas.drawPath(_path, _pain ... -
QPainter drawLines方法(QPainter drawLines method)[2023-09-08]
您正在使用的drawLines()重载(来自Qt5文档): QPainter::drawLines (const QPointF* pointPairs, int lineCount) 我可以提请您注意第二个参数。 它被称为lineCount ,而不是点数,所以你必须传递HALF的点数: assert (0 == horizontalAxis.size () % 2); p.drawLines (&horizontalAxis[0], static_cast(horizontalAxis.si ... -
Qt - 创建QPainter(Qt - creating QPainter)[2022-05-31]
包含QPainter头文件。 QPainter类仅在您在该翻译单元中包含的Qt标头之一中进行前向声明。 Include QPainter header file. QPainter class is only forward declared in one of the Qt headers you're including in that translation unit. -
如果任何人需要类似这样的代码,下面的代码会创建一个与问题图片左上角相似的形状 QRectF newRec = rect; painter->save(); newRec.setSize( newRec.size() / 20 * 11 ); painter->setBrush(Qt::white); QColor colorRect( LMCTheme::Instance()->GetColor(InternalStuff::ColorIconInfoBarArrow)); painter->setPen ...
-
Qpainter情节消失了(Qpainter plot disappears)[2022-01-25]
无法确切知道,但我想最有可能的原因是m_initial_condition变量在每次计算时被修改。 作为诊断此类问题的好方法,我建议将const添加到不应该实际更改的变量中。 Can't know for sure but I suppose that most likely it is caused by m_initial_condition variable being modified on each calculation. As a good way to diagnose such probl ... -
好的,所以我找到了一个适用于“旋转”文本的解决方案。 我必须在绘制文本之前重新缩放画家,并在翻译的位置上绘制它: 所以for循环看起来像这样: for k, text in enumerate(xlabels): painter.save() painter.scale(1,-1) painter.drawText(myxrange[k], -myyrange[0], text) painter.restore() 我仍在寻找固定大小问题的答案。 Ok, so I foun ...
-
旧机器 + 当我们尝试构建更大的场景时,软件会崩溃 =很可能是内存不足。 您可以安装内存不足的处理程序,以便在发生这种情况时获得通知: #include
#include void my_new_handler() { printf("Memory allocation failed, terminating\n"); std::set_new_handler(nullptr); } int main(int argc, char ** argv) { QApp ... -
文档说明你不能在同一个涂装设备上有2个有效的QPainter 。 因此,因为BaseRenderArea::paintEvent可能正在创建自己的QPainter ,所以它可能使之前在DebugRenderArea::paintEvent创建的DebugRenderArea::paintEvent无效。 你可以简单地重新排序两行: BaseRenderArea::paintEvent(event); QPainter painter(this); The documentation says that ...
-
QPainter缓存可能吗?(QPainter Cache Possible?)[2023-11-12]
使用QPixmap作为缓存,QPainter也可以使用它直接绘制。 Use a QPixmap as a cache, QPainter can use it to paint onto directly as well. -
如果你的pts数组少于2个点,它将抛出参数无效错误。 确保您的数组有足够多的点来绘制线条。 If your pts array has less than 2 points, it will throw the parameter is not valid error. Make sure your array has more then enough points to draw the lines.