QTableView disable sorting for some columns - qt

I am using QtableView(qt5.9) with 10 columns and want to disable sorting for 2nd and 3rd (only some) columns when the user clicks on the header of these columns.
I use setsortingenabled flag to make my QtableView allow sorting
Is there any signal which I should listen to on clicking of header and then call some appropraite method or deny sorting.

You can use the header signal sortIndicatorChanged to restore the current sort indicator.
Example:
connect(m_poTableView->header(), &QHeaderView::sortIndicatorChanged,
this, &MyClass::HandleIndicatorChanged);
MyClass::HandleIndicatorChanged(int logicalIndex, Qt::SortOrder eSort)
{
if (logicalIndex != 0)
{
this->m_poTableView->horizontalHeader()->setSortIndicator(
0, this->m_poTableView->model()->sortOrder());
}
}

An easier way (for me, at least) is to subclass the filter proxy and override sorting for just the disabled columns. The below code is in Python, but it is a simple translation to C++.
def CustomSorter(QtCor.QSortFilterProxyModel):
def sort(self, column: int, order: QtCore.Qt.SortOrder) -> None:
if column == 2 or column == 3:
# Do nothing instead of sorting
return
else:
# Sort as usual
super().sort(column, order)

This is the code I use in the case I only want to allow sorting column 2 (sOrder is a private int member of MyClass):
connect(ui->tableView->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &MyClass::onSortIndicatorChanged);
void MyClass::onSortIndicatorChanged(int column, Qt::SortOrder order)
{
if (column == 2){
// Record the sort order when it is column 2
sOrder = order;
}
else{
// Restore the column 2 sort order
ui->tableView->sortByColumn(2, sOrder);
}
}

Related

How can I make a button within Google Sheets that toggles the values 1 and 0 in a destination cell?

I am trying to learn to do basic buttons within a spreadsheet to help with a project at school. I am a simple teacher that is trying to find resources to help. I have learned how to create a button that adds one or subtracts one with the value which will allow me to do what I need to do, but ideally I am looking for script code to make a button that would toggle between the values of 1 and 0 upon pressing the button.
Thanks for any help.
function plus1() {
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(
SpreadsheetApp.getActiveSheet().getRange('A1').getValue() + 1
);
}
I believe your goal as follows.
You want to switch the number of 1 and 0 at the cell "A1" on the active sheet by clicking a button.
In this case, at first, it is required to retrieve the value from the cell "A1" on the active sheet. And, the value is put by checking the retrieved value. So how about the following sample script?
Sample script:
function sample() {
var range = SpreadsheetApp.getActiveSheet().getRange('A1');
var value = range.getValue();
if (value == 1) {
range.setValue(0);
} else if (value == 0) {
range.setValue(1);
}
}
In this case, when the cell "A1" is not 1 or 0, the value in the cell is not modified.
References:
getValue()
setValue(value)
if...else
function toggleActiveCell() {
const sh=SpreadsheetApp.getActiveSheet();
const rg=sh.getActiveCell();
rg.setValue(rg.getValue()?0:1);
}
function toggleUniqueCell() {
const sh=SpreadsheetApp.getActiveSheet();
const rg=sh.getRange(row,col);
rg.setValue(rg.getValue()?0:1);
}

How to add new item in specific index?

