CREATE TABLE IF NOT EXISTS `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`customerId` int(11) NOT NULL,
`industryId` int(11) DEFAULT NULL,
`opCode` varchar(255) DEFAULT NULL,
`statusId` int(11) DEFAULT NULL,
`startDate` date DEFAULT NULL,
`endDate` date DEFAULT NULL,
`notes` text,
PRIMARY KEY (`id`),
UNIQUE KEY `opCode` (`opCode`),
KEY `customerId` (`customerId`),
KEY `status` (`statusId`),
KEY `industryId` (`industryId`),
KEY `customerId_2` (`customerId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=39 ;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
// SETUP THE TABLE
projectsModel.setTable("Projects");
projectsModel.
setRelation(1,
QSqlRelation("Customers",
"id",
"name"));
projectsModel.
setRelation(2,
QSqlRelation("refIndustries",
"naicCode",
"name"));
projectsModel.
setRelation(4,
QSqlRelation("refStatuses",
"id",
"name"));
projectsModel.select();
mapper->setModel(projectModel);
mapper->addMapping(ui->customerNameLineEdit, projectModel->fieldIndex("Customers_Name"));
mapper->addMapping(ui->industryComboBox, projectModel->fieldIndex("refIndustries_name"));
mapper->addMapping(ui->projectCodeLineEdit, projectModel->fieldIndex("opCode"));
mapper->addMapping(ui->statusComboBox, projectModel->fieldIndex("refStatuses_name"));
mapper->addMapping(ui->startDateDateEdit, projectModel->fieldIndex("startDate"));
mapper->addMapping(ui->endDateDateEdit, projectModel->fieldIndex("endDate"));
mapper->addMapping(ui->notesTextEdit, projectModel->fieldIndex("notes"));
mapper->setCurrentIndex(rowId);
// LATER I DO A SUBMIT LIKE THIS
mapper->submit())
projectModel->submitAll()
CREATE TABLE IF NOT EXISTS `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`customerId` int(11) NOT NULL,
`industryId` int(11) DEFAULT NULL,
`opCode` varchar(255) DEFAULT NULL,
`statusId` int(11) DEFAULT NULL,
`startDate` date DEFAULT NULL,
`endDate` date DEFAULT NULL,
`notes` text,
PRIMARY KEY (`id`),
UNIQUE KEY `opCode` (`opCode`),
KEY `customerId` (`customerId`),
KEY `status` (`statusId`),
KEY `industryId` (`industryId`),
KEY `customerId_2` (`customerId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=39 ;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
// SETUP THE TABLE
projectsModel.setTable("Projects");
projectsModel.setRelation(1, QSqlRelation("Customers", "id", "name"));
projectsModel.setRelation(2, QSqlRelation("refIndustries", "naicCode", "name"));
projectsModel.setRelation(4, QSqlRelation("refStatuses", "id", "name"));
projectsModel.select();
mapper = new QDataWidgetMapper(this);
mapper->setModel(projectModel);
mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));
mapper->addMapping(ui->customerNameLineEdit, projectModel->fieldIndex("Customers_Name"));
mapper->addMapping(ui->industryComboBox, projectModel->fieldIndex("refIndustries_name"));
mapper->addMapping(ui->projectCodeLineEdit, projectModel->fieldIndex("opCode"));
mapper->addMapping(ui->statusComboBox, projectModel->fieldIndex("refStatuses_name"));
mapper->addMapping(ui->startDateDateEdit, projectModel->fieldIndex("startDate"));
mapper->addMapping(ui->endDateDateEdit, projectModel->fieldIndex("endDate"));
mapper->addMapping(ui->notesTextEdit, projectModel->fieldIndex("notes"));
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setCurrentIndex(rowId);
// LATER I DO A SUBMIT LIKE THIS
mapper->submit())
projectModel->submitAll()
To copy to clipboard, switch view to plain text mode
Bookmarks