示例#1
0
void
CustomerMaster::slotRenameData()
{
    int row = _extra->currentRow();
    if (row == -1) return;

    Id extra_id = _extra->cellValue(row, 0).toId();
    if (extra_id == INVALID_ID) return;

    Extra extra;
    if (!_quasar->db()->lookup(extra_id, extra)) {
        QMessageBox::critical(this, tr("Error"), tr("Data lookup failed."));
        return;
    }

    bool ok = false;
    QString message = tr("Enter the new name for %1:").arg(extra.name());
    QString text = QInputDialog::getText(tr("Rename Data"), message,
                                         QLineEdit::Normal, QString::null,
                                         &ok, this);
    if (!ok || text.isEmpty()) return;

    Extra orig = extra;
    extra.setName(text);
    if (!_quasar->db()->update(orig, extra)) {
        QMessageBox::critical(this, tr("Error"), tr("Renaming data failed."));
        return;
    }

    _extra->setCellValue(row, 0, extra.id());
}
示例#2
0
void
CustomerMaster::slotDeleteData()
{
    int row = _extra->currentRow();
    if (row == -1) return;

    Id extra_id = _extra->cellValue(row, 0).toId();
    if (extra_id == INVALID_ID) return;

    Extra extra;
    if (!_quasar->db()->lookup(extra_id, extra)) {
        QMessageBox::critical(this, tr("Error"), tr("Data lookup failed."));
        return;
    }

    QString message = tr("Are you sure you want to delete the\n"
                         "%1 data?  It will be removed from\nall items.").arg(extra.name());
    int choice = QMessageBox::warning(this, tr("Delete?"), message,
                                      QMessageBox::No, QMessageBox::Yes);
    if (choice != QMessageBox::Yes)
        return;

    if (!_quasar->db()->remove(extra)) {
        QMessageBox::critical(this, tr("Error"), tr("Deleting data failed."));
        return;
    }

    _extra->deleteRow(row);
}
示例#3
0
QString
ExtraLookup::lookupById(Id extra_id)
{
    Extra extra;
    if (extra_id != INVALID_ID && _quasar->db()->lookup(extra_id, extra))
	return extra.name();
    return "";
}