How can I update a QTextEdit on another QTabWidget tab? - qt5

I have two tabs (QTabWidget). On the first tab are the options when checked tell me what text to send to the second tab (in a QTextEdit field). Then I have a QPushButton to generate the text. The problem I have is to send this text to the second tab.
FenPrincipale::FenPrincipale(QWidget *parent) : QWidget(parent)
{
ongletGenerateur = new OngletGenerateur(this);
ongletTexte = new OngletTexte(this);
tabWidget = new QTabWidget;
tabWidget->addTab(ongletGenerateur, "Options de génération");
tabWidget->addTab(ongletTexte, "Texte");
m_generer = new QPushButton("&Générer !");
.
. layout
.
connect(m_generer, &QPushButton::clicked, ongletGenerateur, &OngletGenerateur::genererCode);
}
void OngletGenerateur::genererCode()
{
.
.
.
texte += "some text";
??? how do I send the texte to the second tab (ongletTexte) ???
}
OngletTexte::OngletTexte(QWidget *parent) : QWidget(parent)
{
m_texteGenere = new QTextEdit;
m_texteGenere->setPlainText("Bla, bla, bla"):
.
.
.
}
Thanks!

Just create a signal in your OngletGenerateur class with one parameter (your string). Emit it from your method. Create a slot in OngletTexte. Then, connect the signal and the slot together in FenPrincipale.
class OngletGenerateur
{
...
signals:
textGenerated(QString);
};
class OngletTexte
{
...
public slots:
void append(QString text)
{
m_texteGenere->append(text);
}
};
FenPrincipale::FenPrincipale(QWidget *parent) : QWidget(parent)
{
connect(ongletGenerateur, &OngletGenerateur::textGenerated, ongletText, &OngletTexte::append);
}

Related

How to get similar behaviour as the Java browsing perspective with two commonNavigator views?

I'd like to reproduce the behavior of the Java browsing perspective as so : the user select a file (selectedFile) from a Custom Common Navigator View (VariabilityNavigator) and it displays only the related files to that selection in another Custom Common Navigator View (ConfigFileNavigator). It refreshes automatically as the selection goes.
I use Common navigator because I want to display the package of the related files and not the other ones or the empty ones. That I coded fine.
Could you please walk me thru the steps to do that ? Here is how far I got..
I have successfully coded the first view VariabilityNavigator.
I thought I would use a filter ConfigurationFilesFilter to get the selectedFile and use it to filter the related files.
I can get the selection from the VariabilityNavigator within the select(...) of ConfigurationFilesFilter code below
I then use it to filter the files I want to display using isRelatedToSelection. I haven't write that part yet, but it's not a problem for testing.
This method don't work for several reasons : it doesn't refresh and I have to click on the ConfigFileNavigator to get the result. What it should do : when I click on the first view and it should automatically display the result in the second view. Thanks for your help.
public class ConfigurationFilesFilter extends ViewerFilter {
String selectedFile;
public ConfigurationFilesFilter() {
}
#Override
public boolean select(Viewer viewer, Object parent, Object element) {
selectedFile = getVariabilityNavigatorSelection();
if (isChildElement(element)) {
return handleChild(element);
} else {
// manipulate tree viewer based on select decision for the sub elements
StructuredViewer sviewer = (StructuredViewer) viewer;
ITreeContentProvider provider = (ITreeContentProvider) sviewer.getContentProvider();
for (Object child : provider.getChildren(element)) {
if (select(viewer, element, child)) {
return true;
}
}
return false;
}
}
/**
*
* #param element
* #return true to be displayed
*/
private boolean handleChild(Object element) {
return true;
}
/**
* Check if an element is a java file and if it is related to the selection
*
* #param element
* #return boolean
*/
private boolean isChildElement(Object element) {
if (element instanceof IFile) {
if (((IFile) element).getFileExtension().equals("java")) {
return (isRelatedToSelection((IFile) element));
}
return false;
}
return false;
}
public String getVariabilityNavigatorSelection() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView(VariabilityNavigator.ID);
String VariabilityNavigatorSelection = "" ;
if (viewPart == null) {
VariabilityNavigatorSelection = "open Variability view. \r\nTo do so, open the menu as followed:\r\nWindow > Show view > Other... > SPL > Variability Navigator";
} else {
ISelectionProvider selProvider = viewPart.getSite().getSelectionProvider();
IStructuredSelection sel = (IStructuredSelection) selProvider.getSelection();
if (sel.isEmpty()) {
VariabilityNavigatorSelection = "selection vide";
}
Iterator<?> i = sel.iterator();
while (i.hasNext()) {
final Object o = i.next();
if (o instanceof IFile) {
VariabilityNavigatorSelection = ((IFile) o).getName();
} else
VariabilityNavigatorSelection = "Please select a file";
}
}
if (!VariabilityNavigatorSelection.isEmpty())
printTrace("selectPrint = " + VariabilityNavigatorSelection);
return VariabilityNavigatorSelection;
}

