Exemplo n.º 1
0
void API::Switcher(SqlCommand* command){
  SqlCommandType command_type = command->command_type();
  Info info;
  // typedef std::chrono::high_resolution_clock Clock;
  // typedef std::chrono::milliseconds milliseconds;
  // Clock::time_point t0 = Clock::now();
  switch(command_type){
    case kSqlInvalid: { info = Info("Invalid Command, Please check your syntax."); break; }
    case kSqlCreateTable: { info = CreateTable(dynamic_cast<SqlCommandCreateTable *>(command)); break; }
    case kSqlCreateIndex: { info = CreateIndex(dynamic_cast<SqlCommandCreateIndex *>(command)); break; }
    case kSqlDeleteFrom: { info = DeleteFrom(dynamic_cast<SqlCommandDeleteFrom *>(command)); break; }
    case kSqlDropTable: { info = DropTable(dynamic_cast<SqlCommandDropTable *>(command)); break; }
    case kSqlDropIndex: { info = DropIndex(dynamic_cast<SqlCommandDropIndex *>(command)); break; }
    case kSqlInsertInto: { info = InsertInto(dynamic_cast<SqlCommandInsertInto *>(command)); break; }
    case kSqlSelectFrom: { info = SelectFrom(dynamic_cast<SqlCommandSelectFrom *>(command));break; }
  }
  info.PrintInfo();
  // Clock::time_point t1 = Clock::now();
  // milliseconds ms = std::chrono::duration_cast<milliseconds>(t1 - t0);
  // std::cout<<"time used:"<<ms.count()<<" ms."<<std::endl;
}
Exemplo n.º 2
0
RoutingDialog::RoutingDialog(QWidget* parentWindow,
                             DBThread* dbThread,
                             const SettingsRef& settings)
 : QDialog(parentWindow),
   settings(settings),
   dbThread(dbThread),
   from(new QLineEdit()),
   hasStart(false),
   to(new QLineEdit()),
   hasEnd(false),
   routeView(new QTableView()),
   routeModel(new RouteModel())
{
  QVBoxLayout  *mainLayout=new QVBoxLayout();
  QFormLayout  *formLayout=new QFormLayout();
  QHBoxLayout  *fromBoxLayout=new QHBoxLayout();
  QHBoxLayout  *toBoxLayout=new QHBoxLayout();
  QHBoxLayout  *asBoxLayout=new QHBoxLayout();
  QPushButton  *selectFromButton=new QPushButton("...");
  QPushButton  *selectToButton=new QPushButton("...");
  QButtonGroup *routeTypes = new QButtonGroup();
  QPushButton  *routeTypeFoot = new QPushButton("Foot");
  QPushButton  *routeTypeBicycle = new QPushButton("Bicycle");
  QPushButton  *routeTypeCar = new QPushButton("Car");

  from->setReadOnly(true);
  from->setEnabled(false);
  from->setMinimumWidth(QApplication::fontMetrics().width("mlxi")/4*70);
  //from->setPlaceholderText("Starting location");
  to->setReadOnly(true);
  to->setEnabled(false);
  to->setMinimumWidth(QApplication::fontMetrics().width("mlxi")/4*70);
  //to->setPlaceholderText("Destination location");

  selectFromButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed));
  selectToButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed));

  fromBoxLayout->addWidget(from);
  fromBoxLayout->addWidget(selectFromButton);

  formLayout->addRow("From:",fromBoxLayout);

  toBoxLayout->addWidget(to);
  toBoxLayout->addWidget(selectToButton);

  formLayout->addRow("To:",toBoxLayout);

  osmscout::Vehicle vehicle=settings->GetRoutingVehicle();

  routeTypeFoot->setCheckable(true);
  routeTypeFoot->setChecked(vehicle==osmscout::vehicleFoot);

  routeTypeBicycle->setCheckable(true);
  routeTypeBicycle->setChecked(vehicle==osmscout::vehicleBicycle);

  routeTypeCar->setCheckable(true);
  routeTypeCar->setChecked(vehicle==osmscout::vehicleCar);

  routeTypes->addButton(routeTypeFoot,
                        osmscout::vehicleFoot);
  routeTypes->addButton(routeTypeBicycle,
                        osmscout::vehicleBicycle);
  routeTypes->addButton(routeTypeCar,
                        osmscout::vehicleCar);


  asBoxLayout->addWidget(routeTypeFoot);
  asBoxLayout->addWidget(routeTypeBicycle);
  asBoxLayout->addWidget(routeTypeCar);

  formLayout->addRow("As: ",asBoxLayout);

  mainLayout->addLayout(formLayout);

  routeView->setModel(routeModel);
  routeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
  routeView->setSelectionMode(QAbstractItemView::SingleSelection);
  routeView->setSelectionBehavior(QAbstractItemView::SelectRows);
  routeView->setShowGrid(false);
  routeView->setMinimumWidth(QApplication::fontMetrics().width("mlxi")/4*70);
  routeView->horizontalHeader()->setStretchLastSection(true);
  routeView->horizontalHeader()->setHighlightSections (false);
  routeView->verticalHeader()->hide();
  routeView->setColumnWidth(0,QApplication::fontMetrics().width("mlxi")/4*12);
  routeView->setColumnWidth(1,QApplication::fontMetrics().width("mlxi")/4*12);
  routeView->setColumnWidth(2,QApplication::fontMetrics().width("mlxi")/4*10);
  routeView->setColumnWidth(3,QApplication::fontMetrics().width("mlxi")/4*10);

  mainLayout->addWidget(routeView);

  QDialogButtonBox *buttonBox=new QDialogButtonBox();

  routeButton=buttonBox->addButton("&Route",QDialogButtonBox::ApplyRole);
  buttonBox->addButton(QDialogButtonBox::Close);

  routeButton->setEnabled(false);

  mainLayout->addWidget(buttonBox);

  setLayout(mainLayout);

  connect(selectFromButton,SIGNAL(clicked()),this,SLOT(SelectFrom()));
  connect(selectToButton,SIGNAL(clicked()),this,SLOT(SelectTo()));
  connect(routeButton,SIGNAL(clicked()),this,SLOT(CalculateRoute()));
  connect(buttonBox->button(QDialogButtonBox::Close),SIGNAL(clicked()),this,SLOT(close()));
  connect(routeTypes,SIGNAL(buttonClicked(int)),this,SLOT(OnVehicle(int)));

  if (!route.start.isEmpty()) {
    from->setText(route.start);
    hasStart=true;
  }

  if (!route.end.isEmpty()) {
    to->setText(route.end);
    hasEnd=true;
  }

  if (hasStart && hasEnd) {
    routeButton->setEnabled(true);
  }
}