I new in kotlin , i want to update an item in lists.
I use this code:
var index: Int
for (record in recordList)
if (record.id == updatedHeader?.id) {
index = recordList.indexOf(record)
recordList.add(index, updatedHeader)
}
but it cant do this, because of ConcurrentModificationException
Assuming that recordList is a MutableList and val (so, you'd like to modify the records in place), you can use forEachIndexed to find the records you care about and replace them.
This did not cause a ConcurrentModificationException:
recordList.forEachIndexed { index, record ->
if(record.id == updatedHeader?.id) recordList[index] = updatedHeader
}
On the other hand, if you redefine recordList as a non-mutable list, and a var, you could rewrite the entire list using map:
recordList = recordList.map { if(it.id == updatedHeader?.id) updatedHeader else it }
Of course, you could call .toMutableList() on the end of that if you wanted to turn your List into a MutableList.
If there's a single record with the given id in the list, you can find its index and add the header at that index:
val index = recordList.indexOfFirst { it.id == updatedHeader.id }
if (index >= 0)
recordList.add(index, updatedHeader)
If there are multiple records with the given id and you want to prepend header before each of them, you can use get listIterator and use its methods to modify the list during the iteration without getting ConcurrentModificationException:
val iterator = recordList.listIterator()
for (record in iterator) {
if (record.id == updatedHeader.id) {
iterator.previous() // move to the position before the record
iterator.add(updatedHeader) // prepend header
iterator.next() // move next, back to the record
}
}

One item per line (row) in timeline? - Vis.js

Is there a way to always have one item per line in the timeline? I don't want two or more items to share the same line, whatever the dates are.
Thanks.
You have to use groups, or if you're already using those for another purpose, you have to use subgroups.
Here's the official documentation for items, groups and subgroups (I'm assuming the website isn't gonna expire anytime soon... again...).
If you can use groups
Specify a different group for every item. You can set the group's content as an empty string, if you don't want to have a label for it on the left side of the Timeline.
If you want to arrange the groups in a specific way, specify an ordering function as the Timeline's options' groupOrder property. Example:
var options = {
// other properties...
groupOrder: function (a, b) {
if(a.content > b.content)// alphabetic order
return 1;
else if(a.content < b.content)
return -1;
return 0;
}
};
If you have to use subgroups
When you create an item, put it in the group it belongs to but also specify for it the subgroup property so that it's unique, like the item's id. For example, you can use the id itself, or add a prefix or suffix to it.
In the Timeline's options, set the stack and stackSubgroups properties to true.
In each group, set the subgroupStack property to true and specify an ordering function as the group's subgroupOrder property. Example:
var group = {
id: 1,
content: 'example group',
subgroupStack: true,
subgroupOrder: function(a, b) {
var tmp = a.start.getTime() - b.start.getTime();
return tmp === 0 ? parseInt(a.id) - parseInt(b.id) : tmp;
// if the start dates are the same, I compare the items' ids.
// this is because due to a bug (I guess) the ordering of items
// that return 0 in the ordering function might "flicker" in certain
// situations. if you want to order the items alphabetically in that
// case, compare their "content" property, or whatever other
// property you want.
}
};

AX NumberSequence: Mark a number as used

How to mark a given number as used in a NumberSequence when this number was not generated by the number sequence?
Let's consider I imported the first 10 records of a custom table and the file already specified its ID from 01 to 10,
then i want to intercept insert() mark the given number as used so that after importing, the first manually created record will assign ID 11.
This would be something like updating the field 'Next' in the NumberSequence.
Update the NumberSequenceTable.NextRec value to the desired value.
Make sure that format is correct.
Example code:
NumberSequenceTable numberSequenceTable;
ttsBegin;
select forUpdate numberSequenceTable
where numberSequenceTable.NumberSequence == 'Acco_1' // as example
;
numberSequenceTable.NextRec = 11;
if (numberSequenceTable.validateField(fieldNum(NumberSequenceTable, NextRec))
&& numberSequenceTable.validateWrite()
)
{
numberSequenceTable.update();
}
else
{
throw error("Validation failed");
}
ttsCommit;

Using Count To Split A Checklist Into 2 Columns in X++ Fetch Method

Here is what I have so far, this is returning two columns, but each counter is stopping and then duplicating the same value over and over...
if(lLogisticsControlTable.APMJobTypeId)
select count (RecID) from jobTypeCheck where jobTypeCheck.APMJobTypeId == lLogisticsControlTable.APMJobTypeId;
{
counter = jobTypeCheck.RecId;
}
while select jobTypeCheck where jobTypeCheck.APMJobTypeId == lLogisticsControlTable.APMJobTypeId
{
counter1 = counter / 2;
halfCount1 = counter - counter1;
if(halfcount <= counter1)
{
halfCount++;
jobListCheck1 = jobTypeCheck.Name;
}
if (halfCount1 > halfCount)
{
halfCount1++;
jobListCheck2 = jobTypeCheck.Name;
}
element.execute(2);
}
}
As Michael Brown indicated, it's difficult to understand the problem with half of the code ;)
However, I would suggest that you call the element.execute(2) method on every second pass through the loop? That way jobListCheck1 would be on the left, and jobListCheck2 would be on the right hand side. Finally you would then need to check immediately outside of your loop if you had an odd number of jobTypeCheck elements, and call the element.execute(2) method one last time remembering to set the jobListCheck2 variable as empty beforehand.
Regards

Resources