QTableWidget removeRow not actually deleting - visual-studio

I have a QTableWidget filled with different QWidgets such that whenever I get a message from the server to add/update them I do so like this:
ui->tableWidget->setRowCount(data.count());
ui->tableWidget->setCellWidget(data.count() - 1, 0, new QCheckBox("Enabled"));
ui->tableWidget->setCellWidget(data.count() - 1, 1, new QLineEdit("ADD" ));
ui->tableWidget->setCellWidget(data.count() - 1, 2, new QComboBox( ));
ui->tableWidget->setCellWidget(data.count() - 1, 3, new QLineEdit("232434" ));
ui->tableWidget->setCellWidget(data.count() - 1, 4, new QComboBox( ));
Then with those widgets I signal/slot connect them in the next method like this:
for (int i = 0; i < TW_CNT; i++)
{
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentIndexChanged(int)), this, SLOT(cboxchanged(int)));
if( i == 0)
{
//stuff
connect((QCheckBox*)ui->tableWidget->cellWidget(cnt, i), SIGNAL(stateChanged(int)), this, SLOT(checkchanged(int)));
}
if( i == 1)
{
//stuff
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentIndexChanged(int)), this, SLOT(cboxchanged(int)));
connect(((QComboBox*)ui->tableWidget->cellWidget(cnt, i)), SIGNAL(currentTextChanged(QString)), this, SLOT(cboxedited(QString)));
}
//....
}
Later when I want to remove stuff from tableWidget, I do so by calling removeRow on the row I no longer need. The issue here is that these widgets still seem to stay children of the ui->tableWidget->viewport() and they never get deleted even if I call ->deleteLater() on them. Deleting them with delete just causes my program to crash, and adding more rows after each row removal is causing my memory usage to skyrocket.
I've been stuck on this for a few days, so any help is appreciated!

Related

explain by what criteria threejs assigns id to Obejct3d

there is an array of objects in the json file, the objects have current information about *.obj files and their paths. when referring to json as [...jsondata] array and calling each object in the scene through for(i=0; i<jsondata.lenght; i++) all are right, all objects are called up and the stage is lined up. But! The object.id assignment order is not the same as in the jsondata array, and for some reason always starts with id: 96. And most importantly id is not editable, and for me it is very important that the order in the scene was the same as in json. Can someone explain by what criteria threejs assigns this id?
Don't rely on the Object.id property to maintain any desired order. These are automatically generated, and they can add up quickly if any of your *.obj files have children, grandchildren, lights, cameras, etc.
For example, if you want 2 cars with id = 1 & 2, each part of the car could have a new id, depending on how it was built:
window: 2,
wheels: 3,
headlamps: 4,
light: 5
By the time you start car # 2, you're already on id = 6.
If you want to store a specific attribute in certain objects, you could use the .userData property to store it.
for(let i = 0; i < jsondata.length; i++) {
object[i].userData.order = i;
}
Or just create your own array to access them in order later:
const orderedItems = [];
for(let i = 0; i < jsondata.length; i++) {
orderedItems.push(someObject);
}

Kendo NumericTextBox with step and rounding

I want to setup kendoNumericTextBox to allow user input any integer number and set step to 1000. But when user enters any value and use spinner, it should update to next multiple of step.
For example:
enter 123, press spin up, value will be 1000
enter 1234, press spin up, value vill be 2000
Is it possible or only way is to handle spin event and modify value from there?
UPDATE:
Ok, guys, thnx for help.
I have this spin handler now and it seems to be working as expected.
function onSpin(e)
{
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0)
{
this.value(Math.floor(currentvalue / this.step()) * this.step());
}
if (currentvalue < 0)
{
this.value(Math.ceil(currentvalue / this.step()) * this.step());
}
}
I have provided a dojo below with a potential solution for you:
https://dojo.telerik.com/UQohUjaP/2
I have created a function that will work on the spin and on change value so that it will step the value up/down on the value that you set e.g. 1000
the function is fairly simple and for brevity I have taken out the log statements here:
function onChange() {
var currentvalue = kendo.parseInt(this.value());
if (currentvalue > 0) {
currentvalue = Math.ceil(currentvalue / this.step()) * this.step();
} else if (currentvalue < 0) {
currentvalue = Math.floor(currentvalue / this.step()) * this.step();
} else {
currentvalue = 0;
}
this.value(currentvalue);
}
Unfortunately there doesn't seem to be a simple way of figuring out if the value has gone up or down so I am basically checking to see if the value is greater than 1 or less than 1 and then calculating the ceiling or the floor for the value and then stepping it in the right direction. in order to cater for zero we have a special condition which just sets the value to 0 assuming that is a valid value in your scenario
As you say, it's possible by listening to the spin event:
$("#numerictextbox").kendoNumericTextBox({
min: 0,
spin: function(e) {
var isUp = e.sender._key === 38,
isDown = e.sender._key === 40;
var m = Math.trunc(this.value()/1000),
value = isUp ? m + 1 : m;
this.value(value * 1000);
}
});
I doubt there's something out of the box, because your needs seem somewhat unusual.

