Eclipse Scout Neon add new row with tab key - eclipse-scout

I would like to add new row in table field if I press tab on the last column of the last row.
If user press tab on cell (editable cell) it select next cell in row or go in new (existing) row. But I would like to achieve that if I press tab on last row with last column that this action would create new row. Currently it focus next button/field/... in form.
Is there a way to do this?

Have you tried to use something like this:
Add on the last Column a execCompleteEdit and check if you are in the last row
#Override
protected void execCompleteEdit(ITableRow row, IFormField editingField) {
if (row.getRowIndex() == row.getTable().getRowCount() - 1) {
// create row
ITableRow r = row.getTable().addRow(getTable().createRow());
//eventually you have to set values into cells
//get first editable cell(in this case NameColumn) and request focus
row.getTable().requestFocusInCell(getNameColumn(), r);
}
}

Related

how to add QSpinBox to a QTableWidget?

I have a QTableWidget and an object of class product called p.
I wanna add items to this table.
I tried the code below but no use.
void MainWindow:: add_to_basket (product p){
ui->tableWidget->insertRow(1);
QLineEdit *qle=new QLineEdit();
qle->setText(p.get_name());
ui->tableWidget->setCellWidget(1,1,qle);
QLineEdit *qle1=new QLineEdit();
qle1->setText(QString::number(p.get_price()));
ui->tableWidget->setCellWidget(1,2,qle1);
QSpinBox *qsb=new QSpinBox();
qsb->setValue(p.get_count());
ui->tableWidget->setCellWidget(1,3,qsb);
}
what should I do?
QTableWidget should have defined rowCount and columnCount properties. It can be done either via QTableWidget constructor (https://doc.qt.io/qt-5/qtablewidget.html#QTableWidget-1) or via appropriate methods (setRowCounts and setColumnCounts). If it is done already, that's great.
insertRow inserts an empty row into the table at given position. ui->tableWidget->insertRow(1) would insert a new row at position 1 only if you have previously defined rowCount and columnCount (see point 1).
It depends what is your idea here - if you would like to have at least 4 columns (please note that we are counting from 0 and the QSpinBox is attempted to be put into third column) and insert new product always at first row, your code with point 1 fullfilled will be work fine. But, if your idea is to add a new row each time new product is added, you should rather call ui->tableWidget->insertRow(tableWidget->rowCount()) and use that value to address appropriate row.
You may also want to have a look here for example how to setup QTableWidget: https://wiki.qt.io/How_to_Use_QTableWidget

Google Sheets: Click button to unhighlight row, highlight the next row, and update cell with date and time button was clicked

I'm trying to create a rotation scheduler. My goal is to have a table of names, phone numbers and a button.
When the button ('Assign') is pressed, it highlights a row, and updates a cell outside the table with the date & time it was clicked. When it is pressed again, it un-highlights that row and highlights the next row, and updates the date/time cell.
When it reaches the bottom, it should move back to the top. It should save where it left off between closing and opening the document and it needs to sync even when several users have it open... I don't think Excel can do that, but Google Sheets should be able to, which is why I'm leaning towards Google Sheets.
I completely understand if that's too much to expect someone to sort out on a forum, but I would very much appreciate even a point in the right direction as to figuring it out myself!!
When the button ('Assign') is pressed, it highlights a row, and
updates a cell outside the table with the date & time it was clicked.
You can add or create an image that acts as a button and associate a script to be triggered when it is clicked.
When it reaches the bottom, it should move back to the top.
One way of doing it is to keep track of the highlighted row and use modular arithmetic to wrap back to the start of the table.
It should save where it left off between closing and opening the
document
One option is to use the Properties Service to store the highlighted row.
I tried to implement a sample using these ideas (make a copy before you run): https://docs.google.com/spreadsheets/d/1bHN5cf2HaLTW3EbAxfXUusQnDL3dNFY313J8cdTGp4o/
The associated script:
var NUMBER_OF_ASSIGNEES = 5;
var LAST_ASSIGNMENT_DATETIME_CELL = 'G3';
var TABLE_OFFSET = 2;
function assignNewPerson(){
var sheet = SpreadsheetApp.getActive().getActiveSheet();
setAssignTime(sheet);
assignNext(sheet);
}
function setAssignTime(sheet) {
var d = new Date();
sheet.getRange(LAST_ASSIGNMENT_DATETIME_CELL).setValue(d.toLocaleTimeString());
}
function assignNext(sheet) {
// Use the Properties Service to store the current assignee index.
var documentProperties = PropertiesService.getDocumentProperties();
var currentAssigneeIndex = parseInt(documentProperties.getProperty('CURRENT_ASSIGNEE_INDEX'));
if (isNaN(currentAssigneeIndex)) {
currentAssigneeIndex = 0;
}
// Remove highlight from assignee cells.
sheet.getRange(TABLE_OFFSET + currentAssigneeIndex, 1, 1, 2).setBackground("white");
// Increment the assignee index. If the last row is reached, go back to the start of the table.
currentAssigneeIndex = (currentAssigneeIndex + 1) % NUMBER_OF_ASSIGNEES;
documentProperties.setProperty('CURRENT_ASSIGNEE_INDEX', currentAssigneeIndex);
// Highlight assignee cells.
sheet.getRange(TABLE_OFFSET + currentAssigneeIndex, 1, 1, 2).setBackground("yellow");
}

Wijmo Flexgrid how to get number of rows pasted/Get index of row where data is pasted

I want to change data while pasting. I am pasting a number of rows and I want to change on pasted data.
I am trying on pasting event but I am not able to get the index of pasted rows.
You can use the event data that was sent to the pasting event:
grid.pasting.addHandler(function(s, e) {
let row = e.row; // gets the starting row index
let rng = e.range; // gets the whole cell range which were affected
});

Hidden sort indicator on column in QTreeView

I have QTreeView and I setSortEnable = true for it, and all of column show sort indicator, but now I want last column do not show sort indicator, just last column.
Have any idea or solution for my issue..:(
please help
Thanks
QHeaderView always draws the sorting indicator on a column when data is sorted by this column (if setSortIndicatorShown is true).
That is why it look like the only way to prohibit drawing of the indicator is to prohibit sorting of the column by left-click.
To prohibit sorting by a certain column you need:
1. create a new class inherited from QHeaderView (or use an event filter)
2. reimplement mouseReleaseEvent and mousePressEvent
3. use logicalIndexAt to indicate that user clicked on the column
4. call setSectionsClickable(false) before calling the base method and setSectionsClickable(true) after it.
Example:
void HeaderView::mouseReleaseEvent(QMouseEvent* e)
{
const int index = logicalIndexAt(e->pos());
if (index == 3) setSectionsClickable(false);
QHeaderView::mouseReleaseEvent(e);
setSectionsClickable(true);
}
Do the same for mousePressEvent.
thus you will prohibit sorting of a certain column
In my case, I've three columns and it was necessary to hide the sort indicator of the second column.
Because of I had custom rules of sorting, just got QHeaderView::sectionClicked event with OnHeaderClicked(int column) slot, and did this:
switch (column)
{
case 0:
// Custom sorting operations
break;
case 1:
tree_widget_->sortByColumn(-1);
break;
case 2:
// Custom sorting operations
break;
}

Extjs4.2 - Get rowIndex of a selected row

I have set up a grid panel with groupingsummary (tried grouping feature also - no luck) feature and actioncolumn [for deleting and editing records]. I'm wrestling a couple of days to get row index but to no avail.
Without the groupingsummary feature the actioncolumn works as it should, i can edit or delete a row by clinking the action icons using the following code to select a row:
handler: function(grid, rowIndex) {
rec = grid.getStore().getAt(rowIndex);
rowId = rec.get('rowId');
rowName = rec.get('rowName');
...
...
}
Then i execute an Ajax request to the server for the corresponding action [edit, delete].
How do i select a row in a grid with groupingsummary feature? Is it a bug?

Resources