Exemple #1
0
TemplatesPrivate::TemplatesPrivate()
{
    qDebug() << "Creating the template engine";
    engine = new Grantlee::Engine();
    engine->addPluginPath(TemplateFilterBaseDir);
    
    // Trims extra whitespace, allowing for more readable templates
    engine->setSmartTrimEnabled(true);
    
    Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr( new Grantlee::FileSystemTemplateLoader() );
    QStringList templateDirs;
    QString base = TemplateDir;
    templateDirs << base + "/cpp";
    templateDirs << base + "/django";
    loader->setTemplateDirs( templateDirs );
    engine->addTemplateLoader( loader );
    
    Common::registerTypes();
    
    Grantlee::registerMetaType<Variable*>();
    Grantlee::registerMetaType<Type*>();
    Grantlee::registerMetaType<Class*>();
    Grantlee::registerMetaType<View*>();
    Grantlee::registerMetaType<Query*>();
    Grantlee::registerMetaType<Function*>();
}
Exemple #2
0
void IDEApplication::initializeTemplates()
{
    mEngine = new Grantlee::Engine(this);
    mEngine->setPluginPaths(QStringList() << QDir(GRANTLEE_PLUGIN_DIR).absolutePath());

    Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr(new Grantlee::FileSystemTemplateLoader);
    loader->setTemplateDirs(QStringList() << ":/templates");
    mEngine->addTemplateLoader(loader);
}
Exemple #3
0
TemplateEngine::TemplateEngine() {
  m_engine = new Grantlee::Engine();
  Grantlee::FileSystemTemplateLoader::Ptr loader =
      Grantlee::FileSystemTemplateLoader::Ptr(
          new Grantlee::FileSystemTemplateLoader());
  string dir = Config::Instance().value<string> ("shaderDir");
  loader->setTemplateDirs(QStringList() << QString::fromStdString(dir));
  m_engine->addTemplateLoader(loader);

  c.insert("precision", false);

  vector<int> GLcontext = Config::Instance().values<int>("GLcontext");
  bool useUniformBuffers = (GLcontext[0] == 3 && GLcontext[1] >= 1) || GLcontext[0] > 3;
  c.insert("useUniformBuffers", useUniformBuffers);

  vector<int> glContext = Config::Instance().values<int>("GLcontext");

  QString version;

  if (glContext[0] == 3 && glContext[1] < 3) {
      switch(glContext[1]) {
      case 0:
          version = "130";
          break;
      case 1:
          version = "140";
          break;
      case 2:
          version = "150";
          break;
      default:
          break;
      }
  } else if(glContext[0] >= 3) {
    version = QString::number(glContext[0]) +  QString::number(glContext[1]) + "0 core";
  } else {
    LogFatal << "Unsupported GL Version" << glContext[0] << "." << glContext[1];
  }

  c.insert("version", version);
}
int main( int argc, char **argv )
{
  QCoreApplication app( argc, argv );

  Grantlee::Engine *engine = new Grantlee::Engine();

  Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr( new Grantlee::FileSystemTemplateLoader() );
  loader->setTemplateDirs( QStringList()
                           << ( QCoreApplication::applicationDirPath() + "/template_dir_1" )
                           << ( QCoreApplication::applicationDirPath() + "/template_dir_2" )
                         );

  engine->addTemplateLoader( loader );

  engine->setPluginPaths( QStringList() << GRANTLEE_PLUGIN_PATH );
  qDebug() << "Expect: \"Template 1 content\"";
  renderTemplate( engine, "template1.txt" );
  qDebug() << "Expect: \"Template 2 content\"";
  renderTemplate( engine, "template2.txt" );
  qDebug() << "Expect: \"Template 4 content\"";
  renderTemplate( engine, "template3.txt" );
  qDebug() << "Expect: \"Template 5 content\"";
  renderTemplate( engine, "template6.txt" );
  qDebug() << "Expect: \n" "file://" + QCoreApplication::applicationDirPath() + "/template_dir_2/red.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_2/blue.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_1/black.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_1/white.png";
  renderTemplate( engine, "mediatemplate1.txt" );
  qDebug() << "Expect: \n" "file://" + QCoreApplication::applicationDirPath() + "/template_dir_1/black.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_1/white.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_2/red.png\n"
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_2/blue.png";
  renderTemplate( engine, "mediatemplate2.txt" );

  app.exit( 0 );
}
BookWindow::BookWindow()
{
    ui.setupUi(this);

    if (!QSqlDatabase::drivers().contains("QSQLITE"))
        QMessageBox::critical(this, "Unable to load database", "This demo needs the SQLITE driver");

    // initialize the database
    QSqlError err = initDb();
    if (err.type() != QSqlError::NoError) {
        showError(err);
        return;
    }

    // Create the data model
    model = new QSqlRelationalTableModel(ui.bookTable);
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setTable("books");

    // Rememeber the indexes of the columns
    authorIdx = model->fieldIndex("author");
    genreIdx = model->fieldIndex("genre");

    // Set the relations to the other database tables
    model->setRelation(authorIdx, QSqlRelation("authors", "id", "name"));
    model->setRelation(genreIdx, QSqlRelation("genres", "id", "name"));

    // Set the localized header captions
    model->setHeaderData(authorIdx, Qt::Horizontal, tr("Author Name"));
    model->setHeaderData(genreIdx, Qt::Horizontal, tr("Genre"));
    model->setHeaderData(model->fieldIndex("title"), Qt::Horizontal, tr("Title"));
    model->setHeaderData(model->fieldIndex("year"), Qt::Horizontal, tr("Year"));
    model->setHeaderData(model->fieldIndex("rating"), Qt::Horizontal, tr("Rating"));

    // Populate the model
    if (!model->select()) {
        showError(model->lastError());
        return;
    }

    // Set the model and hide the ID column
    ui.bookTable->setModel(model);
    ui.bookTable->setItemDelegate(new BookDelegate(ui.bookTable));
    ui.bookTable->setColumnHidden(model->fieldIndex("id"), true);
    ui.bookTable->setSelectionMode(QAbstractItemView::SingleSelection);

    // Initialize the Author combo box
    ui.authorEdit->setModel(model->relationModel(authorIdx));
    ui.authorEdit->setModelColumn(model->relationModel(authorIdx)->fieldIndex("name"));

    ui.genreEdit->setModel(model->relationModel(genreIdx));
    ui.genreEdit->setModelColumn(model->relationModel(genreIdx)->fieldIndex("name"));

    QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
    mapper->setModel(model);
    mapper->setItemDelegate(new BookDelegate(this));
    mapper->addMapping(ui.titleEdit, model->fieldIndex("title"));
    mapper->addMapping(ui.yearEdit, model->fieldIndex("year"));
    mapper->addMapping(ui.authorEdit, authorIdx);
    mapper->addMapping(ui.genreEdit, genreIdx);
    mapper->addMapping(ui.ratingEdit, model->fieldIndex("rating"));

    connect(ui.bookTable->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
            mapper, SLOT(setCurrentModelIndex(QModelIndex)));

    ui.bookTable->setCurrentIndex(model->index(0, 0));

    ui.exportTheme->insertItems(0, QStringList() << "simple" << "coloured" << "simple2" << "coloured2" );

    connect(ui.exportButton, SIGNAL(pressed()), SLOT(renderBooks()));

    m_engine = new Grantlee::Engine();
    Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr( new Grantlee::FileSystemTemplateLoader() );
    loader->setTemplateDirs( QStringList() << GRANTLEE_TEMPLATE_PATH );
    m_engine->addTemplateLoader(loader);

    m_engine->setPluginPaths( QStringList() << GRANTLEE_PLUGIN_PATH );
}