#ifndef WHOLENAMEDLG_H
#define WHOLENAMEDLG_H
.... snip includes ..........
#include "ui_wholenamedlg.h"
class wholenamedlg
: public QDialog{
Q_OBJECT
public:
private:
Ui::wholeNameDlgUI wnui;
private slots:
};
#endif
#ifndef WHOLENAMEDLG_H
#define WHOLENAMEDLG_H
.... snip includes ..........
#include "ui_wholenamedlg.h"
class wholenamedlg : public QDialog
{
Q_OBJECT
public:
wholenamedlg(QWidget *parent = 0, QString partName = "", QString strYear = "2006", QString strSpouseFlag = "F");
QString resultSSN;
QString resultPropID;
QTableView wholeNameView;
private:
Ui::wholeNameDlgUI wnui;
private slots:
void copyVALUES(const QModelIndex &);
};
#endif
To copy to clipboard, switch view to plain text mode
"wholeNameDlgUI" is the name given to the dialog during the Designer session.
/*
Program: wholenamedlg.cpp
Description: A dialog class for picking an SSN and/or a name out of
a query created by the SQL LIKE % syntax.
Author: Jerry L Kreps
Date: 11/10/05 - ff
*/
#include "wholenamedlg.h"
... snip includes ......
{
wnui.setupUi(this);
partName.prepend("'");
partName.append("'");
QString queryStr
= "SELECT proprty_id,ssn,wholename,sssn,sname,city,address FROM persinfo_";
queryStr.append(strYear);
if (strSpouseFlag == "F") {
queryStr.append(" WHERE wholename LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY wholename");
} else {
queryStr.append(" WHERE sname LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY sname");
}
viewModel->setHeaderData(0, Qt::Horizontal, "ID");
viewModel->setHeaderData(1, Qt::Horizontal, "SSN");
viewModel->setHeaderData(2, Qt::Horizontal, "WholeName");
viewModel->setHeaderData(3, Qt::Horizontal, "SSSN");
viewModel->setHeaderData(4, Qt::Horizontal, "SName");
viewModel->setHeaderData(5, Qt::Horizontal, "City");
viewModel->setHeaderData(6, Qt::Horizontal, "Address");
viewModel->setQuery(queryStr);
if (viewModel
->lastError
().
type() == QSqlError::NoError){ wnui.wholeNameView->setModel(viewModel);
if (viewModel->rowCount() > 0){
for (int i = 0; i < viewModel->rowCount(); ++i)
this->wnui.wholeNameView->verticalHeader()->resizeSection(i,20);
for (int i = 0; i < 7; ++i)
wnui.wholeNameView->resizeColumnToContents(i);
}
}
}
void wholenamedlg
::copyVALUES(const QModelIndex &QMI
) { QVariant value
= this
->wnui.
wholeNameView->model
()->data
(QMI,
0);
if (value.isValid()) {
if (QMI.column() == 0)
this->resultPropID = value.toString();
if (QMI.column() == 1)
this->resultSSN = value.toString();
}
}
/*
Program: wholenamedlg.cpp
Description: A dialog class for picking an SSN and/or a name out of
a query created by the SQL LIKE % syntax.
Author: Jerry L Kreps
Date: 11/10/05 - ff
*/
#include "wholenamedlg.h"
... snip includes ......
wholenamedlg::wholenamedlg(QWidget *parent, QString partName, QString strYear, QString strSpouseFlag)
: QDialog(parent)
{
wnui.setupUi(this);
connect(this->wnui.wholeNameView, SIGNAL(clicked(QModelIndex)), this, SLOT(copyVALUES( QModelIndex )));
partName.prepend("'");
partName.append("'");
QString queryStr = "SELECT proprty_id,ssn,wholename,sssn,sname,city,address FROM persinfo_";
queryStr.append(strYear);
if (strSpouseFlag == "F") {
queryStr.append(" WHERE wholename LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY wholename");
} else {
queryStr.append(" WHERE sname LIKE ");
queryStr.append(partName);
queryStr.append(" ORDER BY sname");
}
QSqlQueryModel *viewModel = new QSqlQueryModel(wnui.wholeNameView);
viewModel->setHeaderData(0, Qt::Horizontal, "ID");
viewModel->setHeaderData(1, Qt::Horizontal, "SSN");
viewModel->setHeaderData(2, Qt::Horizontal, "WholeName");
viewModel->setHeaderData(3, Qt::Horizontal, "SSSN");
viewModel->setHeaderData(4, Qt::Horizontal, "SName");
viewModel->setHeaderData(5, Qt::Horizontal, "City");
viewModel->setHeaderData(6, Qt::Horizontal, "Address");
viewModel->setQuery(queryStr);
if (viewModel->lastError().type() == QSqlError::NoError){
wnui.wholeNameView->setModel(viewModel);
if (viewModel->rowCount() > 0){
for (int i = 0; i < viewModel->rowCount(); ++i)
this->wnui.wholeNameView->verticalHeader()->resizeSection(i,20);
for (int i = 0; i < 7; ++i)
wnui.wholeNameView->resizeColumnToContents(i);
}
}
}
void wholenamedlg::copyVALUES(const QModelIndex &QMI) {
QVariant value = this->wnui.wholeNameView->model()->data(QMI,0);
if (value.isValid()) {
if (QMI.column() == 0)
this->resultPropID = value.toString();
if (QMI.column() == 1)
this->resultSSN = value.toString();
}
}
To copy to clipboard, switch view to plain text mode
"wholeNameView" is the name given in the Designer to the tableview grid containing the data being displayed.
/*
Program: homestead.cpp
Description: Homestead Application Program (HAP)
Author: Jerry L Kreps
Date: 11/1/2005
*/
#include "homestead.h"
#include "wholenamedlg.h"
...
// homestead constructor method
ui.setupUi(this); // draw the gui interface
this->Year65 = 1940; // set birth year for 65 year olds
this->dbYear = "2006";
...
connect(ui.btnSearch, SIGNAL(clicked()), this, SLOT(searchAll()));
...
...
} // end of the homestead constructor
void homestead::searchAll() {
// user enters value to search for in search text box
// and clicks the radio button indicating its data type
// then clicks the search button
bool foundProp = false;
bool foundPers = false;
QString seekWN
= "'";
// set up for possible wholename search requestString = "Searching for: ";
requestString.append(ui.leSearch->text()); // echo search request
if (ui.rbWholeName->isChecked()) {
QString partialName
= ui.
leSearch->text
().
trimmed();
if (partialName.contains('%')){
//select proprty_id,ssn,wholename,sssn,sname,city,address from persinfo_2006
//WHERE wholename LIKE 'MILLER/E%' ORDER BY wholename
wholenamedlg dlg(this, partialName, this->dbYear, "F");
if( dlg.
exec() == QDialog::Accepted ){ QString strSSN
= dlg.
resultSSN.
trimmed();
QString strPropID
= dlg.
resultPropID.
trimmed();
// was ssn returned from dialog ?
.....
..... snip lot's of code .....
.....
/*
Program: homestead.cpp
Description: Homestead Application Program (HAP)
Author: Jerry L Kreps
Date: 11/1/2005
*/
#include "homestead.h"
#include "wholenamedlg.h"
...
homestead::homestead(QWidget *parent) : QMainWindow(parent) {
// homestead constructor method
ui.setupUi(this); // draw the gui interface
this->Year65 = 1940; // set birth year for 65 year olds
this->dbYear = "2006";
...
connect(ui.btnSearch, SIGNAL(clicked()), this, SLOT(searchAll()));
...
...
} // end of the homestead constructor
void homestead::searchAll() {
// user enters value to search for in search text box
// and clicks the radio button indicating its data type
// then clicks the search button
bool foundProp = false;
bool foundPers = false;
QString queryStr = "";
QString seekWN = "'"; // set up for possible wholename search
QString requestString;
requestString = "Searching for: ";
requestString.append(ui.leSearch->text()); // echo search request
if (ui.rbWholeName->isChecked()) {
QString partialName = ui.leSearch->text().trimmed();
if (partialName.contains('%')){
//select proprty_id,ssn,wholename,sssn,sname,city,address from persinfo_2006
//WHERE wholename LIKE 'MILLER/E%' ORDER BY wholename
wholenamedlg dlg(this, partialName, this->dbYear, "F");
if( dlg.exec() == QDialog::Accepted ){
QString strSSN = dlg.resultSSN.trimmed();
QString strPropID = dlg.resultPropID.trimmed();
// was ssn returned from dialog ?
.....
..... snip lot's of code .....
.....
To copy to clipboard, switch view to plain text mode
Here is what the dialog looks like in action:
Bookmarks