PDA

View Full Version : apply change to filtered rows is it possible?



jaafari
3rd April 2015, 00:17
hi there!

i am using QSqlRelationalTableModel QSqlTableModel QDataWidgetMapper QSortFilterProxyModel QTableView..
to filter multiple rows in a column and i use QLineedit to display code of that filtered rows and after filtering i want to change other rows in my second table & my thrid table using tow QComboBox so if i changed content in one of that Combobox it should apply the change to all the rows that have the same code in column( N° 3) whech displaied in QLineEdit.. how to do that is it possible? i am sorry if i can't explain well due to my bad english thanks for help :o


{
ui->setupUi(this);

//bla bla bla...
//bla bla bla...

myeditModel = new QSqlRelationalTableModel(this);
myeditModel->setTable("myFirstTable");
myeditModel->setRelation(myeditModel->fieldIndex("myFirstForeignKeyID"/*1*/), QSqlRelation("mySecondTable","id","name"));
myeditModel->setRelation(myeditModel->fieldIndex("mySecondForeignKeyID"/*2*/), QSqlRelation("myThirdTable","id","name"));
myeditModel->setRelation(myeditModel->fieldIndex("myCodeID"/*3*/), QSqlRelation("myFourthTable","id","myCode"));
myeditModel->select();


QSqlTableModel *relationModel1 = myeditModel->relationModel(1);
ui->myFirstComboBox->setModel(relationModel1);
ui->myFirstComboBox->setModelColumn(relationModel1->fieldIndex("name"));

QSqlTableModel *relationModel2 = myeditModel->relationModel(2);
ui->mySecondComboBox->setModel(relationModel2);
ui->mySecondComboBox->setModelColumn(relationModel2->fieldIndex("name"));


mapper = new QDataWidgetMapper(this);

mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
mapper->setModel(myeditModel);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->myFirstComboBox, 1);
mapper->addMapping(ui->mySecondComboBox, 2);
mapper->addMapping(ui->codeEdit, 3);
mapper->addMapping(ui->dateEdit, 4);


//bla bla bla...
//bla bla bla...


mapper->setCurrentIndex(row);

QString filterValue = ui->codeEdit->text();

myproxy= new QSortFilterProxyModel(this);
myproxy->setSourceModel(myeditModel);
myproxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
myproxy->setFilterRegExp(QRegExp(filterValue, Qt::CaseInsensitive, QRegExp::FixedString));
myproxy->setFilterKeyColumn(/*-1*/3);

ui->EditView->setModel(myproxy);
ui->EditView->resizeRowsToContents();
ui->EditView->resizeColumnsToContents();
ui->EditView->setSortingEnabled(true);
ui->EditView->setColumnHidden(0, true);
}

myEditDialog::~myEditDialog()
{
delete ui;
}
void myEditDialog::on_codeEdit_selictionChanged(const QString &arg1)
{
myproxy->setFilterFixedString(arg1);

}

wysota
3rd April 2015, 07:52
I don't see a problem. What have you done so far? How are you updating those two other tables?

jaafari
3rd April 2015, 11:26
thank you !
thank you !

i am sorry for my misstakes bro.. :rolleyes: i don't update the tow other tables it is a relationshape and i want to update only numbers in rows of column 1 ("myFirstForeignKeyID"/*1*/) and column 2 ("mySecondForeignKeyID"/*2*/) whech is filtered by column 3 ("myCodeID"/*3*/) inside ("myFirstTable") whech i am displaing in my tableview.

let say LineEdit displaies number (90) and there are 4 rows with the same (90) in column 3 whech are already filtered and column 1 for example displaies 4 rows whech are Foreign Keys and these foreign keys all of theme are number (1) and they displaies the same "name" (name1,name1,name1,name1) also ComboBox1 displaies the same "name" whech is (name1)... now i want to change ComboBox1 to (name9) and this changing should be applied automaticly to those 4 rows so the foreign keys were (1,1,1,1) now should be (9,9,9,9) please look at my diagram and let me now what should i do... :rolleyes:

wysota
3rd April 2015, 11:30
Ok but what is the problem you are having to implement what you wrote here?

jaafari
3rd April 2015, 11:48
no problem bro :o

i just need some help on how combobox apply change to those filtered rows maybe i should write something like this:




void EditDlvrDialog::on_myFirstComboBox_somethingChange d(something)
{
something
something
}




:cool:

wysota
3rd April 2015, 13:02
Well, you take the value from the combobox and using that value you update your model. Do you know how to update values from your model?

jaafari
3rd April 2015, 14:02
no bro i am sorry i don't know :(


can you tell me how :confused:

wysota
3rd April 2015, 14:35
You use the QAbstractItemModel::setData() method. In general if you want to use models, you should read about them first.

