add remove function
discovered memleak
This commit is contained in:
parent
f4450e7e3d
commit
74fe888188
@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
/*var imgproviderstr = `import QtQuick 2.4
|
||||
|
||||
Image {
|
||||
@ -21,4 +22,9 @@ func imgProvider(id string, width, height int) image.Image {
|
||||
var img1 image.Image = image.NewRGBA(image.Rect(0, 0, 340, 480))
|
||||
return img1
|
||||
}
|
||||
=======
|
||||
func imgProvider(id string, width, height int) image.Image {
|
||||
i, _ := strconv.Atoi(id)
|
||||
return slides[i].getImage(width, height)
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package main
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/gographics/imagick/imagick"
|
||||
"gopkg.in/gographics/imagick.v2/imagick"
|
||||
)
|
||||
|
||||
func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize, center bool) (resmw *imagick.MagickWand) {
|
||||
|
44
main.go
44
main.go
@ -7,17 +7,18 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/go-gl/gl/v2.1/gl"
|
||||
"github.com/go-gl/glfw/v3.1/glfw"
|
||||
"github.com/gographics/imagick/imagick"
|
||||
"github.com/kardianos/osext"
|
||||
"github.com/lordwelch/qml"
|
||||
"gopkg.in/gographics/imagick.v2/imagick"
|
||||
)
|
||||
|
||||
type cell struct {
|
||||
text string
|
||||
img imagick.Image
|
||||
img *imagick.MagickWand
|
||||
qmlimg qml.Object
|
||||
qmlcell qml.Object
|
||||
index int
|
||||
@ -48,7 +49,6 @@ func main() {
|
||||
}
|
||||
|
||||
defer glfw.Terminate()
|
||||
fmt.Println("test")
|
||||
|
||||
}
|
||||
|
||||
@ -241,6 +241,15 @@ func setSignals() {
|
||||
slides.addCell()
|
||||
})
|
||||
|
||||
window.ObjectByName("btnRem").On("clicked", func() {
|
||||
slides[len(slides)-1].remove()
|
||||
fmt.Println("testing....")
|
||||
})
|
||||
|
||||
window.ObjectByName("btnMem").On("clicked", func() {
|
||||
debug.FreeOSMemory()
|
||||
})
|
||||
|
||||
window.On("closing", func() {
|
||||
fmt.Println(window.Bool("cls"))
|
||||
win.Hide()
|
||||
@ -268,7 +277,8 @@ func setSignals() {
|
||||
}
|
||||
|
||||
func (cl cell) getImage(x, y int) (img *image.RGBA) {
|
||||
mw := imagick.NewMagickWandFromImage(&cl.img)
|
||||
mw := cl.img.GetImage()
|
||||
//mw := imagick.NewMagickWandFromImage(cl.img)
|
||||
if (x == 0) || (y == 0) {
|
||||
x = int(mw.GetImageWidth())
|
||||
y = int(mw.GetImageHeight())
|
||||
@ -315,9 +325,8 @@ func (sl *slide) addCell( /*cl *cell*/ ) {
|
||||
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
|
||||
cl.qmlcell.Set("index", cl.index)
|
||||
|
||||
mw := imagick.NewMagickWand()
|
||||
mw.ReadImage("logo:")
|
||||
cl.img = *mw.GetImageFromMagickWand()
|
||||
cl.img = imagick.NewMagickWand()
|
||||
cl.img.ReadImage("logo:")
|
||||
|
||||
cl.text = "testing 1... 2... 3..."
|
||||
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
||||
@ -332,6 +341,27 @@ func (sl *slide) addCell( /*cl *cell*/ ) {
|
||||
|
||||
}
|
||||
|
||||
func (cl *cell) remove() {
|
||||
cl.text = ""
|
||||
cl.qmlimg.Destroy()
|
||||
cl.img.Destroy()
|
||||
cl.qmlcell.Destroy()
|
||||
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")-1)
|
||||
slides.remove(cl.index)
|
||||
cl.index = -1
|
||||
|
||||
}
|
||||
|
||||
func (sl *slide) remove(i int) {
|
||||
//*sl = append((*sl)[:i], (*sl)[i+1:]...)
|
||||
|
||||
/*copy((*sl)[i:], (*sl)[i+1:])
|
||||
(*sl)[len(*sl)-1] = nil // or the zero value of T
|
||||
*sl = (*sl)[:len((*sl))-1]*/
|
||||
// or, more simply:
|
||||
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
||||
}
|
||||
|
||||
func (cl cell) String() string {
|
||||
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
||||
}
|
||||
|
33
main.qml
33
main.qml
@ -80,18 +80,20 @@ ApplicationWindow {
|
||||
id: scview
|
||||
anchors.fill: parent
|
||||
anchors.margins: 4
|
||||
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
|
||||
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
|
||||
|
||||
SplitView {
|
||||
id: gridData
|
||||
objectName: "gridData"
|
||||
width: scview.width
|
||||
height: gridRect.count*100
|
||||
width: scview.width - 1
|
||||
height: gridRect.count * 101
|
||||
|
||||
Rectangle {
|
||||
id: col1
|
||||
objectName: "col1"
|
||||
width: gridData.width / 2
|
||||
color: "#e41616"
|
||||
color: "#00000000"
|
||||
transformOrigin: Item.TopLeft
|
||||
border.width: 0
|
||||
Rectangle {
|
||||
@ -151,19 +153,14 @@ ApplicationWindow {
|
||||
id: data1
|
||||
objectName: "data1"
|
||||
spacing: 1
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
|
||||
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: col2
|
||||
objectName: "col2"
|
||||
color: "#4f90e2"
|
||||
color: "#00000000"
|
||||
border.width: 0
|
||||
|
||||
Column {
|
||||
@ -198,6 +195,22 @@ ApplicationWindow {
|
||||
y: 8
|
||||
text: qsTr("Button")
|
||||
}
|
||||
|
||||
Button {
|
||||
id: button2
|
||||
x: 8
|
||||
y: 39
|
||||
text: qsTr("Button")
|
||||
objectName: "btnRem"
|
||||
}
|
||||
|
||||
Button {
|
||||
id: button3
|
||||
x: 8
|
||||
y: 70
|
||||
text: qsTr("Button")
|
||||
objectName: "btnMem"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user