首页 \ 问答 \ 调用特权函数的父实现(calling parent implementations of privileged functions)

调用特权函数的父实现(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的父实现?

  1. 我知道他们不是真正的课程,但我不知道他们有更好的名字

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 override appendData(). The implementation of this function in RealTimeGauge 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 make chart a public property, which I'd rather not do. Is it possible to call the parent implementation of appendData form RealTimeGauge if it's a privileged function?

  1. I know they're not really classes, but I don't know of a better name for them

原文:https://stackoverflow.com/questions/25384213
更新时间:2022-08-09 15:08

最满意答案

您正在使用的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));

相关问答

更多
  • 你得到的正是在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 ...
  • 您正在使用的drawLines()重载(来自Qt5文档): QPainter::drawLines (const QPointF* pointPairs, int lineCount) 我可以提请您注意第二个参数。 它被称为lineCount ,而不是点数,所以你必须传递HALF的点数: assert (0 == horizontalAxis.size () % 2); p.drawLines (&horizontalAxis[0], static_cast (horizontalAxis.si ...
  • 包含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 ...
  • 无法确切知道,但我想最有可能的原因是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 ...
  • 使用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.

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。