Truncated Display of Amounts in UltraGrid for data Type double - infragistics

I am using infragistics.UltraGrid and I am having a problem with the truncated display of amounts in the grid..The column is in double as datatype..is there anybody know how to fix it?Changing the width and setting it as multiline has no use....Thanks!

You need to format your UltraGridColumn for a currency datatype.
This could be done in the designer if you define the columns of your datasource, otherwise you could do something in code (perhaps in InitializeLayout event)
int integerNumbers = 10; // The max count of integers in the currency value
int decimalNumbers = 2; // The max count of decimals in the currency value
// If you write this in the InitializeLayout then you could
// use e.Layout.Bands[0].Columns
UltraGridColumn cl = grid.DisplayLayout.Bands[0].Columns["yourColumnKey"];
// Align on the right side
cl.CellAppearance.TextHAlign = HAlign.Right;
cl.Header.Appearance.TextHAlign = HAlign.Right;
// Format the maskinput
cl.MaskInput = string.Format("{{currency:-{0}.{1}}}", integerNumbers, decimalNumbers);
cl.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Currency;

Related

How can I get my price vector to = values inside my json array

Hello I am pretty new to json parsing and parsing in general so I am wondering what is the best way I can assaign the correct values for the price of the underlying stock I am looking at. Below is an example of the code I am working with and comments next to them showing kinda what Im confused about
Json::Value chartData = IEX::stocks::chart(symbolSearched);
int n = 390;
QVector<double> time(n), price(n);
//Time and Date Setup
QDateTime start = QDateTime(QDate::currentDate());
QDateTime local = QDateTime::currentDateTime();
QDateTime UTC(local);
start.setTimeSpec(Qt::UTC);
double startTime = start.toTime_t();
double binSize = 3600*24;
time[0] = startTime;
price[0] = //First market price of the stock at market open (930AM)
for(int i = 0; i < n; i++)
{
time[i] = startTime + 3600*i;
price[i] = //Stores prices of specific company stock price all the way until 4:30PM(Market close)
}
the charData is the json output with all the data,
.
I am wondering how I can get the various values inside the json and store them, and also since its intraday data how can I get it where it doesnt store p[i] if there is no data yet due to it being early in the day, and what is the best way to update this every minute so it continously reads in real time data?
Hope I understood correctly (correct me if not) and you just want to save some subset of json data to your QVector. Just iterate through all json elements:
for (int idx = 0; index < chartData.size(); ++idx) {
time[idx] = convert2Timestamp(chartData[idx]["minute"]);
price[idx] = convert2Price(chartData[idx]["high"], chartData[idx]["low"],
chartData[idx]["open"], chartData[idx]["close"], chartData[idx]["average"]);
}
Then you should define what is the logic of convert2Timestamp (how would you like to store the time information) and the logic of convert2Price - how would you like to store the price info, only highest/lowest, only the closing value, maybe all of these numbers grouped together in a structure/class.
Then if you want to execute similar logic every minute to update your locally recorded data, maybe instead of price[idx] = /* something */ you should push additional items that are new to your vector.
If there is a possibility that some of the json keys might not exist, in JsonCPP you could provide a default value e.g. elem.get(KEY, DEFAULT_VAL).

How can I set default values to QDoubleSpinBox

I am doing ballistic calculations for a projectile.
so in that I have a check box and based on check box I have to take the inputs
i.e if check box is enabled then read values from double-spinbox and do ballistics calculations
else go by the default values of the double spin box for that I have written this code but I end up the error in setValue()
so for my requirement wt method should I take.
if(ui->checkBox->isChecked())
{
//if it is checked then take the values given on UI
altitude= ui-doubleSpinBox_1>text();
b_pressure= ui-doubleSpinBox_2>text();
r_humidity= ui-doubleSpinBox_3>text();
temp= ui-doubleSpinBox_4>text();
}
else
{
///else take the default values
altitude=ui-doubleSpinBox_1>setValue(0);
b_pressure=ui-doubleSpinBox_2>setValue(29.53);
r_humidity=ui-doubleSpinBox_3>setValue(0.78);
temp=ui-doubleSpinBox_4>setValue(78);
}
QDoubleSpinBox::setValue returns a (lack of) value of type void, for which there are no conversions to anything. You are trying to assign to (double?) variables, and the compiler is telling you this is impossible.
Instead, you should conditionally set the default values, then unconditionally read the values. This keeps the (disabled?) ui up to date.
if(!ui->checkBox->isChecked())
{
// set the default values
ui->doubleSpinBox_1->setValue(0);
ui->doubleSpinBox_2->setValue(29.53);
ui->doubleSpinBox_3->setValue(0.78);
ui->doubleSpinBox_4->setValue(78);
}
altitude = ui->doubleSpinBox_1->value();
b_pressure = ui->doubleSpinBox_2->value();
r_humidity = ui->doubleSpinBox_3->value();
temp = ui->doubleSpinBox_4->value();
Alternately, you could conditionally set the variables with your defaults, and unconditionally set the UI from the variables
if(!ui->checkBox->isChecked())
{
// set the default values
altitude = 0;
b_pressure = 29.53;
r_humidity = 0.78;
temp = 78;
}
ui->doubleSpinBox_1->setValue(altitude);
ui->doubleSpinBox_2->setValue(b_pressure);
ui->doubleSpinBox_3->setValue(r_humidity);
ui->doubleSpinBox_4->setValue(temp);

