void NumberFieldWizard::loadField(const int fieldId, const int collectionId) { AbstractFieldWizard::loadField(fieldId, collectionId); MetadataEngine *meta = &MetadataEngine::getInstance(); //display properties QString displayProperties = meta->getFieldProperties(meta->DisplayProperty, fieldId, collectionId); MetadataPropertiesParser displayParser(displayProperties); if (displayParser.size()) { if (displayParser.getValue("markNegative") == "1") ui->markNegativeCheckBox->setChecked(true); ui->precisionSpinBox->setValue(displayParser.getValue("precision").toInt()); //display mode QString m = displayParser.getValue("displayMode"); if (m == QString("auto")) ui->notationComboBox->setCurrentIndex(0); else if (m == QString("decimal")) ui->notationComboBox->setCurrentIndex(1); else if (m == QString("scientific")) ui->notationComboBox->setCurrentIndex(2); } //edit properties QString editProperties = meta->getFieldProperties(meta->EditProperty, fieldId, collectionId); MetadataPropertiesParser editParser(editProperties); if (editParser.size()) { if (editParser.getValue("noEmpty") == "1") ui->requiredFieldCheckBox->setChecked(true); } }
void ComboboxFieldWizard::loadField(const int fieldId, const int collectionId) { AbstractFieldWizard::loadField(fieldId, collectionId); MetadataEngine *meta = &MetadataEngine::getInstance(); //display properties QString displayProperties = meta->getFieldProperties(meta->DisplayProperty, fieldId, collectionId); MetadataPropertiesParser displayParser(displayProperties); if (displayParser.getValue("markEmpty") == "1") ui->requiredFieldCheckBox->setChecked(true); //get items if (displayProperties.size()) { QStringList items = displayParser.getValue("items") .split(',', QString::SkipEmptyParts); foreach (QString s, items) { //replace some escape codes s.replace("\\comma", ","); s.replace("\\colon", ":"); s.replace("\\semicolon", ";"); QListWidgetItem *item = new QListWidgetItem(s, ui->itemsListWidget); item->setFlags(item->flags() | Qt::ItemIsEditable); }
void CreationDateFieldWizard::loadField(const int fieldId, const int collectionId) { AbstractFieldWizard::loadField(fieldId, collectionId); MetadataEngine *meta = &MetadataEngine::getInstance(); //display properties QString displayProperties = meta->getFieldProperties(meta->DisplayProperty, fieldId, collectionId); MetadataPropertiesParser displayParser(displayProperties); if (displayParser.size()) { //date format int f = displayParser.getValue("dateFormat").toInt(); if (f) ui->dateFormatBox->setCurrentIndex(f-1); } }
void DateFormWidget::editingFinishedSlot() { //Get current field id (column) and record id int fieldId = -1; int recordId = -1; FormView *view = nullptr; QWidget *parent = parentWidget(); if (parent) view = qobject_cast<FormView*>(parent->parentWidget()); if (view) { int row = view->getCurrentRow(); fieldId = view->getCurrentColumn(); if (row != -1) { bool ok; int i = view->model()->data(view->model()->index(row, 0)).toInt(&ok); if (ok) recordId = i; } } //check if alarm trigger property is enabled //if it is, update alarm trigger in alarms table if (fieldId != -1) { MetadataEngine *meta = &MetadataEngine::getInstance(); MetadataPropertiesParser parser(meta->getFieldProperties( MetadataEngine::TriggerProperty, fieldId)); if (parser.size() > 0) { bool alarmTrigger = parser.getValue("alarmOnDate") == "1"; //add or update alarm if ((recordId != -1) && (alarmTrigger)) { QDateTime dateTime(m_dateTimeEdit->dateTime()); AlarmManager a(this); a.addOrUpdateAlarm(meta->getCurrentCollectionId(), fieldId, recordId, dateTime); } } } //save validateData(); }
void AbstractFieldWizard::createField(MetadataEngine::FieldType fieldType, EditMode mode) { MetadataEngine *meta = &MetadataEngine::getInstance(); int fieldId = m_fieldId; QString displayProperties; QString editProperties; QString triggerProperties; //if mode is modify field, //keep old properties for undo QString oldDisplayProperties; QString oldEditProperties; QString oldTriggerProperties; QString oldFieldName; //collection id must be valid, if not specified if (m_collectionId == 0) m_collectionId = MetadataEngine::getInstance().getCurrentCollectionId(); //get field properties getFieldProperties(displayProperties, editProperties, triggerProperties); if (mode == AbstractFieldWizard::NewEditMode) { fieldId = meta->createField(m_fieldName, fieldType, displayProperties, editProperties, triggerProperties); } else if (mode == AbstractFieldWizard::ModifyEditMode) { //save old properties for undo oldDisplayProperties = meta->getFieldProperties( MetadataEngine::DisplayProperty, fieldId, m_collectionId); oldEditProperties = meta->getFieldProperties( MetadataEngine::EditProperty, fieldId, m_collectionId); oldTriggerProperties = meta->getFieldProperties( MetadataEngine::TriggerProperty, fieldId, m_collectionId); oldFieldName = meta->getFieldName(fieldId, m_collectionId); meta->modifyField(fieldId, m_fieldName, displayProperties, editProperties, triggerProperties); } else if (mode == AbstractFieldWizard::DuplicateEditMode) { fieldId = meta->createField(m_fieldName, fieldType, displayProperties, editProperties, triggerProperties); } //set local data changed SyncSession::LOCAL_DATA_CHANGED = true; //create undo action QUndoStack *stack = MainWindow::getUndoStack(); if (stack) { QUndoCommand *command; if (mode == ModifyEditMode) { command = new ModFieldCommand(m_collectionId, fieldId, oldFieldName, oldDisplayProperties, oldEditProperties, oldTriggerProperties, m_fieldName, displayProperties, editProperties, triggerProperties); } else { //new or duplicate AddFieldCommand::FieldOperation op; if (mode == NewEditMode) op = AddFieldCommand::AddField; else op = AddFieldCommand::DuplicateField; command = new AddFieldCommand(m_collectionId, fieldId, op, m_fieldName, fieldType, displayProperties, editProperties, triggerProperties); } stack->push(command); } }