mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
This commit is contained in:
commit
016789ab2d
@ -147,6 +147,7 @@ SET(PY_FILES
|
||||
console_sci.py
|
||||
console_help.py
|
||||
console_settings.py
|
||||
console_output.py
|
||||
utils.py
|
||||
)
|
||||
FILE(GLOB UI_FILES *.ui)
|
||||
|
@ -23,6 +23,7 @@ from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from qgis.utils import iface
|
||||
from console_sci import PythonEdit
|
||||
from console_output import EditorOutput
|
||||
from console_help import HelpDialog
|
||||
from console_settings import optionsDialog
|
||||
|
||||
@ -58,20 +59,6 @@ def console_displayhook(obj):
|
||||
global _console_output
|
||||
_console_output = obj
|
||||
|
||||
class QgisOutputCatcher:
|
||||
def __init__(self):
|
||||
self.data = ''
|
||||
def write(self, stuff):
|
||||
self.data += stuff
|
||||
def get_and_clean_data(self):
|
||||
tmp = self.data
|
||||
self.data = ''
|
||||
return tmp
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
sys.stdout = QgisOutputCatcher()
|
||||
|
||||
class PythonConsole(QDockWidget):
|
||||
def __init__(self, parent=None):
|
||||
QDockWidget.__init__(self, parent)
|
||||
@ -92,18 +79,17 @@ class PythonConsole(QDockWidget):
|
||||
self.raise_()
|
||||
QDockWidget.setFocus(self)
|
||||
|
||||
|
||||
class PythonConsoleWidget(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
|
||||
|
||||
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
|
||||
self.widgetButton = QWidget()
|
||||
#self.widgetEditors = QWidget()
|
||||
|
||||
self.options = optionsDialog(self)
|
||||
|
||||
self.toolBar = QToolBar()
|
||||
self.toolBar.setEnabled(True)
|
||||
#self.toolBar.setFont(font)
|
||||
self.toolBar.setFocusPolicy(Qt.NoFocus)
|
||||
self.toolBar.setContextMenuPolicy(Qt.DefaultContextMenu)
|
||||
self.toolBar.setLayoutDirection(Qt.LeftToRight)
|
||||
@ -111,16 +97,14 @@ class PythonConsoleWidget(QWidget):
|
||||
self.toolBar.setOrientation(Qt.Vertical)
|
||||
self.toolBar.setMovable(True)
|
||||
self.toolBar.setFloatable(True)
|
||||
#self.toolBar.setAllowedAreas(Qt.LeftToolBarArea)
|
||||
#self.toolBar.setAllowedAreas(Qt.RightToolBarArea)
|
||||
#self.toolBar.setObjectName(_fromUtf8("toolMappa"))
|
||||
|
||||
self.b = QVBoxLayout(self.widgetButton)
|
||||
self.e = QHBoxLayout(self)
|
||||
self.b = QGridLayout(self.widgetButton)
|
||||
self.f = QGridLayout(self)
|
||||
|
||||
self.e.setMargin(0)
|
||||
self.e.setSpacing(0)
|
||||
self.f.setMargin(0)
|
||||
self.f.setSpacing(0)
|
||||
self.b.setMargin(0)
|
||||
self.b.setSpacing(0)
|
||||
|
||||
## Action for Clear button
|
||||
clearBt = QCoreApplication.translate("PythonConsole", "Clear console")
|
||||
@ -268,12 +252,37 @@ class PythonConsoleWidget(QWidget):
|
||||
|
||||
self.b.addWidget(self.toolBar)
|
||||
self.edit = PythonEdit()
|
||||
self.setFocusProxy( self.edit )
|
||||
|
||||
self.e.addWidget(self.widgetButton)
|
||||
self.e.addWidget(self.edit)
|
||||
self.textEditOut = EditorOutput()
|
||||
|
||||
self.clearButton.triggered.connect(self.edit.clearConsole)
|
||||
self.setFocusProxy(self.edit)
|
||||
|
||||
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.widgetButton.sizePolicy().hasHeightForWidth())
|
||||
self.widgetButton.setSizePolicy(sizePolicy)
|
||||
|
||||
self.consoleFrame = QFrame(self)
|
||||
self.consoleFrame.setObjectName("consoleFrame")
|
||||
self.consoleLayout = QVBoxLayout(self.consoleFrame)
|
||||
self.consoleLayout.setSpacing(0)
|
||||
self.consoleLayout.setMargin(0)
|
||||
|
||||
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.textEditOut.sizePolicy().hasHeightForWidth())
|
||||
self.textEditOut.setSizePolicy(sizePolicy)
|
||||
self.consoleLayout.addWidget(self.textEditOut)
|
||||
|
||||
self.edit.setMinimumSize(QSize(0, 32))
|
||||
self.edit.setMaximumSize(QSize(16777215, 32))
|
||||
self.consoleLayout.addWidget(self.edit)
|
||||
|
||||
self.f.addWidget(self.widgetButton, 0, 0)
|
||||
self.f.addWidget(self.consoleFrame, 0, 1)
|
||||
|
||||
self.clearButton.triggered.connect(self.textEditOut.clearConsole)
|
||||
self.optionsButton.triggered.connect(self.openSettings)
|
||||
self.loadIfaceButton.triggered.connect(self.iface)
|
||||
self.loadSextanteButton.triggered.connect(self.sextante)
|
||||
@ -326,7 +335,7 @@ class PythonConsoleWidget(QWidget):
|
||||
if not filename.endswith(".py"):
|
||||
fName += ".py"
|
||||
sF = open(fName,'w')
|
||||
listText = self.edit.getTextFromEditor()
|
||||
listText = self.textEditOut.getTextFromEditor()
|
||||
is_first_line = True
|
||||
for s in listText:
|
||||
if s[0:3] in (">>>", "..."):
|
||||
@ -337,7 +346,7 @@ class PythonConsoleWidget(QWidget):
|
||||
sF.write('\n')
|
||||
sF.write(s)
|
||||
sF.close()
|
||||
|
||||
|
||||
def openHelp(self):
|
||||
dlg = HelpDialog()
|
||||
dlg.exec_()
|
||||
@ -348,6 +357,7 @@ class PythonConsoleWidget(QWidget):
|
||||
|
||||
def prefChanged(self):
|
||||
self.edit.refreshLexerProperties()
|
||||
self.textEditOut.refreshLexerProperties()
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.edit.writeHistoryFile()
|
||||
|
167
python/console_output.py
Normal file
167
python/console_output.py
Normal file
@ -0,0 +1,167 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
/***************************************************************************
|
||||
Python Conosle for QGIS
|
||||
-------------------
|
||||
begin : 2012-09-10
|
||||
copyright : (C) 2012 by Salvatore Larosa
|
||||
email : lrssvtml (at) gmail (dot) com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
Some portions of code were taken from https://code.google.com/p/pydee/
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.Qsci import (QsciScintilla,
|
||||
QsciScintillaBase,
|
||||
QsciLexerPython)
|
||||
from console_sci import PythonEdit
|
||||
import sys
|
||||
|
||||
class writeOut:
|
||||
def __init__(self, edit, out=None, style=None):
|
||||
"""
|
||||
This class allow to write stdout and stderr
|
||||
"""
|
||||
self.editor = edit
|
||||
self.out = None
|
||||
self.style = style
|
||||
|
||||
def write(self, m):
|
||||
if self.style == "traceback":
|
||||
self.editor.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
||||
self.editor.append(m)
|
||||
self.editor.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
||||
else:
|
||||
self.editor.append(m)
|
||||
self.move_cursor_to_end()
|
||||
|
||||
if self.out:
|
||||
self.out.write(m)
|
||||
|
||||
def move_cursor_to_end(self):
|
||||
"""Move cursor to end of text"""
|
||||
line, index = self.get_end_pos()
|
||||
self.editor.setCursorPosition(line, index)
|
||||
self.editor.ensureCursorVisible()
|
||||
self.editor.ensureLineVisible(line)
|
||||
|
||||
def get_end_pos(self):
|
||||
"""Return (line, index) position of the last character"""
|
||||
line = self.editor.lines() - 1
|
||||
return (line, self.editor.text(line).length())
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
class EditorOutput(QsciScintilla):
|
||||
def __init__(self, parent=None):
|
||||
#QsciScintilla.__init__(self, parent)
|
||||
super(EditorOutput,self).__init__(parent)
|
||||
# Enable non-ascii chars for editor
|
||||
self.setUtf8(True)
|
||||
|
||||
sys.stdout = writeOut(self, sys.stdout)
|
||||
sys.stderr = writeOut(self, sys.stderr, "traceback")
|
||||
|
||||
self.edit = PythonEdit()
|
||||
self.setLexers()
|
||||
self.setReadOnly(True)
|
||||
|
||||
# Set the default font
|
||||
font = QFont()
|
||||
font.setFamily('Courier')
|
||||
font.setFixedPitch(True)
|
||||
font.setPointSize(10)
|
||||
self.setFont(font)
|
||||
self.setMarginsFont(font)
|
||||
# Margin 0 is used for line numbers
|
||||
#fm = QFontMetrics(font)
|
||||
self.setMarginsFont(font)
|
||||
self.setMarginWidth(1, "00000")
|
||||
self.setMarginLineNumbers(1, True)
|
||||
self.setMarginsForegroundColor(QColor("#3E3EE3"))
|
||||
self.setMarginsBackgroundColor(QColor("#f9f9f9"))
|
||||
self.setCaretLineVisible(True)
|
||||
self.setCaretLineBackgroundColor(QColor("#fcf3ed"))
|
||||
|
||||
|
||||
# Folding
|
||||
#self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
|
||||
#self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300"))
|
||||
#self.setWrapMode(QsciScintilla.WrapCharacter)
|
||||
|
||||
## Edge Mode : does not seems to work
|
||||
#self.setEdgeMode(QsciScintilla.EdgeLine)
|
||||
#self.setEdgeColumn(80)
|
||||
#self.setEdgeColor(QColor("#FF0000"))
|
||||
|
||||
self.SendScintilla(QsciScintilla.SCI_SETWRAPMODE, 2)
|
||||
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
|
||||
|
||||
def refreshLexerProperties(self):
|
||||
self.setLexers()
|
||||
|
||||
def setLexers(self):
|
||||
self.lexer = QsciLexerPython()
|
||||
|
||||
settings = QSettings()
|
||||
loadFont = settings.value("pythonConsole/fontfamilytext").toString()
|
||||
fontSize = settings.value("pythonConsole/fontsize").toInt()[0]
|
||||
font = QFont(loadFont)
|
||||
font.setFixedPitch(True)
|
||||
font.setPointSize(fontSize)
|
||||
|
||||
self.lexer.setDefaultFont(font)
|
||||
self.lexer.setColor(Qt.red, 1)
|
||||
self.lexer.setColor(Qt.darkGreen, 5)
|
||||
self.lexer.setColor(Qt.darkBlue, 15)
|
||||
self.lexer.setFont(font, 1)
|
||||
self.lexer.setFont(font, 2)
|
||||
self.lexer.setFont(font, 3)
|
||||
self.lexer.setFont(font, 4)
|
||||
|
||||
self.setLexer(self.lexer)
|
||||
|
||||
def getTextFromEditor(self):
|
||||
text = self.text()
|
||||
textList = text.split("\n")
|
||||
return textList
|
||||
|
||||
def clearConsole(self):
|
||||
#self.SendScintilla(QsciScintilla.SCI_CLEARALL)
|
||||
self.setText('')
|
||||
|
||||
def contextMenuEvent(self, e):
|
||||
menu = QMenu(self)
|
||||
runAction = menu.addAction("Enter Selected")
|
||||
copyAction = menu.addAction("Copy CTRL+C")
|
||||
runAction.setEnabled(False)
|
||||
if self.hasSelectedText():
|
||||
runAction.setEnabled(True)
|
||||
action = menu.exec_(self.mapToGlobal(e.pos()))
|
||||
if action == runAction:
|
||||
cmd = self.selectedText()
|
||||
self.edit.insertFromDropPaste(cmd)
|
||||
self.edit.entered()
|
||||
if action == copyAction:
|
||||
self.copy()
|
||||
|
||||
def copy(self):
|
||||
"""Copy text to clipboard... or keyboard interrupt"""
|
||||
if self.hasSelectedText():
|
||||
text = unicode(self.selectedText())
|
||||
text = text.replace('>>> ', '').replace('... ', '').strip() # removing prompts
|
||||
QApplication.clipboard().setText(text)
|
||||
else:
|
||||
self.emit(SIGNAL("keyboard_interrupt()"))
|
||||
|
@ -51,7 +51,7 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
|
||||
self.buffer = []
|
||||
|
||||
self.insertInitText()
|
||||
#self.insertInitText()
|
||||
self.displayPrompt(False)
|
||||
|
||||
for line in _init_commands:
|
||||
@ -69,8 +69,8 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
#self.selectToMatchingBrace()
|
||||
|
||||
# Current line visible with special background color
|
||||
self.setCaretLineVisible(True)
|
||||
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
|
||||
#self.setCaretLineVisible(True)
|
||||
#self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
|
||||
self.setCaretWidth(2)
|
||||
|
||||
# Set Python lexer
|
||||
@ -93,12 +93,14 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
# Use raw message to Scintilla here (all messages are documented
|
||||
# here: http://www.scintilla.org/ScintillaDoc.html)
|
||||
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
|
||||
self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0)
|
||||
|
||||
|
||||
# not too small
|
||||
#self.setMinimumSize(500, 300)
|
||||
self.setMinimumHeight(125)
|
||||
self.setMinimumHeight(32)
|
||||
|
||||
self.SendScintilla(QsciScintilla.SCI_SETWRAPMODE, 1)
|
||||
self.SendScintilla(QsciScintilla.SCI_SETWRAPMODE, 2)
|
||||
self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)
|
||||
|
||||
## Disable command key
|
||||
@ -117,20 +119,14 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
self.newShortcutCAS.activated.connect(self.showHistory)
|
||||
self.connect(self, SIGNAL('userListActivated(int, const QString)'),
|
||||
self.completion_list_selected)
|
||||
|
||||
self.createStandardContextMenu()
|
||||
|
||||
def showHistory(self):
|
||||
self.showUserList(1, QStringList(self.history))
|
||||
|
||||
def autoComplete(self):
|
||||
self.autoCompleteFromAll()
|
||||
|
||||
def clearConsole(self):
|
||||
"""Clear the contents of the console."""
|
||||
self.SendScintilla(QsciScintilla.SCI_CLEARALL)
|
||||
#self.setText('')
|
||||
self.insertInitText()
|
||||
self.displayPrompt(False)
|
||||
self.setFocus()
|
||||
|
||||
def commandConsole(self, command):
|
||||
if not self.is_cursor_on_last_line():
|
||||
@ -142,23 +138,20 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
if command == "iface":
|
||||
"""Import QgisInterface class"""
|
||||
self.append('from qgis.utils import iface')
|
||||
self.move_cursor_to_end()
|
||||
elif command == "sextante":
|
||||
"""Import Sextante class"""
|
||||
self.append('from sextante.core.Sextante import Sextante')
|
||||
self.move_cursor_to_end()
|
||||
elif command == "cLayer":
|
||||
"""Retrieve current Layer from map camvas"""
|
||||
self.append('cLayer = iface.mapCanvas().currentLayer()')
|
||||
self.move_cursor_to_end()
|
||||
elif command == "qtCore":
|
||||
"""Import QtCore class"""
|
||||
self.append('from PyQt4.QtCore import *')
|
||||
self.move_cursor_to_end()
|
||||
elif command == "qtGui":
|
||||
"""Import QtGui class"""
|
||||
self.append('from PyQt4.QtGui import *')
|
||||
self.move_cursor_to_end()
|
||||
self.entered()
|
||||
self.move_cursor_to_end()
|
||||
self.setFocus()
|
||||
|
||||
def setLexers(self):
|
||||
@ -172,6 +165,10 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
font = QFont(loadFont)
|
||||
font.setFixedPitch(True)
|
||||
font.setPointSize(fontSize)
|
||||
font.setStyleHint(QFont.TypeWriter)
|
||||
font.setStretch(QFont.SemiCondensed)
|
||||
font.setLetterSpacing(QFont.PercentageSpacing, 87.0)
|
||||
font.setBold(False)
|
||||
|
||||
self.lexer.setDefaultFont(font)
|
||||
self.lexer.setColor(Qt.red, 1)
|
||||
@ -209,9 +206,9 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
|
||||
def insertInitText(self):
|
||||
#self.setLexers(False)
|
||||
txtInit = QCoreApplication.translate("PythonConsole",
|
||||
"## To access Quantum GIS environment from this console\n"
|
||||
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
|
||||
txtInit = QCoreApplication.translate("PythonConsole", "## Interactive Python Console for Quantum GIS\n\n")
|
||||
#"## To access Quantum GIS environment from this console\n"
|
||||
#"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
|
||||
initText = self.setText(txtInit)
|
||||
|
||||
def getText(self):
|
||||
@ -413,6 +410,16 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
## TODO: press event for auto-completion file directory
|
||||
else:
|
||||
QsciScintilla.keyPressEvent(self, e)
|
||||
|
||||
def contextMenuEvent(self, e):
|
||||
menu = QMenu(self)
|
||||
copyAction = menu.addAction("Copy CTRL+C")
|
||||
pasteAction = menu.addAction("Paste CTRL+V")
|
||||
action = menu.exec_(self.mapToGlobal(e.pos()))
|
||||
if action == copyAction:
|
||||
self.copy()
|
||||
elif action == pasteAction:
|
||||
self.paste()
|
||||
|
||||
def mousePressEvent(self, e):
|
||||
"""
|
||||
@ -458,18 +465,20 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
def insertFromDropPaste(self, textDP):
|
||||
pasteList = textDP.split("\n")
|
||||
for line in pasteList[:-1]:
|
||||
line.replace(">>> ", "").replace("... ", "")
|
||||
self.insert(line)
|
||||
self.move_cursor_to_end()
|
||||
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
|
||||
self.runCommand(unicode(self.currentCommand()))
|
||||
if pasteList[-1] != "":
|
||||
self.insert(unicode(pasteList[-1]))
|
||||
line = pasteList[-1]
|
||||
line.replace(">>> ", "").replace("... ", "")
|
||||
self.insert(unicode(line))
|
||||
self.move_cursor_to_end()
|
||||
|
||||
def getTextFromEditor(self):
|
||||
text = self.text()
|
||||
textList = text.split("\n")
|
||||
return textList
|
||||
# def getTextFromEditor(self):
|
||||
# text = self.text()
|
||||
# textList = text.split("\n")
|
||||
# return textList
|
||||
|
||||
def insertTextFromFile(self, listOpenFile):
|
||||
for line in listOpenFile[:-1]:
|
||||
@ -483,7 +492,7 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
|
||||
def entered(self):
|
||||
self.move_cursor_to_end()
|
||||
self.runCommand( unicode(self.currentCommand()) )
|
||||
self.runCommand( unicode(self.currentCommand()) )
|
||||
self.setFocus()
|
||||
self.move_cursor_to_end()
|
||||
#self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)
|
||||
@ -498,9 +507,14 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
return cmd
|
||||
|
||||
def runCommand(self, cmd):
|
||||
self.write_stdout(cmd)
|
||||
import webbrowser
|
||||
self.updateHistory(cmd)
|
||||
self.SendScintilla(QsciScintilla.SCI_NEWLINE)
|
||||
line, pos = self.getCursorPosition()
|
||||
selCmdLenght = self.text(line).length()
|
||||
self.setSelection(line, 0, line, selCmdLenght)
|
||||
self.removeSelectedText()
|
||||
#self.SendScintilla(QsciScintilla.SCI_NEWLINE)
|
||||
if cmd in ('_save', '_clear', '_clearAll', '_pyqgis', '_api'):
|
||||
if cmd == '_save':
|
||||
self.writeHistoryFile()
|
||||
@ -528,9 +542,6 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
elif cmd == '_api':
|
||||
webbrowser.open( "http://www.qgis.org/api/" )
|
||||
|
||||
output = sys.stdout.get_and_clean_data()
|
||||
if output:
|
||||
self.append(output)
|
||||
self.displayPrompt(False)
|
||||
else:
|
||||
self.buffer.append(cmd)
|
||||
@ -538,15 +549,14 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
|
||||
more = self.runsource(src, "<input>")
|
||||
if not more:
|
||||
self.buffer = []
|
||||
output = sys.stdout.get_and_clean_data()
|
||||
if output:
|
||||
self.append(output)
|
||||
self.move_cursor_to_end()
|
||||
self.displayPrompt(more)
|
||||
|
||||
def write(self, txt):
|
||||
self.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(txt), 1)
|
||||
self.append(txt)
|
||||
self.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(txt), 1)
|
||||
|
||||
sys.stderr.write(txt)
|
||||
|
||||
def write_stdout(self, txt):
|
||||
if len(txt) > 0:
|
||||
getCmdString = self.text()
|
||||
prompt = getCmdString[0:4]
|
||||
sys.stdout.write(prompt+txt+'\n')
|
||||
|
@ -52,9 +52,6 @@ class QgsRasterRenderer : QgsRasterInterface
|
||||
void setAlphaBand( int band );
|
||||
int alphaBand() const;
|
||||
|
||||
void setInvertColor( bool invert );
|
||||
bool invertColor() const;
|
||||
|
||||
/**Get symbology items if provided by renderer*/
|
||||
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
|
||||
|
||||
|
@ -195,6 +195,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
|
||||
tableTransparency->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
|
||||
|
||||
//resampling
|
||||
mResamplingGroupBox->setSaveCheckedState( true );
|
||||
const QgsRasterRenderer* renderer = mRasterLayer->renderer();
|
||||
mZoomedInResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
|
||||
mZoomedInResamplingComboBox->insertItem( 1, tr( "Bilinear" ) );
|
||||
@ -206,12 +207,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
|
||||
//set combo boxes to current resampling types
|
||||
if ( resampleFilter )
|
||||
{
|
||||
//invert color map
|
||||
if ( renderer->invertColor() )
|
||||
{
|
||||
mInvertColorMapCheckBox->setCheckState( Qt::Checked );
|
||||
}
|
||||
|
||||
const QgsRasterResampler* zoomedInResampler = resampleFilter->zoomedInResampler();
|
||||
if ( zoomedInResampler )
|
||||
{
|
||||
@ -744,9 +739,6 @@ void QgsRasterLayerProperties::apply()
|
||||
|
||||
//set global transparency
|
||||
rasterRenderer->setOpacity(( 255 - sliderTransparency->value() ) / 255.0 );
|
||||
|
||||
//invert color map
|
||||
rasterRenderer->setInvertColor( mInvertColorMapCheckBox->isChecked() );
|
||||
}
|
||||
|
||||
QgsDebugMsg( "processing general tab" );
|
||||
|
@ -57,7 +57,6 @@ QgsRasterInterface * QgsMultiBandColorRenderer::clone() const
|
||||
}
|
||||
renderer->setOpacity( mOpacity );
|
||||
renderer->setAlphaBand( mAlphaBand );
|
||||
renderer->setInvertColor( mInvertColor );
|
||||
renderer->setRasterTransparency( mRasterTransparency );
|
||||
|
||||
return renderer;
|
||||
@ -136,8 +135,7 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
|
||||
//In some (common) cases, we can simplify the drawing loop considerably and save render time
|
||||
bool fastDraw = ( !usesTransparency()
|
||||
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
|
||||
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement
|
||||
&& !mInvertColor );
|
||||
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
|
||||
|
||||
QSet<int> bands;
|
||||
if ( mRedBand > 0 )
|
||||
@ -290,13 +288,6 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
|
||||
blueVal = mBlueContrastEnhancement->enhanceContrast( blueVal );
|
||||
}
|
||||
|
||||
if ( mInvertColor )
|
||||
{
|
||||
redVal = 255 - redVal;
|
||||
greenVal = 255 - greenVal;
|
||||
blueVal = 255 - blueVal;
|
||||
}
|
||||
|
||||
//opacity
|
||||
double currentOpacity = mOpacity;
|
||||
if ( mRasterTransparency )
|
||||
|
@ -39,7 +39,6 @@ QgsRasterInterface * QgsPalettedRasterRenderer::clone() const
|
||||
QgsPalettedRasterRenderer * renderer = new QgsPalettedRasterRenderer( 0, mBand, colors(), mNColors );
|
||||
renderer->setOpacity( mOpacity );
|
||||
renderer->setAlphaBand( mAlphaBand );
|
||||
renderer->setInvertColor( mInvertColor );
|
||||
renderer->setRasterTransparency( mRasterTransparency );
|
||||
return renderer;
|
||||
}
|
||||
@ -179,14 +178,7 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
|
||||
}
|
||||
QColor& currentColor = mColors[val];
|
||||
|
||||
if ( mInvertColor )
|
||||
{
|
||||
outputBlock->setColor( i, qRgba( currentOpacity * currentColor.blue(), currentOpacity * currentColor.green(), currentOpacity * currentColor.red(), currentOpacity * 255 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
outputBlock->setColor( i, qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 ) );
|
||||
}
|
||||
outputBlock->setColor( i, qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 0, 0, 0, 0 );
|
||||
QgsRasterRenderer::QgsRasterRenderer( QgsRasterInterface* input, const QString& type )
|
||||
: QgsRasterInterface( input )
|
||||
, mType( type ), mOpacity( 1.0 ), mRasterTransparency( 0 )
|
||||
, mAlphaBand( -1 ), mInvertColor( false )
|
||||
, mAlphaBand( -1 ) //, mInvertColor( false )
|
||||
{
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ void QgsRasterRenderer::_writeXML( QDomDocument& doc, QDomElement& rasterRendere
|
||||
rasterRendererElem.setAttribute( "type", mType );
|
||||
rasterRendererElem.setAttribute( "opacity", QString::number( mOpacity ) );
|
||||
rasterRendererElem.setAttribute( "alphaBand", mAlphaBand );
|
||||
rasterRendererElem.setAttribute( "invertColor", mInvertColor );
|
||||
//rasterRendererElem.setAttribute( "invertColor", mInvertColor );
|
||||
|
||||
if ( mRasterTransparency )
|
||||
{
|
||||
@ -135,7 +135,7 @@ void QgsRasterRenderer::readXML( const QDomElement& rendererElem )
|
||||
mType = rendererElem.attribute( "type" );
|
||||
mOpacity = rendererElem.attribute( "opacity", "1.0" ).toDouble();
|
||||
mAlphaBand = rendererElem.attribute( "alphaBand", "-1" ).toInt();
|
||||
mInvertColor = rendererElem.attribute( "invertColor", "0" ).toInt();
|
||||
//mInvertColor = rendererElem.attribute( "invertColor", "0" ).toInt();
|
||||
|
||||
//todo: read mRasterTransparency
|
||||
QDomElement rasterTransparencyElem = rendererElem.firstChildElement( "rasterTransparency" );
|
||||
|
@ -92,8 +92,8 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
|
||||
void setAlphaBand( int band ) { mAlphaBand = band; }
|
||||
int alphaBand() const { return mAlphaBand; }
|
||||
|
||||
void setInvertColor( bool invert ) { mInvertColor = invert; }
|
||||
bool invertColor() const { return mInvertColor; }
|
||||
//void setInvertColor( bool invert ) { mInvertColor = invert; }
|
||||
//bool invertColor() const { return mInvertColor; }
|
||||
|
||||
/**Get symbology items if provided by renderer*/
|
||||
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const { Q_UNUSED( symbolItems ); }
|
||||
@ -124,7 +124,7 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
|
||||
Default: -1 (not set)*/
|
||||
int mAlphaBand;
|
||||
|
||||
bool mInvertColor;
|
||||
//bool mInvertColor;
|
||||
};
|
||||
|
||||
#endif // QGSRASTERRENDERER_H
|
||||
|
@ -36,7 +36,6 @@ QgsRasterInterface * QgsSingleBandColorDataRenderer::clone() const
|
||||
QgsSingleBandColorDataRenderer * renderer = new QgsSingleBandColorDataRenderer( 0, mBand );
|
||||
renderer->setOpacity( mOpacity );
|
||||
renderer->setAlphaBand( mAlphaBand );
|
||||
renderer->setInvertColor( mInvertColor );
|
||||
renderer->setRasterTransparency( mRasterTransparency );
|
||||
return renderer;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <QImage>
|
||||
|
||||
QgsSingleBandGrayRenderer::QgsSingleBandGrayRenderer( QgsRasterInterface* input, int grayBand ):
|
||||
QgsRasterRenderer( input, "singlebandgray" ), mGrayBand( grayBand ), mContrastEnhancement( 0 )
|
||||
QgsRasterRenderer( input, "singlebandgray" ), mGrayBand( grayBand ), mGradient( BlackToWhite ), mContrastEnhancement( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ QgsRasterInterface * QgsSingleBandGrayRenderer::clone() const
|
||||
QgsSingleBandGrayRenderer * renderer = new QgsSingleBandGrayRenderer( 0, mGrayBand );
|
||||
renderer->setOpacity( mOpacity );
|
||||
renderer->setAlphaBand( mAlphaBand );
|
||||
renderer->setInvertColor( mInvertColor );
|
||||
renderer->setRasterTransparency( mRasterTransparency );
|
||||
if ( mContrastEnhancement )
|
||||
{
|
||||
@ -57,6 +56,11 @@ QgsRasterRenderer* QgsSingleBandGrayRenderer::create( const QDomElement& elem, Q
|
||||
QgsSingleBandGrayRenderer* r = new QgsSingleBandGrayRenderer( input, grayBand );
|
||||
r->readXML( elem );
|
||||
|
||||
if ( elem.attribute( "gradient" ) == "WhiteToBlack" )
|
||||
{
|
||||
r->setGradient( WhiteToBlack ); // BlackToWhite is default
|
||||
}
|
||||
|
||||
QDomElement contrastEnhancementElem = elem.firstChildElement( "contrastEnhancement" );
|
||||
if ( !contrastEnhancementElem.isNull() )
|
||||
{
|
||||
@ -149,7 +153,7 @@ QgsRasterBlock* QgsSingleBandGrayRenderer::block( int bandNo, QgsRectangle cons
|
||||
grayVal = mContrastEnhancement->enhanceContrast( grayVal );
|
||||
}
|
||||
|
||||
if ( mInvertColor )
|
||||
if ( mGradient == WhiteToBlack )
|
||||
{
|
||||
grayVal = 255 - grayVal;
|
||||
}
|
||||
@ -184,6 +188,18 @@ void QgsSingleBandGrayRenderer::writeXML( QDomDocument& doc, QDomElement& parent
|
||||
_writeXML( doc, rasterRendererElem );
|
||||
|
||||
rasterRendererElem.setAttribute( "grayBand", mGrayBand );
|
||||
|
||||
QString gradient;
|
||||
if ( mGradient == BlackToWhite )
|
||||
{
|
||||
gradient = "BlackToWhite";
|
||||
}
|
||||
else
|
||||
{
|
||||
gradient = "WhiteToBlack";
|
||||
}
|
||||
rasterRendererElem.setAttribute( "gradient", gradient );
|
||||
|
||||
if ( mContrastEnhancement )
|
||||
{
|
||||
QDomElement contrastElem = doc.createElement( "contrastEnhancement" );
|
||||
|
@ -29,6 +29,12 @@ class QDomElement;
|
||||
class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer
|
||||
{
|
||||
public:
|
||||
enum Gradient
|
||||
{
|
||||
BlackToWhite,
|
||||
WhiteToBlack
|
||||
};
|
||||
|
||||
QgsSingleBandGrayRenderer( QgsRasterInterface* input, int grayBand );
|
||||
~QgsSingleBandGrayRenderer();
|
||||
QgsRasterInterface * clone() const;
|
||||
@ -43,6 +49,9 @@ class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer
|
||||
/**Takes ownership*/
|
||||
void setContrastEnhancement( QgsContrastEnhancement* ce );
|
||||
|
||||
void setGradient( Gradient theGradient ) { mGradient = theGradient; }
|
||||
Gradient gradient() const { return mGradient; }
|
||||
|
||||
void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;
|
||||
|
||||
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
|
||||
@ -51,6 +60,7 @@ class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer
|
||||
|
||||
private:
|
||||
int mGrayBand;
|
||||
Gradient mGradient;
|
||||
QgsContrastEnhancement* mContrastEnhancement;
|
||||
};
|
||||
|
||||
|
@ -63,7 +63,6 @@ QgsRasterInterface * QgsSingleBandPseudoColorRenderer::clone() const
|
||||
|
||||
renderer->setOpacity( mOpacity );
|
||||
renderer->setAlphaBand( mAlphaBand );
|
||||
renderer->setInvertColor( mInvertColor );
|
||||
renderer->setRasterTransparency( mRasterTransparency );
|
||||
|
||||
return renderer;
|
||||
@ -165,14 +164,6 @@ QgsRasterBlock* QgsSingleBandPseudoColorRenderer::block( int bandNo, QgsRectangl
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( mInvertColor )
|
||||
{
|
||||
// 1.8 was flipping blue and red
|
||||
red = 255 - red;
|
||||
green = 255 - green;
|
||||
blue = 255 - blue;
|
||||
}
|
||||
|
||||
if ( !hasTransparency )
|
||||
{
|
||||
outputBlock->setColor( i, qRgba( red, green, blue, 255 ) );
|
||||
|
@ -23,6 +23,9 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
mGradientComboBox->insertItem( 0, tr( "Black to white" ), QgsSingleBandGrayRenderer::BlackToWhite );
|
||||
mGradientComboBox->insertItem( 1, tr( "White to black" ), QgsSingleBandGrayRenderer::WhiteToBlack );
|
||||
|
||||
mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) );
|
||||
mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) );
|
||||
|
||||
@ -36,7 +39,12 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer
|
||||
|
||||
mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
|
||||
mMinMaxWidget->setExtent( extent );
|
||||
layout()->addWidget( mMinMaxWidget );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
layout->setContentsMargins( 0, 0, 0, 0 );
|
||||
mMinMaxContainerWidget->setLayout( layout );
|
||||
layout->addWidget( mMinMaxWidget );
|
||||
|
||||
connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
|
||||
this, SLOT( loadMinMax( int, double, double, int ) ) );
|
||||
|
||||
@ -84,6 +92,9 @@ QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer()
|
||||
|
||||
QgsSingleBandGrayRenderer* renderer = new QgsSingleBandGrayRenderer( provider, band );
|
||||
renderer->setContrastEnhancement( e );
|
||||
|
||||
renderer->setGradient(( QgsSingleBandGrayRenderer::Gradient ) mGradientComboBox->itemData( mGradientComboBox->currentIndex() ).toInt() );
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@ -127,6 +138,8 @@ void QgsSingleBandGrayRendererWidget::setFromRenderer( const QgsRasterRenderer*
|
||||
//band
|
||||
mGrayBandComboBox->setCurrentIndex( mGrayBandComboBox->findData( gr->grayBand() ) );
|
||||
const QgsContrastEnhancement* ce = gr->contrastEnhancement();
|
||||
|
||||
mGradientComboBox->setCurrentIndex( mGradientComboBox->findData( gr->gradient() ) );
|
||||
//minmax
|
||||
mMinLineEdit->setText( QString::number( ce->minimumValue() ) );
|
||||
mMaxLineEdit->setText( QString::number( ce->maximumValue() ) );
|
||||
|
@ -278,7 +278,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
|
||||
for ( int i = 0; i < numberOfEntries; ++i )
|
||||
{
|
||||
QColor currentColor;
|
||||
currentColor.setRgb( colorDiff*i, 0, 255 - colorDiff * i );
|
||||
int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
|
||||
currentColor.setRgb( colorDiff*idx, 0, 255 - colorDiff * idx );
|
||||
entryColors.push_back( currentColor );
|
||||
}
|
||||
}
|
||||
@ -286,7 +287,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
|
||||
{
|
||||
for ( int i = 0; i < numberOfEntries; ++i )
|
||||
{
|
||||
entryColors.push_back( colorRamp->color((( double ) i ) / numberOfEntries ) );
|
||||
int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
|
||||
entryColors.push_back( colorRamp->color((( double ) idx ) / numberOfEntries ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>258</width>
|
||||
<height>203</height>
|
||||
<width>463</width>
|
||||
<height>298</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -16,17 +16,17 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="mContrastEnhancementLabel">
|
||||
<property name="text">
|
||||
<string>Contrast enhancement</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="mMinLineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="mContrastEnhancementComboBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
@ -36,7 +36,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="mMinLabel">
|
||||
<property name="text">
|
||||
<string>Min</string>
|
||||
@ -46,18 +46,57 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mGrayBandComboBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="mMaxLabel">
|
||||
<property name="text">
|
||||
<string>Max</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="mMaxLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Color gradient</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="mGradientComboBox"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>140</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="mMinMaxContainerWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -345,6 +345,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="mInvertCheckBox">
|
||||
<property name="text">
|
||||
<string>Invert colors order</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -356,7 +363,6 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<zorder>grpGenerateColorMap</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user