void MediaRoutingView::_openInfoWindowsForSelection() { D_METHOD(("MediaRoutingView::_openInfoWindowsForSelection()\n")); InfoWindowManager *manager = InfoWindowManager::Instance(); if (!manager) { return; } if (selectedType() == DiagramItem::M_BOX) { for (uint32 i = 0; i < countSelectedItems(); i++) { MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i)); if (panel && manager->Lock()) { manager->openWindowFor(panel->ref); manager->Unlock(); } } } else if (selectedType() == DiagramItem::M_WIRE) { for (uint32 i = 0; i < countSelectedItems(); i++) { MediaWire *wire = dynamic_cast<MediaWire *>(selectedItemAt(i)); if (wire && manager->Lock()) { manager->openWindowFor(wire->connection); manager->Unlock(); } } } }
void NewFileChooser::accept() { QString fullPath = url().path(); if ( !selectedType()->ext().isEmpty() && !fullPath.endsWith("." + selectedType()->ext())) fullPath+="." + selectedType()->ext(); QFileInfo file( fullPath ); if ( file.exists() ) { KMessageBox::sorry( this, i18n("A file with this name already exists"), i18n("File Exists") ); return; } KDialogBase::accept(); }
void MediaRoutingView::_broadcastSelection() const { int32 selectedGroup = 0; if (selectedType() == DiagramItem::M_BOX) { // iterate thru the list of selected node panels and make the // first group we find the selected group for (uint32 i = 0; i < countSelectedItems(); i++) { MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i)); if (panel && panel->ref->group()) { selectedGroup = panel->ref->group()->id(); BMessenger messenger(Window()); BMessage groupMsg(M_GROUP_SELECTED); groupMsg.AddInt32("groupID", selectedGroup); messenger.SendMessage(&groupMsg); return; } } } // currently no group is selected BMessenger messenger(Window()); BMessage groupMsg(M_GROUP_SELECTED); groupMsg.AddInt32("groupID", selectedGroup); messenger.SendMessage(&groupMsg); }
void MediaRoutingView::_deleteSelection() { D_METHOD(("MediaRoutingView::_deleteSelection()\n")); if (selectedType() == DiagramItem::M_BOX) { for (uint32 i = 0; i < countSelectedItems(); i++) { MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i)); if (panel && panel->ref->isInternal()) { status_t error = panel->ref->releaseNode(); if (error) { BString s; s << "Could not release '" << panel->ref->name() << "'"; showErrorMessage(s, error); } } } } else if (selectedType() == DiagramItem::M_WIRE) { for (uint32 i = 0; i < countSelectedItems(); i++) { MediaWire *wire = dynamic_cast<MediaWire *>(selectedItemAt(i)); if (wire && !(wire->connection.flags() & Connection::LOCKED)) { status_t error = manager->disconnect(wire->connection); if (error) { showErrorMessage("Could not disconnect", error); } } } } // make sure none of the deleted items is still displaying its mouse cursor ! be_app->SetCursor(B_HAND_CURSOR); }
void Tomahawk::EchonestControl::setSelectedType ( const QString& type ) { if( type != selectedType() ) { if( !m_input.isNull() ) delete m_input.data(); if( !m_match.isNull() ) delete m_match.data(); Tomahawk::DynamicControl::setSelectedType ( type ); updateWidgets(); updateData(); // qDebug() << "Setting new type, set data to:" << m_data.first << m_data.second; } }
void MediaRoutingView::_startControlPanelsForSelection() { D_METHOD(("MediaRoutingView::_startControlPanelsForSelection()\n")); if (selectedType() != DiagramItem::M_BOX) { // can only start control panel for nodes return; } for (uint32 i = 0; i < countSelectedItems(); i++) { MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i)); if (panel && (panel->ref->kind() & B_CONTROLLABLE)) { ParameterWindowManager *paramMgr= ParameterWindowManager::Instance(); if (paramMgr && paramMgr->Lock()) { paramMgr->startControlPanelFor(panel->ref); paramMgr->Unlock(); } } } }
void MediaRoutingView::_changeRunModeForSelection( uint32 mode) { D_METHOD(("MediaRoutingView::_changeRunModeForSelection()\n")); if (selectedType() == DiagramItem::M_BOX) { manager->lock(); for (uint32 i = 0; i < countSelectedItems(); i++) { MediaNodePanel *panel = dynamic_cast<MediaNodePanel *>(selectedItemAt(i)); if (panel && (panel->ref->runMode() != mode)) { panel->ref->setRunMode(mode); } } manager->unlock(); } }
void Tomahawk::EchonestControl::updateWidgets() { if( !m_input.isNull() ) delete m_input.data(); if( !m_match.isNull() ) delete m_match.data(); m_overrideType = -1; // make sure the widgets are the proper kind for the selected type, and hook up to their slots if( selectedType() == "Artist" ) { m_currentType = Echonest::DynamicPlaylist::Artist; QComboBox* match = new QComboBox(); QLineEdit* input = new QLineEdit(); match->addItem( tr( "Similar To" ), Echonest::DynamicPlaylist::ArtistRadioType ); match->addItem( tr( "Limit To" ), Echonest::DynamicPlaylist::ArtistType ); m_matchString = match->currentText(); m_matchData = match->itemData( match->currentIndex() ).toString(); input->setPlaceholderText( tr( "Artist name" ) ); input->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ); input->setCompleter( new QCompleter( QStringList(), input ) ); input->completer()->setCaseSensitivity( Qt::CaseInsensitive ); connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) ); connect( match, SIGNAL( currentIndexChanged(int) ), this, SIGNAL( changed() ) ); connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) ); connect( input, SIGNAL( editingFinished() ), this, SLOT( editingFinished() ) ); connect( input, SIGNAL( textEdited( QString ) ), &m_editingTimer, SLOT( stop() ) ); connect( input, SIGNAL( textEdited( QString ) ), &m_delayedEditTimer, SLOT( start() ) ); connect( input, SIGNAL( textEdited( QString ) ), this, SLOT( artistTextEdited( QString ) ) ); match->hide(); input->hide(); m_match = QPointer< QWidget >( match ); m_input = QPointer< QWidget >( input ); m_data.first = m_currentType; }
bool QgsNewSpatialiteLayerDialog::apply() { // Build up the sql statement for creating the table QString sql = QString( "create table %1(" ).arg( quotedIdentifier( leLayerName->text() ) ); QString delim = ""; if ( checkBoxPrimaryKey->isChecked() ) { sql += "pkuid integer primary key autoincrement,"; } QTreeWidgetItemIterator it( mAttributeView ); while ( *it ) { sql += delim + QString( "%1 %2" ).arg( quotedIdentifier(( *it )->text( 0 ) ) ).arg(( *it )->text( 1 ) ); delim = ","; ++it; } // complete the create table statement sql += ")"; QgsDebugMsg( QString( "Creating table in database %1" ).arg( mDatabaseComboBox->currentText() ) ); QgsDebugMsg( sql ); // OK QString sqlAddGeom = QString( "select AddGeometryColumn(%1,%2,%3,%4,2)" ) .arg( quotedValue( leLayerName->text() ) ) .arg( quotedValue( leGeometryColumn->text() ) ) .arg( mCrsId.split( ':' ).value( 1, "0" ).toInt() ) .arg( quotedValue( selectedType() ) ); QgsDebugMsg( sqlAddGeom ); // OK QString sqlCreateIndex = QString( "select CreateSpatialIndex(%1,%2)" ) .arg( quotedValue( leLayerName->text() ) ) .arg( quotedValue( leGeometryColumn->text() ) ); QgsDebugMsg( sqlCreateIndex ); // OK sqlite3 *db; int rc = QgsSLConnect::sqlite3_open( mDatabaseComboBox->currentText().toUtf8(), &db ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "SpatiaLite Database" ), tr( "Unable to open the database: %1" ).arg( mDatabaseComboBox->currentText() ) ); } else { char * errmsg; rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating SpatiaLite Table" ), tr( "Failed to create the SpatiaLite table %1. The database returned:\n%2" ).arg( leLayerName->text() ).arg( errmsg ) ); sqlite3_free( errmsg ); } else { // create the geometry column and the spatial index rc = sqlite3_exec( db, sqlAddGeom.toUtf8(), NULL, NULL, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating Geometry Column" ), tr( "Failed to create the geometry column. The database returned:\n%1" ).arg( errmsg ) ); sqlite3_free( errmsg ); } else { // create the spatial index rc = sqlite3_exec( db, sqlCreateIndex.toUtf8(), NULL, NULL, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating Spatial Index" ), tr( "Failed to create the spatial index. The database returned:\n%1" ).arg( errmsg ) ); sqlite3_free( errmsg ); } QgsVectorLayer *layer = new QgsVectorLayer( QString( "dbname='%1' table='%2'(%3) sql=" ) .arg( mDatabaseComboBox->currentText() ) .arg( leLayerName->text() ) .arg( leGeometryColumn->text() ), leLayerName->text(), "spatialite" ); if ( layer->isValid() ) { // register this layer with the central layers registry QList<QgsMapLayer *> myList; myList << layer; //addMapLayers returns a list of all successfully added layers //so we compare that to our original list. if ( myList == QgsMapLayerRegistry::instance()->addMapLayers( myList ) ) return true; } else { QgsDebugMsg( leLayerName->text() + " is an invalid layer - not loaded" ); QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( leLayerName->text() ) ); delete layer; } } } QgsSLConnect::sqlite3_close( db ); } return false; }
bool QgsNewSpatialiteLayerDialog::apply() { // Build up the sql statement for creating the table QString sql = QStringLiteral( "create table %1(" ).arg( quotedIdentifier( leLayerName->text() ) ); QString delim; if ( checkBoxPrimaryKey->isChecked() ) { sql += QLatin1String( "pkuid integer primary key autoincrement" ); delim = QStringLiteral( "," ); } QTreeWidgetItemIterator it( mAttributeView ); while ( *it ) { sql += delim + QStringLiteral( "%1 %2" ).arg( quotedIdentifier( ( *it )->text( 0 ) ), ( *it )->text( 1 ) ); delim = QStringLiteral( "," ); ++it; } // complete the create table statement sql += ')'; QgsDebugMsg( QStringLiteral( "Creating table in database %1" ).arg( mDatabaseComboBox->currentText() ) ); QgsDebugMsg( sql ); spatialite_database_unique_ptr database; int rc = database.open( mDatabaseComboBox->currentText() ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "SpatiaLite Database" ), tr( "Unable to open the database: %1" ).arg( mDatabaseComboBox->currentText() ) ); return false; } char *errmsg = nullptr; // create the table rc = sqlite3_exec( database.get(), sql.toUtf8(), nullptr, nullptr, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating SpatiaLite Table" ), tr( "Failed to create the SpatiaLite table %1. The database returned:\n%2" ).arg( leLayerName->text(), errmsg ) ); sqlite3_free( errmsg ); return false; } // create the geometry column and the spatial index if ( mGeometryTypeBox->currentIndex() != 0 ) { QString sqlAddGeom = QStringLiteral( "select AddGeometryColumn(%1,%2,%3,%4,%5)" ) .arg( QgsSqliteUtils::quotedString( leLayerName->text() ), QgsSqliteUtils::quotedString( leGeometryColumn->text() ) ) .arg( mCrsId.split( ':' ).value( 1, QStringLiteral( "0" ) ).toInt() ) .arg( QgsSqliteUtils::quotedString( selectedType() ) ) .arg( QgsSqliteUtils::quotedString( selectedZM() ) ); QgsDebugMsg( sqlAddGeom ); rc = sqlite3_exec( database.get(), sqlAddGeom.toUtf8(), nullptr, nullptr, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating Geometry Column" ), tr( "Failed to create the geometry column. The database returned:\n%1" ).arg( errmsg ) ); sqlite3_free( errmsg ); return false; } QString sqlCreateIndex = QStringLiteral( "select CreateSpatialIndex(%1,%2)" ) .arg( QgsSqliteUtils::quotedString( leLayerName->text() ), QgsSqliteUtils::quotedString( leGeometryColumn->text() ) ); QgsDebugMsg( sqlCreateIndex ); rc = sqlite3_exec( database.get(), sqlCreateIndex.toUtf8(), nullptr, nullptr, &errmsg ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "Error Creating Spatial Index" ), tr( "Failed to create the spatial index. The database returned:\n%1" ).arg( errmsg ) ); sqlite3_free( errmsg ); return false; } } const QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "dbname='%1' table='%2'%3 sql=" ) .arg( mDatabaseComboBox->currentText(), leLayerName->text(), mGeometryTypeBox->currentIndex() != 0 ? QStringLiteral( "(%1)" ).arg( leGeometryColumn->text() ) : QString() ), leLayerName->text(), QStringLiteral( "spatialite" ), options ); if ( layer->isValid() ) { // Reload connections to refresh browser panel QgisApp::instance()->reloadConnections(); // register this layer with the central layers registry QList<QgsMapLayer *> myList; myList << layer; //addMapLayers returns a list of all successfully added layers //so we compare that to our original list. if ( myList == QgsProject::instance()->addMapLayers( myList ) ) return true; } else { QgsDebugMsg( leLayerName->text() + " is an invalid layer - not loaded" ); QMessageBox::critical( this, tr( "SpatiaLite Database" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( leLayerName->text() ) ); delete layer; } return false; }