what is "Dojo Name Text Box" onremove event?

I have a Dojo Name Text Box "xe:djextNameTextBox" on my form. By clicking [x] it removes a name from the list. How do I check what exact name was removed or clicked without parsing all values in getComponent("myNameBox").getValue()?
In my opinion the only way to handle this issue is to parse all values to get the information which name exactly was removed. I had to deal with the same problem in a previous project.
XPage
Set viewScope var "viewFiltersAsString":
<xp:this.beforeRenderResponse><![CDATA[#{javascript:log('beforerenderresponse (start rendering)');
requestScope.start = new Date().getTime();
viewScope.put('viewFiltersAsString', viewController.getViewFiltersAsString());
viewController.actionSetPage();}]]></xp:this.beforeRenderResponse>
Extension Library Dojo Name List Text Box control:
<xe:djextListTextBox id="djFilters" multipleSeparator=","
value="#{viewScope.viewFiltersAsString}" displayLabel="true"
title="Hier klicken um Filter zu löschen">
<xe:this.dataProvider>
<xe:simpleValuePicker caseInsensitive="false"
labelSeparator="~" valueListSeparator=","
valueList="#{viewController.viewFiltersLabelsAsString}">
</xe:simpleValuePicker>
</xe:this.dataProvider>
<xp:eventHandler event="onChange" submit="true" refreshMode="partial"
refreshId="${javascript:compositeData.refreshId}" execMode="partial"
action="#{javascript:viewController.setViewFiltersAsString(#Trim(viewScope.get('viewFiltersAsString')).toString())}">
</xp:eventHandler>
</xe:djextListTextBox>
Managed Bean "viewController"
/**
* Converts all filters to a useable format for dojo List Textbox
* #return string of filters
*/
public String getViewFiltersAsString() {
String filtersAsString = "";
for (ViewFilter filter : viewFilters) {
if (filtersAsString == "") filtersAsString = filter.getKey();
else filtersAsString += "," + filter.getKey();
}
return filtersAsString;
}
public void setViewFiltersAsString(String viewFiltersAsString) {
if (viewFiltersAsString != null && !viewFiltersAsString.equals("")) {
List<String> currentfilters = Converter.toList(",", viewFiltersAsString);
for (ViewFilter filter : viewFilters) {
boolean remove = true;
for (String currentFilter : currentfilters) {
if (filter.getKey().equals(currentFilter)) {
remove = false;
break;
}
}
if (remove) {
// user can click only one filter at one time
setActionViewFilter(viewFilters.removeFilter(filter));
break;
}
}
} else {
setActionViewFilter(viewFilters.removeFilter(viewFilters.get(0)));
}
}
Hint: viewFilters is a java.util.List of ViewFilter objects and a ViewFilter is a simple java class holding information about a filter (in your case a name)

Trying to make tables in mono develop

