void Clients::updateCleintTable()
{
QString searchValue
= ui
->lineEdit_search_clients
->text
();
proxyModel->setSourceModel(model);
proxyModel
->setFilterRegExp
(QRegExp(searchValue, Qt
::CaseInsensitive,
QRegExp::FixedString));
proxyModel->setFilterKeyColumn(-1);
connect(ui
->lineEdit_search_clients,
SIGNAL(textChanged
(QString)),
proxyModel,
SLOT(setFilterFixedString
(QString)));
connect(ui
->lineEdit_search_clients,
SIGNAL(textChanged
(QString)),
ui->tableView_clients, SLOT(setModel(proxyModel)));
model->setQuery("SELECT ROWID, ClientName, ClientCity, ClientEik FROM clients");
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("RowID"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Name"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("City"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("ID"));
ui->tableView_clients->setModel(proxyModel);
//ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,30);
ui->tableView_clients->setColumnWidth(1,170);
ui->tableView_clients->setColumnWidth(2,100);
ui->tableView_clients->setColumnWidth(3,70);
ui
->tableView_clients
->horizontalHeader
()->setResizeMode
(QHeaderView::Interactive);
ui->tableView_clients->horizontalHeader()->setStretchLastSection(true);
ui->tableView_clients->show();
}
void Clients::updateCleintTable()
{
QString searchValue = ui->lineEdit_search_clients->text();
QSqlQueryModel *model=new QSqlQueryModel(this);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(model);
proxyModel->setFilterRegExp(QRegExp(searchValue, Qt::CaseInsensitive, QRegExp::FixedString));
proxyModel->setFilterKeyColumn(-1);
connect(ui->lineEdit_search_clients, SIGNAL(textChanged(QString)),
proxyModel, SLOT(setFilterFixedString(QString)));
connect(ui->lineEdit_search_clients, SIGNAL(textChanged(QString)),
ui->tableView_clients, SLOT(setModel(proxyModel)));
model->setQuery("SELECT ROWID, ClientName, ClientCity, ClientEik FROM clients");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("RowID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("City"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("ID"));
ui->tableView_clients->setModel(proxyModel);
//ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,30);
ui->tableView_clients->setColumnWidth(1,170);
ui->tableView_clients->setColumnWidth(2,100);
ui->tableView_clients->setColumnWidth(3,70);
ui->tableView_clients->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
ui->tableView_clients->horizontalHeader()->setStretchLastSection(true);
ui->tableView_clients->show();
}
To copy to clipboard, switch view to plain text mode
void Clients::on_pushButton_select_clicked()
{
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
int selected_row;
int i=0;
selected_row=selectedList.at(i).row();
mod->setQuery("SELECT * FROM clients");
QString ClientName
= mod
->data
(mod
->index
(selected_row,
0)).
toString();
QString ClientCity
= mod
->data
(mod
->index
(selected_row,
1)).
toString();
QString ClientAddress
= mod
->data
(mod
->index
(selected_row,
2)).
toString();
QString ClientMol
= mod
->data
(mod
->index
(selected_row,
3)).
toString();
QString ClientEik
= mod
->data
(mod
->index
(selected_row,
4)).
toString();
QString ClientVat
= mod
->data
(mod
->index
(selected_row,
5)).
toString();
//QMessageBox::information(this,"", ClientMol);
emit selectedName(ClientName);
emit selectedCity(ClientCity);
emit selectedAddress(ClientAddress);
emit selectedMol(ClientMol);
emit selectedEik(ClientEik);
emit selectedVat(ClientVat);
//emit selectedRaw(QString::number(ClientId));
this->close();
}
void Clients::on_pushButton_select_clicked()
{
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
QSqlQueryModel *mod=new QSqlQueryModel(this);
int selected_row;
int i=0;
selected_row=selectedList.at(i).row();
mod->setQuery("SELECT * FROM clients");
QString ClientName = mod->data(mod->index(selected_row, 0)).toString();
QString ClientCity = mod->data(mod->index(selected_row, 1)).toString();
QString ClientAddress = mod->data(mod->index(selected_row, 2)).toString();
QString ClientMol = mod->data(mod->index(selected_row, 3)).toString();
QString ClientEik = mod->data(mod->index(selected_row, 4)).toString();
QString ClientVat = mod->data(mod->index(selected_row, 5)).toString();
//QMessageBox::information(this,"", ClientMol);
emit selectedName(ClientName);
emit selectedCity(ClientCity);
emit selectedAddress(ClientAddress);
emit selectedMol(ClientMol);
emit selectedEik(ClientEik);
emit selectedVat(ClientVat);
//emit selectedRaw(QString::number(ClientId));
this->close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks