Ejemplo n.º 1
0
std::string CtrlHelper::saveFile(const std::string& caption, std::vector<FileDialogFilter> filter, FileDialogFilter* selection) {

	// show chooser
	QString selFilter;
	std::string fs = getFilterString(filter);
	std::string file = QFileDialog::getSaveFileName(0, caption.c_str(), "", fs.c_str(), &selFilter).toUtf8().constData();
	if (file.empty()) {return "";}

	// pass selected filter back to the caller?
	if (selection) {
		std::string selFilterStr = selFilter.toUtf8().constData();
		for (FileDialogFilter& f : filter) {
			if (f.getFilterString() == selFilterStr) {*selection = f;}
		}
	}

	// get selected file-extension from filter
	int p1 = selFilter.lastIndexOf("(*.");
	int p2 = selFilter.lastIndexOf(")");
	std::string fileExt = selFilter.mid(p1+3, p2-p1-3).toUtf8().constData();

	// append (missing) extension
	std::string curExt = file.substr( file.length() - fileExt.length(), fileExt.length() );
	if (curExt != fileExt) {file += "." + fileExt;}

	return file;

}
WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE( wxWindow* aParent ) :
    WIZARD_FPLIB_TABLE_BASE( aParent ), m_welcomeDlg( m_pages[0] ),
    m_fileSelectDlg( m_pages[1] ), m_githubListDlg( m_pages[2] ),
    m_reviewDlg( m_pages[3] ), m_targetDlg( m_pages[4] ), m_selectedFilter( 0 )
{
    m_filePicker->SetFilter( getFilterString() );

    // Initialize default download dir
    wxString default_path;
    wxGetEnv( FP_LIB_TABLE::GlobalPathEnvVariableName(), &default_path );
    setDownloadDir( default_path );
    m_filePicker->SetPath( default_path );

    // Restore the Github url
    wxString githubUrl;

    wxConfigBase* cfg = Pgm().CommonSettings();
    cfg->Read( KICAD_FPLIBS_URL_KEY, &githubUrl );
    cfg->Read( KICAD_FPLIBS_LAST_DOWNLOAD_DIR, &m_lastGithubDownloadDirectory );


    if( !m_lastGithubDownloadDirectory.IsEmpty() )
    {
        setDownloadDir( m_lastGithubDownloadDirectory );
        m_filePicker->SetPath( m_lastGithubDownloadDirectory );
    } else {
        m_lastGithubDownloadDirectory = default_path;
    }

    if( githubUrl.IsEmpty() )
        githubUrl = wxT( "https://github.com/KiCad" );

    SetGithubURL( githubUrl );

    // Give the minimal size to the dialog, which allows displaying any page
    wxSize minsize;

    for( unsigned ii = 0; ii < m_pages.size(); ii++ )
    {
        wxSize size = m_pages[ii]->GetSizer()->CalcMin();
        minsize.x = std::max( minsize.x, size.x );
        minsize.y = std::max( minsize.y, size.y );
    }

    SetMinSize( minsize );
    SetPageSize( minsize );
    GetSizer()->SetSizeHints( this );
    Center();

    if( !m_radioAddGithub->GetValue() && !m_radioAddLocal->GetValue() )
        m_radioAddLocal->SetValue( true );

    setupDialogOrder();
    updateGithubControls();

    Connect( wxEVT_RADIOBUTTON, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSourceCheck ), NULL, this );
    Connect( wxEVT_DIRCTRL_SELECTIONCHANGED, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSelectFiles ), NULL, this );
    Connect( wxEVT_CHECKLISTBOX, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnCheckGithubList ), NULL, this );
}
Ejemplo n.º 3
0
void MainWindow::handleMissingCheckBox(int state) {
    if (state == Qt::Checked)
        filter_map["missing"] = "examined IS FALSE";
    else
        filter_map.remove("missing");
    image_table_model->setFilter(getFilterString());
    qDebug() << image_table_model->query().executedQuery();
    qDebug() << image_table_model->filter();
}
Ejemplo n.º 4
0
void MainWindow::handleHeaderFilter(int index) {
    QSearchDialog dialog;
    dialog.updateItemList(getColumnDataList(index));
    if (dialog.exec()) {
        if (dialog.isSorted())
            ui->image_table->sortByColumn(index, dialog.getSortingOrder());
        if (dialog.getFilterString().isEmpty())
            filter_map.remove(image_table_model->headerData(index, Qt::Horizontal).toString());
        else
            filter_map[image_table_model->headerData(index, Qt::Horizontal).toString()] =
                    QString("cast(%1 as text) LIKE '%2'").arg(image_table_model->record().fieldName(index)).arg(dialog.getFilterString());
        image_table_model->setFilter(getFilterString());
    }

}
Ejemplo n.º 5
0
void MainWindow::handleSessionSelection() {
    if (!mapCanvas->saveData(config->current_cam, config->current_image)) {
        QMessageBox::critical(this,"Fehler","Fehler beim Sichern der Daten fuer"
                              "Metadaten fuer "+config->current_cam+" Kamera "+config->current_image+
                              "\n konnte nicht gesichert werden!",
                             "OK");
        imgSelector->clearSelection();
    }
	config->setProjectId(ui->cmbSession->currentText());
	if (config->getProjectId().isEmpty())
		return;
    QStringList project_parameters = db->getSessionParameters(config->getProjectId());
    qDebug() << config->getProjectId();
    config->setFlightId(project_parameters[0]);
    config->setUtmSector(project_parameters[1].toInt());
    config->setProjectPath(project_parameters[2]);

    /*
     * Filtern nach session und anschließend nach project_list.
     * Operation auf unindizierter project_list ist sonst zu langsam.
     * TODO: image_properties neu indizieren
     */
    filter_map.clear();
    filter_map["session"] = QString("session='%1' AND project='%2'").arg(config->getFlightId()).arg(ui->cmbSession->currentText());
    ui->chbNotReady->setChecked(false);
    /*
     * ModelView referenziert Datenbank-View daisi_bird_census_images
     * session und rdy Spalte werden ausgeblendet
     */
    image_table_model = db->getImageView();
    ui->image_table->setModel(image_table_model);
    ui->image_table->hideColumn(image_table_model->fieldIndex("session"));
    ui->image_table->hideColumn(image_table_model->fieldIndex("project"));
    ui->image_table->hideColumn(image_table_model->fieldIndex("project_list"));
    ui->image_table->hideColumn(image_table_model->fieldIndex("examined"));
    ui->image_table->hideColumn(image_table_model->fieldIndex("analysed"));
    ui->image_table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    image_table_model->setFilter(getFilterString());
    image_table_model->select();
    qDebug() << image_table_model->query().executedQuery();
    qDebug() << image_table_model->filter();

    imgSelector = ui->image_table->selectionModel();
    connect( imgSelector, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleImageSelection()));
}
Ejemplo n.º 6
0
std::string CtrlHelper::openFile(const std::string& caption, std::vector<FileDialogFilter> filter, FileDialogFilter* selection) {

	QFileDialog dialog;
	std::string fs = getFilterString(filter);
	dialog.setNameFilter(fs.c_str());
	dialog.setViewMode(QFileDialog::Detail);
	dialog.setWindowTitle(caption.c_str());
	if (dialog.exec()) {

		// pass selected filter back to the caller?
		if (selection) {
			std::string fs = dialog.selectedFilter().toUtf8().constData();
			for (FileDialogFilter& f : filter) {
				if (f.getFilterString() == fs) {*selection = f;}
			}
		}

		std::string file = dialog.selectedFiles().at(0).toUtf8().constData();
		return file;

	}
	return "";

}
Ejemplo n.º 7
0
void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{
    if( !m_cur_grid->CommitPendingChanges() )
        return;

    if( m_lastBrowseDir.IsEmpty() )
        m_lastBrowseDir = m_projectBasePath;

    DIALOG_FILE_DIR_PICKER dlg( this, _( "Select Library" ), m_lastBrowseDir,
                                getFilterString(), FD_MULTIPLE );

    auto result = dlg.ShowModal();

    if( result == wxID_CANCEL )
        return;

    m_lastBrowseDir = dlg.GetDirectory();

    // Drop the last directory if the path is a .pretty folder
    if( m_lastBrowseDir.EndsWith( KiCadFootprintLibPathExtension ) )
        m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() );

    const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
    bool addDuplicates = false;
    bool applyToAll = false;
    wxString warning = _( "Warning: Duplicate Nickname" );
    wxString msg = _( "A library nicknamed \"%s\" already exists." );
    wxArrayString files;
    dlg.GetFilenames( files );

    for( const auto& filePath : files )
    {
        wxFileName fn( filePath );
        wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB );
        bool doAdd = true;

        if( cur_model()->ContainsNickname( nickname ) )
        {
            if( !applyToAll )
            {
                int ret = YesOrCancelDialog( this, warning, wxString::Format( msg, nickname ),
                                             _( "Skip" ), _( "Add Anyway" ), &applyToAll );
                addDuplicates = (ret == wxID_CANCEL );
            }

            doAdd = addDuplicates;
        }

        if( doAdd && m_cur_grid->AppendRows( 1 ) )
        {
            int last_row = m_cur_grid->GetNumberRows() - 1;

            m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );

            auto type = IO_MGR::GuessPluginTypeFromLibPath( filePath );
            m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( type ) );

            // try to use path normalized to an environmental variable or project path
            wxString path = NormalizePath( filePath, &envVars, m_projectBasePath );

            if( path.IsEmpty() )
                path = fn.GetFullPath();

            m_cur_grid->SetCellValue( last_row, COL_URI, path );
        }
    }

    if( !files.IsEmpty() )
    {
        int new_row = m_cur_grid->GetNumberRows() - 1;
        m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() );
        m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() );
    }
}