I just started using monodevelop and I am having a hard time to design the forms. I have understood the concept of widgets inside containes. I am trying to get a Table which is inside a scroll view. The Table should have 3 columns and I should be able to set the column names.
I have looked at some documentation by mono develop which shows how to use the Node View to do the same but I haven't been able to figure out why is it coming in a new window and how to get it on my first screen itself.Also is there any way I can drag and drop to the form to make my columns and table header? I have attached the code :
using System;
using Gtk;
namespace ImageCompressionTool
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
Gtk.Application.Init ();
NodeViewExample win1 = new NodeViewExample ();
win1.Show ();
Gtk.Application.Run ();
}
}
public class MyTreeNode : Gtk.TreeNode {
string song_title;
public MyTreeNode (string artist, string song_title)
{
Artist = artist;
this.song_title = song_title;
}
[Gtk.TreeNodeValue (Column=0)]
public string Artist;
[Gtk.TreeNodeValue (Column=1)]
public string SongTitle {get { return song_title; } }
}
public class NodeViewExample : Gtk.Window {
Gtk.NodeStore store;
Gtk.NodeStore Store {
get {
if (store == null) {
store = new Gtk.NodeStore (typeof (MyTreeNode));
store.AddNode (new MyTreeNode ("The Beatles", "Yesterday"));
store.AddNode (new MyTreeNode ("Peter Gabriel", "In Your Eyes"));
store.AddNode (new MyTreeNode ("Rush", "Fly By Night"));
}
return store;
}
}
public NodeViewExample () : base ("NodeView")
{
SetSizeRequest (200,150);
// Create our TreeView and add it as our child widget
Gtk.NodeView view = new Gtk.NodeView (Store);
Add (view);
// Create a column with title Artist and bind its renderer to model column 0
view.AppendColumn ("Artist", new Gtk.CellRendererText (), "text", 0);
// Create a column with title 'Song Title' and bind its renderer to model column 1
view.AppendColumn ("Song Title", new Gtk.CellRendererText (), "text", 1);
view.ShowAll ();
}
}
}
Kindly help me out. Thanks!
If you only want your NodeView window to be displayed then remove the code that is showing the MainWindow. Your Main method is currently showing two windows. If you just want it to show your NodeViewExample window then it should look like:
public static void Main (string[] args)
{
Gtk.Application.Init ();
NodeViewExample win1 = new NodeViewExample ();
win1.Show ();
Gtk.Application.Run ();
}
You cannot drag and drop columns into a Gtk.NodeView or Gtk.TreeView into the designer.

Show a Dialog() or MessageDialog() from the MainWindow.cs?

I'm trying to display a Dialog() or MessageDialog() from my MainWindow.cs (standard MainWindow.cs file that is created from the C# GTK# 2.0 Project template).
I'm getting a rather nasty error when using the below code:
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build();
}
public void CreateAlert(string message)
{
Console.WriteLine(string.Format("CreateAlert() - message: {0}", message));
Dialog dialog = new Dialog("Error", this, Gtk.DialogFlags.DestroyWithParent);
dialog.Modal = true;
dialog.AddButton ("OK", ResponseType.Close);
dialog.Response += on_dialog_response;
dialog.Run ();
dialog.Destroy ();
}
}
I believe the cause of this error is the second param in the Dialog() constructor - "this". My question is... how does one satisfy the second param of "Window win" when inside the MainWindow.cs?
Thanks in advance.

Telerik Mail Merge - Friendly Names (using RadRichTextBox)

