Retrieve corresponding QStandardItem when rightclicked (contextMenu) on QTreeView - contextmenu

I have a QTreeView with names. I added a contextMenu as here:
_treeMenu = new QMenu(myTreeView);
_editTreeViewAction = new QAction("Edit Selection", _treeMenu);
_deleteTreeViewAction = new QAction("Delete Selection",_treeMenu);
myTreeView->addAction(_editTreeViewAction);
myTreeView->addAction(_deleteTreeViewAction);
myTreeView->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(_editTreeViewAction, SIGNAL(triggered(bool)), this, SLOT(onEdit(bool)));
connect(_deleteTreeViewAction, SIGNAL(triggered(bool)), this, SLOT(onDelete(bool)));
When I hit 'Edit Selection', SLOT onEdit() is properly triggered. But here I need the QStadardItem (* Pointer or at least its text()) from the QTreeView where I rightclicked ? How can I access that?

That solves myissue:
myTreeView.currenIndex();

Related

In Networkx is there a way to select when to save to a file, when show on screen and when both?

At the moment, I am doing both:
pos = nx.spring_layout(G)
f1 = plt.figure(figsize=(18,10))
default_axes = plt.axes(frameon=True)
nx.draw_networkx(G, node_size=600, alpha=0.8, ax=default_axes, pos=pos)
edge_labels = nx.get_edge_attributes(G, "weight")
nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=edge_labels)
plt.savefig('graph.jpg')
I would like to be able to select if to display, save or both (what I am doing now)
There is no built-in option for that in networkx. One option is to wrap the code in a function along these lines:
def custom(G, plot=True, save_file=False):
'''plots G by default. save_file should be a string'''
pos = nx.spring_layout(G)
f1 = plt.figure(figsize=(18,10))
default_axes = plt.axes(frameon=True)
nx.draw_networkx(G, node_size=600, alpha=0.8, ax=default_axes, pos=pos)
edge_labels = nx.get_edge_attributes(G, "weight")
nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=edge_labels)
if save: plt.savefig(save) # can allow custom save name
if plot: plt.show()
return
Note that if the figure displays regardless of the option passed to the command, then the inline option might need to be disabled.

How to change direction of existing link in zoomcharts

I'm trying to do it like this
function btnChangeDirClick(){
var fromNode = document.getElementById("linkMenuLinkFrom").value;
var toNode = document.getElementById("linkMenuLinkTo").value;
chart.addData({
links:[{id:document.getElementById("linkMenuLinkid").value,
from:toNode,
to:fromNode
}]
});
}
but my console returns
Changing link from,to not supported
Of course it's possible to delete and recreate, but are there any alternatives?
One alternative is to store a direction flag in data and assign from and to decorations depending on it.
I suggest using delete/recreate for now. Link reconnection support will come.
Finally I ended up implementing is as follows, which works fine:
function btnChangeDirClick(){
var fromNode = document.getElementById("linkMenuLinkFrom").value;
var toNode = document.getElementById("linkMenuLinkTo").value;
chart.removeData({links:[{id:document.getElementById("linkMenuLinkid").value}]});
chart.addData({
links:[{
"id":document.getElementById("linkMenuLinkid").value,
from:toNode,
to:fromNode,
"style":{label:document.getElementById("linkMenuLinklabel").value}
}]
});
nextId += 1;
document.getElementById("linkMenuLinkFrom").value = toNode;
document.getElementById("linkMenuLinkTo").value = fromNode;
}

How to share functions in Coffeescript? Rails

I have one function that should be used in two different events, but I can't make it work. Where am I making a mistake? Or do I have to use Class instead?
coment_error = (that) ->
$this = $(that)
$new_answer = $this.parent('.new_answer')
$new_answer.on('ajax:success',((evt, data, status, xhr)->
$new_answer.hide()
$('.open').show()
))
$new_answer.on('ajax:error',((evt, data, status, xhr)->
$(this).addClass("error")
))
$(document).on("click", ".new_answer > INPUT[type='submit']", coment_error($(this)))
$(document).on("click", ".new_comment > INPUT[type='submit']", coment_error($(this)))
I think the problem is that the last two lines execute the function immediately instead of when the events are called.
$(document).on("click", ".new_answer > INPUT[type='submit']", coment_error)
Also you don't want coment_error to receive "that" because "this" will automatically be bound to the clicked element. So you can get right down to $this = $(this).

How can I set the value of a textbox in Dart?

I have a textbox field with id="textbox1". How do I set its value?
This is what I tried:
query('#textbox1').text = 'test 123';
But it did not work.
InputElement input = querySelector("#textbox1");
input.value = "test123";
Tips : When you use querySelector(selector) you can type the result with what you expect (a InputElement here). Thus, editor will provide content assist to help you.
Note that query is now deprecated. For all those that find this through Google as I did, here is updated
InputElement input = querySelector("#textbox1");
input.value = "test123";

How can I protect an excel sheet, except for a particular cell using Open XML 2.0?

I am generating a report using OpenXML and exporting it to excel. I want to protect the excel sheet except for a particular cell.
If anyone has worked on this before, kindly help
Thanks,
Amolik
PageMargins pageM = worksheetPart.Worksheet.GetFirstChild<PageMargins>();
SheetProtection sheetProtection = new SheetProtection();
sheetProtection.Password = "CC";
sheetProtection.Sheet = true;
sheetProtection.Objects = true;
sheetProtection.Scenarios = true;
ProtectedRanges pRanges = new ProtectedRanges();
ProtectedRange pRange = new ProtectedRange();
ListValue<StringValue> lValue = new ListValue<StringValue>();
lValue.InnerText = "A1:E1"; //set cell which you want to make it editable
pRange.SequenceOfReferences = lValue;
pRange.Name = "not allow editing";
pRanges.Append(pRange);
worksheetPart.Worksheet.InsertBefore(sheetProtection, pageM);
worksheetPart.Worksheet.InsertBefore(pRanges, pageM);
ref : http://social.msdn.microsoft.com/Forums/en-US/a6f7502d-3867-4d5b-83a9-b4e0e211068f/how-to-lock-specific-columns-in-xml-workbook-while-exporting-dataset-to-excel?forum=oxmlsdk
Have you tried using the OpenXML Productivity Toolkit?
from what I can see you have to add a
new CellFormat
with attribute
ApplyProtection = true
to
CellFormats
append
new Protection
with attribute
Locked = false
to the the CellFormat you created.
CellFormat is a element of CellFormats which is a element of Stylesheet
then to the Worksheet you add a
new SheetProtection(){ Password = "CC1A", Sheet = true, Objects = true, Scenarios = true };
I havent tried this, but it should be easy enought to find out what you need to do with the Productivity Toolkit. I hope this points you and anyone trying to do this in the right direction.

Resources