Erase portion from UIBezierpath - uibezierpath

I have drawn some line using UIBezierpath.
Now I wanted to erase some portion of that line.
How can I erase any specific area of a line drawn by UIBezierpath

You can not remove part of UIBezierPath.
Remove old path:
oldPath = nil which clears the old bezier path! and call setNeedsDisplay on the view where you draw.
Create new UIBezierPath without that part.
And set new path.

Related

Is it possible to set a clip path on a QImage or save what a Qpainter paints?

I have a QImage I am able to clip out a QRegion of and successfully clip out the region using the QPainter class setClipRegion() function. However, I want to save what is drawn as a new QImage but am not seeing anything in the docs about saving what is actually displayed.
I've tried directly changing the images alpha channel to match the clipping region but my implementation is very inefficient. The setClipRegion() function was the only thing I learned that could efficiently display what I wanted. My end goal is to use the clipped image as a QOpenGLTexture so I somehow need to save the originally clipped image.
Thanks for any help.
You can simply specify a new file name when saving. so you do not overwrite the old one.
image = QtGui.QImage('orginal.png')
output = QtGui.QImage(image.size(), QtGui.QImage.Format_ARGB32)
output.fill(QtCore.Qt.transparent)
painter = QtGui.QPainter(output)
....
-> your clip path
....
painter.drawImage(QtCore.QPoint(), image)
painter.end()
output.save('new.png')

How does one use a CDSView with MultiLine on GMAPPlot?

(First Question so apologies)
Bokeh 1.3.4
Situation:
I am trying top map a Bokeh MultiLine using a CDSView and all the existing examples seem to use the "figure" object which has a helper (multi_line) which accepts a view as an argument. I am doing this on top of a GMAPPlot which does not support multi_line (only MultiLine) (see below). The commented out line throws an error saying GMAPPlot does not support multi_line.
plot = GMapPlot(
x_range=Range1d(), y_range=Range1d(), map_options=map_options, sizing_mode='scale_height'
)
.
.
.
sel_sa1s = []
v_bf = [True if sa1_val in sel_sa1s else False for sa1_val in v_source.data['SA1']]
v_view = CDSView(source=v_source, filters=[BooleanFilter(v_bf)])
v_ml = MultiLine(xs="xs",ys="ys",line_color="black", line_width="w")
#v_rend = plot.multi_line(xs="xs",ys="ys",line_color="black", line_width="w", source=v_source, view=v_view)
v_rend = plot.add_glyph(v_source, v_ml, name='votes')
The snippet shown above works and maps the entire network (very crowded) because there is no filter. What I want to have happen is for the filter to be initialised to hide everything then when the user clicks on an area (SA1) it will display the network related to that SA1.
Actually I can do that but only one area at a time and it would be much more efficient to be able to load the whole map and use a filtered view to control which sub-networks are displayed.
It seems that GMAPPlot only likes the pattern:
create glyph
add glyph
So, my question is - how does one use a CDSView in this environment (how does one add it to the renderer?)
Screenshot of unfiltered data set
It seems that GMAPPlot only likes the pattern:
create glyph
add glyph
That has not been true for some time. There is a higher level bokeh.plotting.gmap function that creates and configures GMapPlot instances with deafult axes, etc, and also has all the same methods and conveniences as figure (e.g. multi_line). It will be much less work to go this route than assembling everything by hand from low-level objects.

Is there a way to make a plugin display lines 'between' numbered lines in atom?

In the atom editor I'd like to be able to create notes 'in between' the lines of a file. I'm more than happy to do this via a plugin, but I'm wondering if someone more experienced in the API can confirm whether it's even possible before I dive in.
Basically, if I open a file with 10 lines, I want to be able to 'insert' new lines between some of them (which will be saved to another file), while still maintaining the line numbering of the original file. Eg:
1 Hello
2 World
. This is a note line saved in another file 'attached' to line 2
3 Foo
4 Etc
Think along the lines of inline comments on GitHub.
You can use block decorations to inject text between two lines:
A block decoration is a special kind of decoration that allows you to insert a DOM node before or after a certain line, and have it follow the line as the buffer changes. You can see it in action by running the snippet below in the DevTools:
var element = document.createElement('div')
element.textContent = 'Block decorations! 🐲'
var editor = atom.workspace.getActiveTextEditor()
var marker = editor.markScreenPosition([0, 0])
editor.decorateMarker(marker, {type: 'block', position: 'before', item: element})
In your case, you would be injecting text rather than GIFs, but you get the idea!

How to refer to source file related line numbers in Qt5 code editor?

It is a replacement of the migrated question
https://stackoverflow.com/questions/36681197/qt5-code-editor-sreen-or-source-line-numbering
I want to highlight a source line using the function below. Basically it works, but when I have a long comment line and the line wraps, the highlighted area is shifted to a wrong line. Reformatting the window size, it works OK, so I guess that the line number refers to the screen line number, rather than the source line number of the document. Is there any option which fixes this difference?
void CodeEditor::setCursorToLine(unsigned int lineno)
{
QTextBlock text_block = document()->findBlockByLineNumber(lineno-1);
QTextCursor text_cursor = textCursor ();
text_cursor.setPosition(text_block.position());
setFocus();
text_cursor.select(QTextCursor::BlockUnderCursor);
setTextCursor(text_cursor);
}

QPlainTextEdit truncate history linewise

I have a GUI application whose main part is a QPlainTextEdit. It is used to display a log of the application, and as such the associated text grows line by line ad infinitum.
As the application is intended to run very long, I need to limit the memory that will be allocated for this log. Therefore I want to have some maxNumLines or maxNumCharacters parameter that will make sure the history will be truncated when reached, i.e. the head lines will be removed as new lines are appended (a.k.a. log rotation).
To achieve this I found the functions
// get the associated text
QString toPlainText () const
// set the associated text
void setPlainText ( const QString & text )
Therefore something like this untested code would probably do the trick:
QString &tmp = pte.toPlainText();
while (tmp.size() > maxNumCharacters) {
// remove lines from the head of the string until the desired size is reached
// removes nothing if "\n" could not be found
tmp.remove(0, tmp.indexOf("\n")+1);
}
pte.setPlainText( tmp );
Is this the way to go to remove the first line(s) from the QPlainTextEdit? Are there probably other Qt Text GUI elements that would better fit to this task (set a maximum number of lines and truncate at the head of the list), e.g. somehow display a QStringList in which I could store the lines (s.t. I could easily erase(0))?
Or does the QPlainTextEdit eventually implement such upper bound for the size of the associated QString after all?
Apparantly the property maximumBlockCount is exactly what I need:
If you want to limit the total number of paragraphs in a QPlainTextEdit, as it is for example useful in a log viewer, then you can use the maximumBlockCount property. The combination of setMaximumBlockCount() and appendPlainText() turns QPlainTextEdit into an efficient viewer for log text.
For reference:
http://doc.qt.io/qt-5/qplaintextedit.html#maximumBlockCount-prop
I had exactly the same problem a months back, and I ended up using a QListView. Although using the model/view/delegate architecture is a bit more fiddly, it scales much better in the long run. For example once the basic architecture is in place, adding a filter that displays only error or warning entries becomes trivial, or creating a delegate so that the background of error entries are painted red is also straightforward.

Resources