I think i'm missing something obvious...
I'm using the Telerik Rad controls for WPF but i assume that the Rich text box uses some similar implementation for the mail merge functionality.
I want to have some friendly names on my mail merge fields. (namely spaces in the field names)
So i have a class for instance
Public Class someclass
{
<DisplayName("This is the complex description of the field")>
Public property thisfieldnamehasacomplexdescription as string
Public property anothercomplexfield as string
}
This is the only way i know to get "Friendly" names in the dropdown that is the mail merge.
So the two fields turn up okay as :
"This is the complex description of the field"
"anothercomplexfield"
but only anothercomplexfield actually populates with data when you do the merge.
Am i going to have to template the raddropdownbutton that holds the mail merge fields?
Is there an example of this somewhere?
Also a sub question. How do i add a scroll bar on these things?
(also i know this board is not a TELERIK specific board (duh!) but this might be useful to someone in the future. So i'll copy the answer i get from Telerik into here!
http://www.telerik.com/community/forums/wpf/richtextbox/558428-radrichtextbox-mailmerge---using-displayname-to-create-a-friendly-name-with-spaces.aspx )
This is what telerik gave me:
With the default MergeFields, it is not possible to change the display name fragment of the field in order to achieve a more friendly look. This should be possible if you implement a custom MergeField by deriving from the MergeField class. Here is a sample implementation that shows how this can be done:
public class CustomMergeField : MergeField
{
private const string CustomFieldName = "CustomField";
static CustomMergeField()
{
CodeBasedFieldFactory.RegisterFieldType(CustomMergeField.CustomFieldName, () => { return new CustomMergeField(); });
}
public override string FieldTypeName
{
get
{
return CustomMergeField.CustomFieldName;
}
}
public override Field CreateInstance()
{
return new CustomMergeField();
}
protected override DocumentFragment GetDisplayNameFragment()
{
return base.CreateFragmentFromText(string.Format(Field.DisplayNameFragmentFormat, this.GetFriendlyFieldName(this.PropertyPath)));
}
private string GetFriendlyFieldName(string fieldName)
{
int lettersInEnglishAlphabet = 26;
List<char> separators = new List<char>(lettersInEnglishAlphabet);
for (int i = 0; i < lettersInEnglishAlphabet; i++)
{
separators.Add((char)('A' + i));
}
StringBuilder newFieldName = new StringBuilder();
int previousIndex = 0;
for (int i = 1; i < fieldName.Length; i++)
{
if (separators.Contains(fieldName[i]))
{
if (previousIndex > 0)
{
newFieldName.Append(" ");
}
newFieldName.Append(fieldName.Substring(previousIndex, i - previousIndex));
previousIndex = i;
}
}
newFieldName.Append(" " + fieldName.Substring(previousIndex));
return newFieldName.ToString();
}
}
Note that the fragment that is shown when the DisplayMode is Code cannot be changed.
As for your other question, you can change the content of the dropdown button to show the friendly name of the fields and to include a scrollbar in the following way:
1. First, remove the binding of the button to the InsertMergeFieldEmptyCommand from XAML and give it a name (e.g. insertMergeField).
2. Next, add the following code in code-behind:
AddMergeFieldsInDropDownContent(this.insertMergeFieldButton);
private void AddMergeFieldsInDropDownContent(RadRibbonDropDownButton radRibbonDropDownButton)
{
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(100, GridUnitType.Pixel) });
ScrollViewer scrollViewer = new ScrollViewer();
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
StackPanel stackPanel = new StackPanel();
foreach (string fieldName in this.editor.Document.MailMergeDataSource.GetColumnNames())
{
RadRibbonButton fieldButton = new RadRibbonButton()
{
Text = this.GetFriendlyFieldName(fieldName),
Size = ButtonSize.Medium,
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Left
};
fieldButton.Command = this.editor.Commands.InsertFieldCommand;
fieldButton.CommandParameter = new MergeField() { PropertyPath = fieldName };
//or
//fieldButton.CommandParameter = new CustomMergeField() { PropertyPath = fieldName };
stackPanel.Children.Add(fieldButton);
}
stackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
scrollViewer.Content = stackPanel;
grid.Children.Add(scrollViewer);
radRibbonDropDownButton.DropDownContent = grid;
}
You can, of course optimize the code of the GetFriendlyName method and add it in a way that will be available by both classes.