Пример #1
0
XmlDomDocument::XmlDomDocument(const QByteArray& xmlFileContent, const FilePath& filepath) throw (Exception) :
    mFilePath(filepath), mRootElement(nullptr)
{
    QDomDocument doc;
    doc.implementation().setInvalidDataPolicy(QDomImplementation::ReturnNullNode);

    QString errMsg;
    int errLine;
    int errColumn;
    if (!doc.setContent(xmlFileContent, &errMsg, &errLine, &errColumn))
    {
        QString line = xmlFileContent.split('\n').at(errLine-1);
        throw RuntimeError(__FILE__, __LINE__, QString("%1: %2 [%3:%4] LINE:%5")
            .arg(filepath.toStr(), errMsg).arg(errLine).arg(errColumn).arg(line),
            QString(tr("Error while parsing XML in file \"%1\": %2 [%3:%4]"))
            .arg(filepath.toNative(), errMsg).arg(errLine).arg(errColumn));
    }

    // check if the root node exists
    QDomElement root = doc.documentElement();
    if (root.isNull())
    {
        throw RuntimeError(__FILE__, __LINE__, QString(),
            QString(tr("No XML root node found in \"%1\"!")).arg(/*xmlFilePath.toNative()*/QString()));
    }

    mRootElement = XmlDomElement::fromQDomElement(root, this);
}
Пример #2
0
void RecentProjectsModel::setLastRecentProject(const FilePath& filepath)
{
    // if the filepath is already in the list, we just have to move it to the top of the list
    for (int i = 0; i < mRecentProjects.count(); i++)
    {
        if (mRecentProjects.at(i).toStr() == filepath.toStr())
        {
            if (i == 0)
                return; // the filename is already on top of the list, so nothing to do here...

            beginMoveRows(QModelIndex(), i, i, QModelIndex(), 0);
            mRecentProjects.move(i, 0);
            endMoveRows();
            save();
            return;
        }
    }

    // limit the maximum count of entries in the list
    while (mRecentProjects.count() >= 5)
    {
        beginRemoveRows(QModelIndex(), mRecentProjects.count()-1, mRecentProjects.count()-1);
        mRecentProjects.takeLast();
        endRemoveRows();
    }

    // add the new filepath to the list
    beginInsertRows(QModelIndex(), 0, 0);
    mRecentProjects.prepend(filepath);
    endInsertRows();
    save();
}
Пример #3
0
void FabricationOutputDialog::on_btnBrowseOutputDir_clicked() {
  BoardGerberExport grbExport(mBoard, mBoard.getFabricationOutputSettings());
  FilePath          dir = grbExport.getOutputDirectory();
  if (dir.isExistingDir()) {
    QDesktopServices::openUrl(QUrl::fromLocalFile(dir.toStr()));
  } else {
    QMessageBox::warning(this, tr("Warning"), tr("Directory does not exist."));
  }
}
Пример #4
0
TEST_F(DeviceConverterTest, testConversion) {
  FilePath testDataDir(TEST_DATA_DIR "/unittests/eagleimport");

  // load eagle device
  FilePath           eagleLibFp = testDataDir.getPathTo("resistor.lbr");
  parseagle::Library eagleLibrary(eagleLibFp.toStr());
  ASSERT_EQ(1, eagleLibrary.getDeviceSets().count());
  const parseagle::DeviceSet& eagleDeviceSet =
      eagleLibrary.getDeviceSets().first();
  ASSERT_EQ(1, eagleDeviceSet.getDevices().count());
  const parseagle::Device& eagleDevice = eagleDeviceSet.getDevices().first();

  // load converter database
  ConverterDb db(testDataDir.getPathTo("db.ini"));

  // convert device set
  DeviceConverter                  converter(eagleDeviceSet, eagleDevice, db);
  std::unique_ptr<library::Device> device = converter.generate();
}
Пример #5
0
ConverterDb::ConverterDb(const FilePath& ini) noexcept
  : mIniFile(ini.toStr(), QSettings::IniFormat) {
}