Amibroker: Daily Loss Limit

I want to implement an afl code to find Daily Loss Limit in intraday trading. I will use the code for backtesting around 200 days.
I have the following code but it is with mistakes.
// identify new day
dn = DateNum();
newDay = dn != Ref( dn,-1);
// Daily Loss Limit
dll = Optimize("dll", 0, 5, 10000, 5 );
EquityCount = 10000;
for( i = 0; i < BarCount; i++ )
{
// signals
Buy = ....;
Sell = ....;
diff = (Equity(1) - Ref(Equity(1), -1));
EquityCount = EquityCount + diff;
// allow only dll
Buy = Buy AND EquityCount > dll;
}
Any help will be appreciated.
Thanks.
First your code is completely wrong.
Secondly Equity() function is single security function. It is obsolete.
Use custom backtest interface of AmiBroker instead. See AmiBroker help.

Is there a limit for the number of propertyPages in a propertySheet?

In one of my mfc dialogs I use a propertySheet (with hidden tabs) to update subsections of the dialog during runtime.
This works generally fine, but today I've hit a problem I can not find the reason to.
I'm adding propertyPages to the propertySheet in a simple for-loop:
m_myPropertySheet = new CMyPropertySheet();
long maxN = 50;
for ( long i=0; i<maxN; i++ )
{
CMyPropPage * pMyPropPage = new CMyPropPage(i);
m_myPropertySheet->AddPage( pMyPropPage );
}
and later I create that page using:
if(m_myPropertySheet->m_hWnd == NULL)
{
if ( FALSE == m_myPropertySheet->Create(this, WS_CHILD | WS_VISIBLE, 0) )
return;
}
This code works fine as long as I have less than 100 propertyPages in the sheet (i.e. maxN<100 ), but once maxN>=100 the Create call returns FALSE, and I do not quite understand why.
Can somebody explain this?
Is there a limit of how many propertyPages I can have in a sheet?

How do I structure the Data array for the following d3 chart, in order to populate with real data

http://nvd3.org/ghpages/scatter.html
I want to build a chart thats very similar to the above example. I'm still in the beginning phases and am having a little difficulty trying to input my own data, either as a CSV or inline in the code.
I'm pretty sure that the code below is responsible for generating fake data to populate the chart, however, I can't seem to find the correct way to input real data. I've read over the "data" reference portions of the documentation on the d3 site and tried implementing the code but have not been able to get it to work. I believe the problem is structuring. The question is, how do I find out how I need to structure the data array and use that, as input for the data?
Here is the live example of where I'm building my version of the chart.
http://goo.gl/XHela
Here is the code that is generating the random data:
function randomData(groups, points) { //# groups,# points per group
var data = [],
shapes = ['circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'],
random = d3.random.normal();
for (i = 0; i < groups; i++) {
data.push({
key: 'Group ' + i,
values: []
});
for (j = 0; j < points; j++) {
data[i].values.push({
x: random(),
y: random(),
size: Math.random(),
shape: shapes[j % 6]
});
}
}
return data;
}
Before your response I tried to output the results of the function randomData to the page, using the following code, (the same just modified).
function see(groups, points) { //# groups,# points per group
var data = [],
shapes = ['circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'],
random = d3.random.normal();
for (i = 0; i < groups; i++) {
data.push({
key: 'Group ' + i,
values: []
});
for (j = 0; j < points; j++) {
data[i].values.push({
x: random(),
y: random(),
size: Math.random(),
shape: shapes[j % 6]
});
}
}
data.toString();
var x=document.getElementById("demo");
x.innerHTML=data;
}
But on the page the output is
[object Object],[object Object],[object Object],[object Object]
I guess the follow up question is how do I use my own data for this chart and not generated data?
You can see how the data is structured by stepping through the code using Chrome Developer tools' console in Chrome. In the page you linked above (first link) Pressing Ctrl + Shift + C in Windows or Command + Shift + c in OSX will bring up this window. Click on Sources and find the file scatter.js from the list of files on the left. Set a break point at the line: return data. Referesh the page. Code execution will pause at that line. Now go the the Console and type data. The data used for the chart will be output. You can browse the structure and get an idea of how it was created.
You should see something like this in the end:

Resources