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 ImageTypeEditor::browseButtonClicked() { QString file = QFileDialog::getOpenFileName(this, tr("Import Image"), QDir::homePath(), tr("Images (*.png *.jpeg " "*.jpg *.tiff *.gif *.bmp *.svg)") ); if (file.isEmpty()) return; MetadataEngine *meta = &MetadataEngine::getInstance(); FileManager fm(this); QProgressDialog pd(this); pd.setWindowModality(Qt::WindowModal); pd.setWindowTitle(tr("Importing file")); pd.setLabelText(tr("Copying image file... Please wait!")); pd.setRange(0, 0); pd.setValue(-1); connect(&fm, SIGNAL(addFileCompletedSignal(QString)), this, SLOT(setLastFileHashResult(QString))); connect(&fm, SIGNAL(addFileCompletedSignal(QString)), &pd, SLOT(close())); connect(&fm, SIGNAL(fileOpFailed()), &pd, SLOT(close())); //remove exiting file if (m_currentFileId) { QString fileName, hashName; QDateTime dateAdded; meta->getContentFile(m_currentFileId, fileName, hashName, dateAdded); //if user dragged the image from and to the image label (same image) if (file.contains(hashName)) return; fm.startRemoveFile(hashName); } //add file fm.startAddFile(file); //wait until file has been copied pd.exec(); //set data m_currentFileId = meta->getContentFileId(m_lastFileHashResult); m_browseButton->setIcon(QPixmap(fm.getFilesDirectory() + m_lastFileHashResult)); //close editor emit editingFinished(); }
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); } }