How to add found item to a QListView using Qt? - search

I am trying to implement search option for my file browser application.
I can get the item after taking an input from the user. Now, I want to add this item to my listview. Also after the search is over, the item should be clickable to open them.
Here, is the piece of code... Any suggestions will be appreciated.
void Browser::search()
{
QDirIterator it(path,QDir::AllDirs|QDir::Files|QDir::NoSymLinks|QDir::NoDotAndDotDot,QDirIterator::Subdirectories);
while(it.hasNext())
{
it.next();
if(it.fileInfo().completeBaseName().contains(content,Qt::CaseInsensitive))
{
qDebug()<<"it.fileinfo = "<<it.fileInfo().fileName();
}
}
path.clear();
}

Instead of List View you can use List Widget and simply fill the list using method addItem or addItems. If your list is small/simple it doesn't in my opinion make sense to use Model-View paradigm.
Look at QListWidget in documentation

You should read more about model/view concept. You add data to your model not to a view. You'll find in this article sections "Editable items" and "Resizable models", which address your issue.

Related

OrchardCMS: How to access Content Menu Item boolean field in cshtml view

In orchard, I've added a boolean field called "IsDone" to the built in Content Menu Item content part via that Admin interface. I've then picked an item in Navigation and set the option to "yes" for the corresponding field i added.
In my custom theme, I've copied over MenuItem.cshtml.
How would I get the value of my custom "IsDone" field here?
I've tried something like
dynamic item = Model.ContentItem;
var myValue = item.MenuItem.IsDone.Value;
but I'm pretty sure my syntax is incorrect (because i get null binding errors at runtime).
thanks in advance!
First i suggest you use the shape alternate MenuItemLink-ContentMenuItem.cshtml instead of MenuItem.cshtml to target the content menu item directly.
Secondly, the field is attached to the ContentPart of the menu item. The following code retrieves the boolean field from this content part:
#using Orchard.ContentManagement;
#using System.Linq;
#{
Orchard.ContentManagement.ContentItem lContentItem = Model.Content.ContentItem;
var lBooleanField = lContentItem
.Parts
.Where(p => p.PartDefinition.Name == "ContentMenuItem") // *1
.SelectMany(p => p.Fields.Where(f => f.Name == "IsDone"))
.FirstOrDefault() as Orchard.Fields.Fields.BooleanField;
if (lBooleanField != null)
{
bool? v = lBooleanField.Value;
if (v.HasValue)
{
if (v.Value)
{
#("done")
}
else
{
#("not done")
}
}
else
{
#("not done")
}
}
}
*1
Sadly you cannot simply write lContentItem.As<Orchard.ContentManagement.ContentPart>() here as the first part in the part list is derived from this type, thus you would receive the wrong part.
While #ViRuSTriNiTy's answer is probably correct, it doesn't take advantage of the power of the dynamic objects that Orchard provides.
This is working for me but is a much shorter version:
#Model.Text
#{
bool? IsDone = Model.Content.ContentMenuItem.IsDone.Value;
var IsItDoneThough = (IsDone.HasValue ? IsDone.Value : false);
}
<p>Is it done? #IsItDoneThough</p>
You can see that in the first line I pull in the IsDone field using the dynamic nature of the Model.
For some reason (I'm sure there is a good one somewhere) the BooleanField uses a bool? as its backing value. This means that if you create the new menu item and just leave the checkbox blank it will be null when you query it. After you have saved it as checked it will be true and then if you go back and uncheck it then it will have the value false.
The second line that I've provided IsItDoneThough checks if it has a value yet. If it does then it uses that, otherwise it assumes it to be false.
Shape Alternate
#ViRuSTriNiTy's other advice, to change it to use the MenuItemLink-ContentMenuItem.cshtml instead of MenuItem.cshtml is also important.
The field doesn't exist on other menu items so it will crash if you try to access it. Just rename the .cshtml file to fix this.
Dynamic Model
Just to wrap this up with a little bit of insight as to how I got there (I'm still learning this as well) the way I figured it out is as follows:
.Content is a way of casting the current content item to dynamic, so you can use the dynamic advantages with the rest of line;
When you add the field in the admin panel it looks like it should be right there on the ContentItem, however it actually creates an invisible ContentPart to contain them and calls it whatever the ContentItem's type is.
So if you had added this field to a Page content type you would have used Model.Content.Page.IsDone.Value. If you had made a new content type called banana it would be Model.Content.Banana.IsDone.Value, etc.
Once you are inside the "invisible" part which holds the fields you can finally get at IsDone. This won't give you the actual value yet though. Each Field has its own properties which you can look up in the source code. the IsDone is actually a BooleanField and it exposes its data via the Value property.
Try doing a solution-wide search for : ContentField to see the classes for each of the fields you have available.
Hopefully this will have explained things clearly but I have actually written about using fields in a blog post and as part of my getting started with modules course over on the official docs (its way down in part 3 if you're curious).
Using built-in features instead of IsDone
This seems like a strange approach to do it this way. If you have a Content Item like a Page then you can just use the "Show on a menu" setting on the page.
Go to admin > content > open the page > down near the bottom you will find "Show on a menu":
This will automatically put it into your navigation and then you can move it around to where you want:
After it "IsDone" you can just go back and untick the "Show on a menu" option.
Setting up the alternative .cshtml
To clarify your comments about how to use the alternative, you need to
Copy the file you have at Orchard.Core/Shapes/Views/MenuItem.cshtml over to your theme's view folder so its /Views/MenuItem.cshtml
Rename the copy in your theme to MenuItem-ContentMenuItem.cshtml
Delete probably everything in it and paste in my sample at the start of this post. You don't want most of the original MenuItem.cshtml code in there as it is doing some special tricks to change itself into a different shape which isn't what you want.
Reset your original Orchard.Core/Shapes/Views/MenuItem.cshtml back to the factory default, grab it from the official Orchard repository
Understanding the view names
From your comments you asked about creating more specific views (known as alternates). You can use something call the Shape Tracer to view these. The name of them follows a certain pattern which makes them more and more specific.
You can learn about the alternates on the official docs site:
Accessing and Rendering Shapes
Alternates
To figure out what shape is being used and what alternates are available you can use the shape tracing module which is documented here:
Getting Started with Shape Tracing

Search operation in javafx tableview

I used the tutorial on link TUTORIAL LINK
Now I want to perform the search operation on tableview to search for table row contents to match the query.
So is there any way to to search for items in tableview.
Something I found in c# was the LINQ query which search in the list for condition.
Is there something similar in javafx.
Seems, there is nothing similar. You can file a RFE, or a Tweak, in JavaFX-2 jira, if you want to have such functionality (if it doesn't exist yet).
Or, if you know, how should it look like, you can talk to author of TableView, and implement it by yourself, and push according patch in an open javafx.
Practically, you can do a search over a collection of content of TableView, and apply value factory of each column for according value, and check, if it returns an appropriate value/content.
I saw a project like this once.
Maybe this is what your looking for: Advanced TableView
Sadly i have no idea how they implemented it.
EDIT The page i linked to states that you should go to the following page: TiwulFX
this is search method, where data is your list ,
private boolean search(String a ){
int i=0;
do{
if(data.get(i).getNom().equals(a) )
{
return true;
}
i++;
}while(data.size()>i);
return false;}
1) Get your TableView object
2) Call getItems() method on it
3) Call get() method the parameter for this method is the index of your object
TableView<String> tableView = new TableView<>();Now, suppose that we've already filled tableView with Products objects
You can reach to every object this way
tableView.getItems().get(0)
This will return the first object you added to tableView
I Hope This Helps ^_^

Loading existing data into MonoTouch.Dialog

I am new to MonoTouch from a VS/C# background and am trying to rewrite an existing c# app.
I have made one simple MonoTouch app which succesfully loads data into a List<> from an XML file, and was starting to add Master/Detail code when I discovered the existence of MonoTouch.Dialog which looked like it would make my job much easier. So I started a new project using the sample code at http://docs.xamarin.com/ios/tutorials/MonoTouch.Dialog , changing the basic class to match what I needed.
But I am stuck with trying to prepopulate the DialogViewController with my existing List<>. I have tried using LoadMoreElement but cannot find an example of its use and don't know if it's the best way of doing this.
Thanks Anders.
In the interim period I discovered a different method:
_rootElement = new RootElement ("Riders")
{
new Section()
{
from x in riderList.Riders select (Element) new RootElement(x.Name)
{
new Section()
{
new StringElement("Rider",x.Name),
new StringElement("Club",x.Club),
....
....
...ill try both and see what suits best.
But I'm struggling to find any documentation to describe the methods for the dialog classes, e.g. Section.AddAll() and others used in the link you have provided.
If you want to create a list within an existing dialog view, you can for example create an empty Section and to this section add the list the elements from the list as RadioElement:s or CheckboxElement:s, depending on how many elements you want to be able to select simultaneously.
To facilitate selection, you may need to create a Group/RadioGroup and reference this group when you create the respective list elements in your section.
Here is a quick example of creating a new Section and adding the list elements, assuming that only one element can be selected simultaneously:
var list = new List<SomeClass> { ... };
var listGroup = new RadioGroup("grp", 0);
var listSection = new Section();
listSection.AddAll(list.Select(elem =>
new RadioElement(elem.ToString(), "grp") as Element));
If you want more specialized handling of the elements in the list or the events associated with list actions, you may want to subclass RadioElement or CheckboxElement. There is a good example on how to do this in the answer to this SO question.

Best way to programmatically create/maintain SharePoint Quick Launch menu

We have a solution that deploys a number of lists and pages. We wan't to create links for them on the Quick Launch menu automatically when a feature is activated.
The structure could be something like this.
Customers
Active
Inactive
Sales
Quotes
Orders
And so on. The site collection admin might add another link between the "Active" and "Inactive" links. When the feature is deactivated I don't want to remove the items, but if the feature is activated again i don't want the navigation to be added again :)
Is there a built in API that you can use? I know about the SPWeb.Navigation.QuickLaunch and the SPNavigationNode(Collection) structure etc. But is there another way?
Hope you can help :)
What kind of other way would you be looking for?
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = (SPWeb)properties.Feature.Parent;
// Check for an existing link to the list.
SPNavigationNode listNode = web.Navigation.GetNodeByUrl(list.DefaultViewUrl);
// No link, so create one.
if (listNode == null)
{
// Create the node.
listNode = new SPNavigationNode(list.Title, list.DefaultViewUrl);
// Add it to Quick Launch.
web.Navigation.AddToQuickLaunch(listNode, SPQuickLaunchHeading.Lists);
}
}
We have used the method above for a while and it tends to work out just fine.
If you can let me know what kind of thing you are trying to accomplish that manipulating SPWeb.Navigation wont let you do, I might be able to be of some more help

how to add a non-selectable item to a List in J2ME

I would like to be able to add a non-selectable element to a list within a j2me screen. At the moment any item that I add to the List can be navigated to on the screen, such that it is selected and is surrounded by a black border.
Is possible to add an element to a List which cannot be selected in this way?
Can this be achieved through some other means or using a different UI object like a Form?
Many thanks for your help.
Quick thoughts. How about to use Form with CustomItem.
Please see this document for CustomItem => http://developers.sun.com/mobility/midp/ttips/customitem/
It's not clear to me, if you use J2MEPolish. If you do, style your item with the icon-inactive css-attribute as described here. So for example:
.inactiveListItem extends listItem {
icon-inactive: true;
border: none;
}

Resources