C++ - set column names in HDF5

Is there a way, how to set column names in h5 file?
I can do this with compound datatype or it could be probably done using H5Table.
One option is also to make attribute and save names of columns this way.
But usual matrices of single datatype can not have named columns, do they?
As far as I know you can't set column name in an atomic datatype. As you have seen the trick of H5Table is that it creates a compund datatype where there is a field for each "column". LINK.
If I were you I would write the column names in an attribute (array of strings) and keep the datatype simple.
To create a list of strings in C++ I do as follows:
H5::H5File m_h5File;
m_h5File = H5File("MyH5File.h5", H5F_ACC_RDWR);
DataSet theDataSet = m_h5File.openDataSet("/channel001");
H5Object * myObject = &theDataSet;
//The data of the attribute.
vector<string> att_vector;
att_vector.push_back("ColName1");
att_vector.push_back("ColName2 more characters");
att_vector.push_back("ColName3");
const int RANK = 1;
hsize_t dims[RANK];
StrType str_type(PredType::C_S1, H5T_VARIABLE);
dims[0] = att_vector.size(); //The attribute will have 3 strings
DataSpace att_datspc(RANK, dims);
Attribute att(myObject->createAttribute("Column_Names" , str_type, att_datspc));
vector<const char *> cStrArray;
for(int index = 0; index < att_vector.size(); ++index)
{
cStrArray.push_back(att_vector[index].c_str());
}
//att_vector must not change
att.write(str_type, (void*)&cStrArray[0]);

Fast search through QTableWidget rows

I need to search rows through a QTableWidget. Each of the rows in the table contains a field with date and I need to show only rows that are within a specified date interval based on user input. Here is my function:
void nvr::sort()
{
QTableWidget* tabela = this->findChild<QTableWidget*>("NCtable");
QDateEdit* c1 = this->findChild<QDateEdit*>("c1");
QDateEdit* c2 = this->findChild<QDateEdit*>("c2");
// user specified ranges for date
QDate date1 = c1->date();
QDate date2 = c2->date();
//row numbers in table
int rowsNum = tabela->rowCount();
// hide all rows
for(int z = 0; z < rowsNum; z++) {
tabela->hideRow(z);
}
// show only rows that are within range
for(int z = 0; z < rowsNum; z++) {
QDateTime dateTime = QDateTime::fromString(tabela->item(z,2)->text(),"dd.MM.yyyy hh:mm");
QDate date = dateTime.date();
//date compares
if ( (date1.operator <=(date)) && (date2.operator >=(date) ) ) {
tabela->showRow(z);
}
}
}
This works fine if i have 200 rows. But when i have 30 000 rows and i surely will, the gui freezes because i suppose the function executes very slow. Any suggestions for faster execution?
It is hard to reproduce your problem, but here is the approach I would take:
Create a custom class to store the data of one row, let's call it
DataRow.
Store those in a QVector<DataRow>, that you can sort by Date1 for example.
Loop through this QVector<DataRow> and find the elements that correspond to the criteria.
Add those DataRow to a class derived from QAbstractItemModel.
Show this model derived from QAbstractItemModel with a QTableView.
QTableWidget is heavyweight and was not really built for speed. It's really convenient to build something quickly with few elements though.
QTableView is the one you want, with a custom model inherited from QAbstractItemModel.
Then, when the user requests a new input, you could just wipe the model and restart the process. This is not optimal, but the user should not see the difference. Feel free to add more logic here to keep the good elements and only remove the bad ones.
About the GUI freezing, one way to always avoid that is to have the GUI thread separated from other worker threads. The QThread documentation is exhaustive and can help you set up something like this.

C++ CListCtrl - GetItemData() returning wrong value?

I have a C++ application with an SQL backend, and have been storing the row id of any retrieved columns (an integer, primary key bigint in the database) with SetItemData() on list control rows as required. This is then retrieved with GetItemData() if that ID needs to be queried.
I am now getting a weird problem in that, in this one scenario, GetItemData() is returning a random 7-digit number instead of the stored ID. When I add the row I use the following code:
CListCtrl& lc = GetListCtrl();
for (int i = 0; i < vInsertItems.size(); i++) {
int j = lc.InsertItem(i,i.strName);
DWORD dwdRowID = (DWORD)cammms,nRowID;
lc.SetItemData(j,dwdRowID);
}
To retrieve and check the value I can do the following (where I have determined that nCurrentlySelectedIndex is correct):
CListCtrl& lc = GetListCtrl();
int msgID = lc.GetItemData(nCurrentlySelectedIndex);
CString debugInt; debugInt.Format(_T("debugInt = %d"),msgID);
AfxMessageBox(debugInt);
What is bizarre, is that if I run the second batch of code directly after the first, it is all fine. But if I run it in a separate function, msgID becomes set to a set of random 7 digits, different every time.
Does anyone have any idea what could be causing this?