jaafari
3rd April 2015, 15:47
and how to use QAbstractItemModel::setData() ? :)

yeye_olive
3rd April 2015, 16:01
and how to use QAbstractItemModel::setData() ? :)
Easy:

you stop being lazy;
you go read the documentation as you were already advised to;
you try to solve your problem;
you come back and explain the approaches you tried, and ask specific questions.

Does that sound reasonable to you, or would you rather have other people do for free the work you are paid for?

wysota
3rd April 2015, 16:01
Call it on your model passing the index, value and role in the model you wish to change (e.g. Qt::EditRole).

jaafari
3rd April 2015, 19:22
Does that sound reasonable to you, or would you rather have other people do for free the work you are paid for?

i am not a programmer bro.. i am just here to learn and in fact there is no documentation in my language :( thank you :)

wysota
3rd April 2015, 20:54
i am not a programmer bro.. i am just here to learn and in fact there is no documentation in my language :( thank you :)

There is documentation in English. This forum is English. If you can't understand English documentation, how are you going to understand my English explanation?

jaafari
3rd April 2015, 21:27
There is documentation in English. This forum is English. If you can't understand English documentation, how are you going to understand my English explanation?

it is very difficult for me and in some conversation i try translator (thanks to google).. i hope one day other people can find Qt in other languages

jaafari
4th April 2015, 17:38
any help guys or should i pay to someone to tell how?

anda_skoa
4th April 2015, 20:41
any help guys or should i pay to someone to tell how?

What's wrong with the solution already given in comment #11?

Cheers,
_

jaafari
5th April 2015, 20:32
my dear i just want an example even if i will pay for it no problem :cool:

Added after 5 minutes:


Easy:
Does that sound reasonable to you, or would you rather have other people do for free the work you are paid for?

give me a example pravite and i am ready to pay for it.. just tell me how much that will cust?

wysota
6th April 2015, 12:38
I can give you an example for free.


model.setData(model.index(0, 0), 7, Qt::EditRole); // sets 7 into default role of item (0, 0)

jaafari
10th July 2015, 19:44
and what about combobox:


void myEditDialog::on_myFirstComboBox_currentIndexChang ed(int index)
{

}


should i do it like this?

wysota
10th July 2015, 20:24
What about it?

jaafari
10th July 2015, 23:43
i mean should i use it in this way?




void myEditDialog::on_myFirstComboBox_currentIndexChang ed(int index)
{
model.setData(model.index(0, 0), 7, Qt::EditRole); // sets 7 into default role of item (0, 0)
}

d_stranz
11th July 2015, 04:19
So every time someone selects a different item from the combo box, you want to store the value 7 into item( 0, 0 )? Why?

Why don't you try to explain what you really want to do when someone changes the combo box selection?

jaafari
11th July 2015, 18:16
in my diagram below i have a form with a lineedit a tableview a combobox..
in my database table i have 4 columns and many rows and this columns are: ID , Name , Filter Code , Other Data... and i am just working in tow columns.. Name and Filter Code columns..
and as i am showing in my diagram in column (Filter Code) there are alot of rows but they divided into groups and every group has a different number which is that (filter code ) the lineedit displays the filtered number.. for example if it is 22 the filter code column in tableview displays only the group with that number..

now the combobox displays column (Name) contains which is name1 , name2 , name3 , name4... i assume that the column (Name) in tableview displays name2 and the 22 group belongs to that name.. the combobox should display the same name which is name2 and if we change the contain in combobox the change should be applied to all the rows that belongs to the group that already filtered by the number 22 which displayd in lineedit..

this is already happened because i am using QDataWidgetMapper but the change apply only to the last row not to all rows which i want..

in my form i am using: QLineEdit QComboBox QTableView , QSqlRelationalTableModel , QSortFilterProxyModel , QDataWidgetMapper..

wolcome

d_stranz
12th July 2015, 00:52
I am sorry but I don't understand what you are trying to do.

Do you want to change the database? (That is, if the user types a new name into the combobox do you want "newName" to replace "name2" in the database)?

Do you want to select something new from the database (read only) when the user changes the combobox selection or enters a new code in the line edit?

jaafari
21st July 2015, 23:18
hi!

for the lineedit i used it only to filter database.. so the table displays only filtered rows... the combo box i want to use it with filtered rows so if i change data in that combo box the data should be changed also in the filtered rows so if the names were name2 in the table and changed combobox to name3 the change should be aplied to all that filtered rows only (the filtered rows with linedit) after that i will call SubmitAll function with save button to update database... thats all thank you.

Added after 9 minutes:




Do you want to select something new from the database (read only) when the user changes the combobox selection

yes i already have names in the database and it is a relationship database the combo box will update values because it is a forignkey.. and use qsqlrelationaltablemodel with itemdelegate.. thank you!