Skip to content

Instantly share code, notes, and snippets.

View slarosa's full-sized avatar
🏠
Working from home

Salvatore Larosa slarosa

🏠
Working from home
  • Rende, Calabria (Italy)
View GitHub Profile
@slarosa
slarosa / gist:3453470
Created August 24, 2012 17:53
buffer and intersection test
def testIntersection(self):
myLine = QgsGeometry.fromPolyline([QgsPoint(0, 0),QgsPoint(1, 1),QgsPoint(2, 2)])
myPoint = QgsGeometry.fromPoint(QgsPoint(1, 1))
intersectionGeom = QgsGeometry.intersection(myLine, myPoint)
myMessage = ('Expected:\n%s\nGot:\n%s\n' %
(QGis.Point, intersectionGeom.type()))
assert intersectionGeom.wkbType() == QGis.WKBPoint, myMessage
def testBuffer(self):
myPoint = QgsGeometry.fromPoint(QgsPoint(1, 1))
@slarosa
slarosa / gist:3527525
Created August 30, 2012 12:27
AutoCompletion Python Console
import sys
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
lineEdit = QtGui.QLineEdit()
completer = QtGui.QCompleter(['QgsVectorLayer', 'QgsRasterLayer'])
lineEdit.setCompleter(completer)
lineEdit.show()
@slarosa
slarosa / gist:3755609
Created September 20, 2012 12:28
Reimplemented Paste and Drop
def paste(self):
"""Reimplement QScintilla method"""
stringPaste = unicode(QApplication.clipboard().text())
self.insertFromDropPaste(stringPaste)
def dropEvent(self, e):
if e.mimeData().hasText():
stringDrag = e.mimeData().text()
self.insertFromDropPaste(stringDrag)
@slarosa
slarosa / gist:3760664
Created September 21, 2012 09:48
lizmap.py
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Lizmap
A QGIS plugin
Publication plugin for Lizmap web application, by 3liz.com
-------------------
begin : 2011-11-01
copyright : (C) 2011 by 3liz
@slarosa
slarosa / gist:3761797
Created September 21, 2012 14:31
baselayer default
// add default base layer
baseLayerDefault = baselayers[0]
map.addLayer(baseLayerDefault);
select.push('<input type="radio" name="baselayers" value="'+baseLayerDefault.name+'">'+baseLayerDefault.name+'</input>');
for (var i=1,len=baselayers.length; i<len; i++) {
var baselayer = baselayers[i]
baselayer.units = projection.proj.units;
map.addLayer(baselayer);
var blConfig = config.layers[baselayer.name];
/*
@slarosa
slarosa / gist:3781331
Created September 25, 2012 11:55
PM.Custom
$.extend(PM,
{
Custom: {
showGroupInfo: function(nome_layer){
var nome = nome_layer.replace(/ligrp_/, '');
var server = window.location.hostname;
var Url = 'http://www.google.it/?search='+nome+';
window.location.href = URL;
}
}
diff --git a/python/console/console.py b/python/console/console.py
index 6dd69f1..670e3a3 100644
--- a/python/console/console.py
+++ b/python/console/console.py
@@ -340,6 +340,7 @@ class PythonConsoleWidget(QWidget):
sF.write('\n')
sF.write(s)
sF.close()
+ self.callWidgetMessageBar('Script was correctly saved.')
@slarosa
slarosa / gist:5594862
Created May 16, 2013 20:31
patch_console
diff --git a/python/console/console_editor.py b/python/console/console_editor.py
index cdf79cb..06c5342 100644
--- a/python/console/console_editor.py
+++ b/python/console/console_editor.py
@@ -602,11 +602,12 @@ class Editor(QsciScintilla):
return True
def keyPressEvent(self, e):
- t = unicode(e.text())
- ## Close bracket automatically
@slarosa
slarosa / gist:6292293
Created August 21, 2013 09:27
Fix for #8480 and #8481
diff --git a/src/app/qgsaddattrdialog.cpp b/src/app/qgsaddattrdialog.cpp
index c21e204..b32cb00 100644
--- a/src/app/qgsaddattrdialog.cpp
+++ b/src/app/qgsaddattrdialog.cpp
@@ -61,7 +61,7 @@ void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx )
mLength->setMinimum( mTypeBox->itemData( idx, Qt::UserRole + 2 ).toInt() );
mLength->setMaximum( mTypeBox->itemData( idx, Qt::UserRole + 3 ).toInt() );
- mLength->setVisible( mLength->minimum() < mLength->maximum() );
+ mLength->setEnabled( mLength->minimum() < mLength->maximum() );
@slarosa
slarosa / gist:6292807
Created August 21, 2013 10:24
QgsField::operator==
diff --git a/src/app/qgsaddattrdialog.cpp b/src/app/qgsaddattrdialog.cpp
index c21e204..b32cb00 100644
--- a/src/app/qgsaddattrdialog.cpp
+++ b/src/app/qgsaddattrdialog.cpp
@@ -61,7 +61,7 @@ void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx )
mLength->setMinimum( mTypeBox->itemData( idx, Qt::UserRole + 2 ).toInt() );
mLength->setMaximum( mTypeBox->itemData( idx, Qt::UserRole + 3 ).toInt() );
- mLength->setVisible( mLength->minimum() < mLength->maximum() );
+ mLength->setEnabled( mLength->minimum() < mLength->maximum() );
if ( mLength->value() < mLength->minimum() )