qtmobility/tools/qcrmlgen/qcrmlgen.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
   119     QLineEdit *editor = new QLineEdit(parent);
   119     QLineEdit *editor = new QLineEdit(parent);
   120     QTableWidgetItem *item = m_parentTable->currentItem();
   120     QTableWidgetItem *item = m_parentTable->currentItem();
   121     if (!item->text().isEmpty()) {
   121     if (!item->text().isEmpty()) {
   122         editor->setText(item->text());
   122         editor->setText(item->text());
   123     }
   123     }
   124     QRegExpValidator *validator = new QRegExpValidator(QRegExp("([0-9]|[A-F]|[a-f]){1,8}"), editor);
   124     QRegExpValidator *validator =
       
   125         new QRegExpValidator(QRegExp(QLatin1String("([0-9]|[A-F]|[a-f]){1,8}")), editor);
   125     editor->setValidator(validator);
   126     editor->setValidator(validator);
   126 
   127 
   127     return editor;
   128     return editor;
   128 }
   129 }
   129 
   130 
   158     QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
   159     QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
   159     m_parentTable->item(index.row(), index.column())->setText(lineEdit->text());
   160     m_parentTable->item(index.row(), index.column())->setText(lineEdit->text());
   160 }
   161 }
   161 
   162 
   162 EditorWidget::EditorWidget():m_isModified(false) {
   163 EditorWidget::EditorWidget():m_isModified(false) {
   163     m_RPropRadio = new QRadioButton("RProperty");
   164     m_RPropRadio = new QRadioButton(QLatin1String("RProperty"));
   164     m_CRepRadio = new QRadioButton("CRepository");
   165     m_CRepRadio = new QRadioButton(QLatin1String("CRepository"));
   165     QButtonGroup *targetGroup = new QButtonGroup(this);
   166     QButtonGroup *targetGroup = new QButtonGroup(this);
   166     targetGroup->addButton(m_CRepRadio);
   167     targetGroup->addButton(m_CRepRadio);
   167     targetGroup->addButton(m_RPropRadio);
   168     targetGroup->addButton(m_RPropRadio);
   168     targetGroup->setExclusive(true);
   169     targetGroup->setExclusive(true);
   169     connect(targetGroup, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(targetChanged(QAbstractButton *)));
   170     connect(targetGroup, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(targetChanged(QAbstractButton *)));
   171     QHBoxLayout *targetLayout = new QHBoxLayout;
   172     QHBoxLayout *targetLayout = new QHBoxLayout;
   172     targetLayout->addWidget(m_RPropRadio);
   173     targetLayout->addWidget(m_RPropRadio);
   173     targetLayout->addWidget(m_CRepRadio);
   174     targetLayout->addWidget(m_CRepRadio);
   174 
   175 
   175     m_RPropRadio->setChecked(true);
   176     m_RPropRadio->setChecked(true);
   176     m_repoLabel = new QLabel("Category ID", this);
   177     m_repoLabel = new QLabel(tr("Category ID"), this);
   177     m_repoUID = new QLineEdit(this);
   178     m_repoUID = new QLineEdit(this);
   178     QRegExpValidator *validator = new QRegExpValidator(QRegExp("([0-9]|[A-F]|[a-f]){1,8}"), this);
   179     QRegExpValidator *validator =
       
   180         new QRegExpValidator(QRegExp(QLatin1String("([0-9]|[A-F]|[a-f]){1,8}")), this);
   179     m_repoUID->setValidator(validator);
   181     m_repoUID->setValidator(validator);
   180     connect(m_repoUID, SIGNAL(textEdited(const QString &)), this, SLOT(setModified()));
   182     connect(m_repoUID, SIGNAL(textEdited(const QString &)), this, SLOT(setModified()));
   181     m_repoUID->setToolTip("Must be a hexidecimal number no longer than  8 digits");
   183     m_repoUID->setToolTip(tr("Must be a hexidecimal number no longer than 8 digits"));
   182 
   184 
   183     QHBoxLayout *repoLayout = new QHBoxLayout;
   185     QHBoxLayout *repoLayout = new QHBoxLayout;
   184     repoLayout->addWidget(m_repoLabel);
   186     repoLayout->addWidget(m_repoLabel);
   185     repoLayout->addWidget(m_repoUID);
   187     repoLayout->addWidget(m_repoUID);
   186 
   188 
   239     int row = m_tableWidget->rowCount();
   241     int row = m_tableWidget->rowCount();
   240     m_tableWidget->insertRow(row);
   242     m_tableWidget->insertRow(row);
   241 
   243 
   242     QTableWidgetItem *item;
   244     QTableWidgetItem *item;
   243     item = new QTableWidgetItem;
   245     item = new QTableWidgetItem;
   244     item->setToolTip("Must be a hexidecimal number no longer than 8 digits");
   246     item->setToolTip(tr("Must be a hexidecimal number no longer than 8 digits"));
   245     m_tableWidget->setItem(row, EditorWidget::KeyId, item);
   247     m_tableWidget->setItem(row, EditorWidget::KeyId, item);
   246 
   248 
   247     item = new QTableWidgetItem("/");
   249     item = new QTableWidgetItem(QLatin1String("/"));
   248     item->setToolTip("Must not be empty and must start with a /");
   250     item->setToolTip(tr("Must not be empty and must start with a /"));
   249     m_tableWidget->setItem(row, EditorWidget::Path, item);
   251     m_tableWidget->setItem(row, EditorWidget::Path, item);
   250 
   252 
   251 #ifdef INCL_TYPE
   253 #ifdef INCL_TYPE
   252     item = new QTableWidgetItem("int");
   254     item = new QTableWidgetItem(tr("int"));
   253     m_tableWidget->setItem(row, EditorWidget::Type, item);
   255     m_tableWidget->setItem(row, EditorWidget::Type, item);
   254 #endif
   256 #endif
   255 
   257 
   256     setModified(true);
   258     setModified(true);
   257 }
   259 }
   291     QString keyId;
   293     QString keyId;
   292     QString path;
   294     QString path;
   293 #ifdef INCL_TYPE
   295 #ifdef INCL_TYPE
   294     QString type;
   296     QString type;
   295 #endif
   297 #endif
   296     QString documentStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
   298     QString documentStart(QLatin1String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
   297     file.write(documentStart.toUtf8());
   299     file.write(documentStart.toUtf8());
   298 
   300 
   299     QString repositoryElementStart("<repository target=\"%1\" uidValue=\"0x%2\">\n");
   301     QString repositoryElementStart(QLatin1String("<repository target=\"%1\" uidValue=\"0x%2\">\n"));
   300     QString target = m_RPropRadio->isChecked()?"RProperty":"CRepository";
   302     QString target = m_RPropRadio->isChecked() ? QLatin1String("RProperty") : QLatin1String("CRepository");
   301     file.write(repositoryElementStart.arg(target).arg(repoUID).toUtf8());
   303     file.write(repositoryElementStart.arg(target).arg(repoUID).toUtf8());
   302 #ifdef INCL_TYPE
   304 #ifdef INCL_TYPE
   303     QString keyElementStart("    <key int=\"0x%1\" type=\"%2\" ref=\"%3\">\n");
   305     QString keyElementStart(QLatin1String("    <key int=\"0x%1\" type=\"%2\" ref=\"%3\">\n"));
   304 #else
   306 #else
   305 
   307     QString keyElementStart(QLatin1String("    <key int=\"0x%1\" ref=\"%2\">\n"));
   306     QString keyElementStart("    <key int=\"0x%1\" ref=\"%2\">\n");
   308 #endif
   307 #endif
   309     QString keyElementEnd(QLatin1String("    </key>\n"));
   308     QString keyElementEnd("    </key>\n");
       
   309 
   310 
   310     for(int i=0; i < m_tableWidget->rowCount(); i++) {
   311     for(int i=0; i < m_tableWidget->rowCount(); i++) {
   311         keyId = m_tableWidget->item(i, EditorWidget::KeyId)->text();
   312         keyId = m_tableWidget->item(i, EditorWidget::KeyId)->text();
   312         path = m_tableWidget-> item(i, EditorWidget::Path)->text().remove(0,1);
   313         path = m_tableWidget-> item(i, EditorWidget::Path)->text().remove(0,1);
   313 #ifdef INCL_TYPE
   314 #ifdef INCL_TYPE
   318 #endif
   319 #endif
   319 
   320 
   320         file.write(keyElementEnd.toUtf8());
   321         file.write(keyElementEnd.toUtf8());
   321     }
   322     }
   322 
   323 
   323     QString repositoryElementEnd("</repository>\n");
   324     QString repositoryElementEnd(QLatin1String("</repository>\n"));
   324     file.write(repositoryElementEnd.toUtf8());
   325     file.write(repositoryElementEnd.toUtf8());
   325     file.close();
   326     file.close();
   326     setModified(false);
   327     setModified(false);
   327 }
   328 }
   328 
   329 
   412         }
   413         }
   413     }
   414     }
   414 
   415 
   415     QString repoUID = m_repoUID->text();
   416     QString repoUID = m_repoUID->text();
   416     if (!checkID(repoUID)) {
   417     if (!checkID(repoUID)) {
   417         QMessageBox::warning(this, "Invalid input", m_repoLabel->text() + "field is invalid, it must be a hexidecimal number no longer than 8 digits");
   418         QMessageBox::warning(this, tr("Invalid input"),
       
   419                              tr("The '%1' field is invalid, "
       
   420                                 "it must be a hexidecimal number no longer than 8 digits.")
       
   421                              .arg(m_repoLabel->text()));
   418         m_repoUID->setFocus();
   422         m_repoUID->setFocus();
   419         return false;
   423         return false;
   420     }
   424     }
   421 
   425 
   422     QString keyId;
   426     QString keyId;
   433             m_tableWidget->setFocus();
   437             m_tableWidget->setFocus();
   434             return false;
   438             return false;
   435         }
   439         }
   436 
   440 
   437         path = m_tableWidget->item(i, EditorWidget::Path)->text();
   441         path = m_tableWidget->item(i, EditorWidget::Path)->text();
   438         if (path.isEmpty() || !path.startsWith("/")) {
   442         if (path.isEmpty() || !path.startsWith(QLatin1Char('/'))) {
   439             QMessageBox::warning(this, tr("Invalid Path"),
   443             QMessageBox::warning(this, tr("Invalid Path"),
   440                             tr("The Key Path field is invalid, it must not be empty and start with a /"));
   444                             tr("The Key Path field is invalid, it must not be empty and start with a /"));
   441             m_tableWidget->setCurrentCell(i, EditorWidget::Path);
   445             m_tableWidget->setCurrentCell(i, EditorWidget::Path);
   442             m_tableWidget->setFocus();
   446             m_tableWidget->setFocus();
   443             return false;
   447             return false;
   499 }
   503 }
   500 
   504 
   501 void EditorWidget::targetChanged(QAbstractButton *button)
   505 void EditorWidget::targetChanged(QAbstractButton *button)
   502 {
   506 {
   503     if (button == m_RPropRadio)
   507     if (button == m_RPropRadio)
   504         m_repoLabel->setText("Category ID");
   508         m_repoLabel->setText(tr("Category ID"));
   505     else
   509     else
   506         m_repoLabel->setText("Repository ID");
   510         m_repoLabel->setText(tr("Repository ID"));
   507 }
   511 }
   508 
   512 
   509 QCrmlGenerator::QCrmlGenerator()
   513 QCrmlGenerator::QCrmlGenerator()
   510 {
   514 {
   511     QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
   515     QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
   569 
   573 
   570 void QCrmlGenerator::saveFileAs()
   574 void QCrmlGenerator::saveFileAs()
   571 {
   575 {
   572     if (m_editorWidget->verifyContents()) {
   576     if (m_editorWidget->verifyContents()) {
   573         QFileDialog saveDialog(this, tr("Save As"), QString(), tr("QCrml (*.qcrml);;Any Files (*)"));
   577         QFileDialog saveDialog(this, tr("Save As"), QString(), tr("QCrml (*.qcrml);;Any Files (*)"));
   574         saveDialog.setDefaultSuffix("qcrml");
   578         saveDialog.setDefaultSuffix(QLatin1String("qcrml"));
   575         saveDialog.setFileMode(QFileDialog::AnyFile);
   579         saveDialog.setFileMode(QFileDialog::AnyFile);
   576         saveDialog.setAcceptMode(QFileDialog::AcceptSave);
   580         saveDialog.setAcceptMode(QFileDialog::AcceptSave);
   577         if (saveDialog.exec() == QDialog::Accepted) {
   581         if (saveDialog.exec() == QDialog::Accepted) {
   578             if (saveDialog.selectedFiles().count() > 0) {
   582             if (saveDialog.selectedFiles().count() > 0) {
   579             m_saveFile = saveDialog.selectedFiles().at(0);
   583             m_saveFile = saveDialog.selectedFiles().at(0);