QAbstractItemModel - inserting rows - how to specify the columns - c++

The doc shows a table
But the API does not allow you to specify the column under which to insert the rows.
void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last)
Under which column does the row get inserted?

You always insert a complete row, not a single cell so when adding a row into a table model the parent is the root index (= invalid QModelIndex), if you insert into a tree then the parent is the parent node.

Related

how to solve concatenate issue with.cell()? row = row work, column = column gives error

I am looping through an excel sheet, looking for a specific name. When found, I print the position of the cell and the value.
I would like to find the position and value of a neighbouring cell, however I can't get .cell() to work by adding 2, indicating I would like the cell 2 columns away in the same row.
row= row works, but column= column gives error, and column + 2 gives error. Maybe this is due to me listing columns as 'ABCDEFGHIJ' earlier in my code? (For full code, see below)
print 'Cell position {} has value {}'.format(cell_name, currentSheet[cell_name].value)
print 'Cell position next door TEST {}'.format(currentSheet.cell(row=row, column=column +2))
Full code:
file = openpyxl.load_workbook('test6.xlsx', read_only = True)
allSheetNames = file.sheetnames
#print("All sheet names {}" .format(file.sheetnames))
for sheet in allSheetNames:
print('Current sheet name is {}'.format(sheet))
currentSheet = file[sheet]
for row in range(1, currentSheet.max_row + 1):
#print row
for column in 'ABCDEFGHIJ':
cell_name = '{}{}'.format(column,row)
if currentSheet[cell_name].value == 'sign_name':
print 'Cell position {} has value {}'.format(cell_name, currentSheet[cell_name].value)
print 'Cell position TEST {}'.format(currentSheet.cell(row=row, column=column +2))
I get this output:
Current sheet name is Sheet1
Current sheet name is Sheet2
Cell position D5 has value sign_name
and:
TypeError: cannot concatenate 'str' and 'int' objects
I get the same error if I try "column = column" as "column = column +2".
Why does row=row work, but column=column dosen't? And how to find the cell name of the cell to the right of my resulting D5 cell?
The reason row=row works and column=column doesn't is because your column value is a string (letter from A to J) while the column argument of a cell is expecting an int (A would be 1, B would be 2, Z would be 26, etc.)
There are a few changes I would make in order to more effectively iterate through the cells and find a neighbor. Firstly, OpenPyXl offers sheet.iter_rows(), which given no arguments, will provide a generator of all rows that are used in the sheet. So you can iterate with
for row in currentSheet.iter_rows():
for cell in row:
because each row is a generator of cells in that row.
Then in this new nested for loop, you can get the current column index with cell.column (D would give 4) and the cell to the right (increment by one column) would be currentSheet.cell(row=row, column=cell.column+1)
Note the difference between the two cell's: currentSheet.cell() is a request for a specific cell while cell.column+1 is the column index of the current cell incremented by 1.
Relevant OpenPyXl documentation:
https://openpyxl.readthedocs.io/en/stable/api/openpyxl.cell.cell.html
https://openpyxl.readthedocs.io/en/stable/api/openpyxl.worksheet.worksheet.html

How to get value from list using index?

I have to try to get one by one value from list using index and i have try to get index value and update my stage one by one and respectively.
my python code below :
for ress in status_list:
print"res", ress
#self.workflow_stages = ress
if ress:
self.workflow_stages = ress
for index, item in enumerate(status_list):
print "test::", index
index_init = index
print"index_init:::", index_init
next = index_init + 1
print "next", next
lent = len(status_list)
print"lent", lent
return True
Thanks.
This for index, item in enumerate(status_list): means that index variable holds your respective index of the status_list and item variable holds your value. So in given for loop, item will hold the value of the corresponding index.
Generally, if you don't use the enumerate functionality to iterate over a list, you can access a value of the list like this status_list[index]

how to get next item in repeater c#, if list is given as datasource?

How to get next item in repeater by index or any other way?
e.g. in Sitecore if I'm getting the current item in repeater as
Item currentItem = (Item)e.Item.DataItem;
How can I get item which is next in the list which is given as the datasource?
Thanks Thomas ,
I got one similar approach . Declared list global and in repeater databound used :
Item currentItem = (Item)e.Item.DataItem;
int index = myList.IndexOf(currentItem);
Item nextItem = myList.ElementAt(index + 1);
You should make the Item List available to the method where you need it.
Then you could do something like this:
Item currentItem = (Item)e.Item.DataItem;
Item nextItem = MyList
.SkipWhile(item => item.ID != currentItem.ID)
.Skip(1)
.FirstOrDefault();

sqlite: How to get the column id of the selected column?

Given:
an sqlite database with a table T
the table T contains 10 columns - C0, C1 ... C9.
an sqlite3_stmt pointer corresponding to select C3,C2 from T
OK, so I can fetch the selected column values using the sqlite3_column_XXX family of methods (http://www.sqlite.org/capi3ref.html#sqlite3_column_blob), like this:
sqlite3_stmt *s;
sqlite3_prepare_v2(db, query, sizeof(query), &s, NULL);
while ((result = sqlite3_step(s)) == SQLITE_ROW)
{
const char *v3 = reinterpret_cast<const char *>(sqlite3_column_text(s, 0);
const char *v2 = reinterpret_cast<const char *>(sqlite3_column_text(s, 1);
}
What I need is the real index of the selected columns, i.e. 3 for v3 and 2 for v2.
Motivation: I want to be able to parse the returned string value into the real column type. Indeed, my schema says that c3 is a datetime, which sqlite treats as TEXT. So, sqlite3_column_type(s, 0) returns SQLITE3_TEXT, but the table metadata (available from pragma table_info(T)) retains the string datetime, which is the intended type of the column. Knowing it, I can parse the returned string into the respective unix time since the epoch, for instance.
But how can I map the query column index to the table column index:
query column 0 -> table column 3
query column 1 -> table column 2
Thanks.
You could use the sqlite C function sqlite3_column_decltype to get the declared column data type from the result stmt? It doesn't specifically answer your question (getting the original column's index), but could be an alternative way to achieve what you need?

Janus GridEx: Add custom row and select a specific row

I have GridEx object on my form and...
I want to add some items in it with a for...next loop. Actually I couldn't find any method for adding a new row with a custom data.
I want to select a specific row in that GridEx object. For example: I want to select the 6th row, is there anything like mygrid.rows(6).value or something like that?!
Thanks in Advance...
Assuming you have a GridEX control called grid...
To add new data:
GridEXRow row = grid.AddItem();
row.BeginEdit();
row.Cells[0].Value = "Whatever"; // refer to columns by index or name
...
row.EndEdit();
To retrieve a specific row:
GridEXRow row = grid.GetRow(5); // returns the 6th row
To select a specific row:
grid.MoveTo(5); // moves the selection to the 6th row
To add new row to gridex called MyGridEX:
object[] data = { "value0", "value1", "value2", ... };
this.MyGridEX.AddItem(data);
To select a specific row:
this.MyGridEX.GetRow(1); // select the second row