How to use Delegate with QCalendarWidget? - c++

I need modify the delegate in a QCalenderWidget. I want to change the background-color of cell when the user select a specific day.
I would like getting a simple example.

You could use QWidget::setStyleSheet(const QString & styleSheet) and set selection-background-color value:
auto calendar = new QCalendarWidget(this);
calendar->setStyleSheet("selection-background-color:black");

Related

set List filters in ExtJS grid dynamically from response

I am trying to set(check) List filters of a grid column dynamically
from response.
I am able to set them but when I open the menu of the corresponding
filter and setting some other combination of data to filter
dynamically it is getting selected and later cleared.
Is the code am using below for setting filters is right?Need help.
var gridFilter = currentGrid.columns[i].filter;
gridFilter.setActive(true);
gridFilter.filter.value="SELECTED,REJECTED"; //putting static data for now
gridFilter.filter.setValue(["SELECTED", "REJECTED"]);
Best way to add and Edit filter for ExtJs is FilterBy method:
grid.getStore().filterBy(function(rec, id)) {
return (rec.get("DynamicRecName")=="DynamicFilterRecord");
}
If you want to edit existing then just remove current filters:
grid.getStore().clearFilters()

Sitecore get all parent (ancestor) with little processing (performance)

I'm trying to come up with solution on getting all the ancestors for the context item. One option is to store _path in index and other option is to do similar to one below:
http://www.glass.lu/Blog/GettingAncestors
I'm having no luck with getting the solution work for above (glass mapper) solution.
I got the index solution working but would like to avoid using index just to get the _path (collection of ancestors) as we don't have any other requirements to use index e.g. search etc.
Appreciate if someone could share the snippet for working solution or even better if Glassmapper has already included the above blog solution.
The most efficient way to check if one item is a descendant of another is to simply check that the current item property Paths.LongID starts with the LongID of the parent item:
Item currentItem = Sitecore.Context.Item;
IList<Item> menuItems = GetMenuItems();
foreach (var menuItem in menuItems)
{
bool isActive = currentItem.Paths.LongID.StartsWith(menuItem.Paths.LongID);
// do code
}
This will work since the path GUIDs are unique for each item.
Alternatively, if you want to use Glass models only then you can use the SitecoreInfoType.FullPath attribute:
[SitecoreInfo(SitecoreInfoType.FullPath)]
public virtual string FullPath { get; private set; }
And then from your code you can simply check:
Item currentItem = Sitecore.Context.Item; //or use SitecoreContext() to get a strongly types model
IEnumerable<MenuItem> menuItems = GetMenuItems();
foreach (var menuItem in menuItems)
{
bool isActive = currentItem.Paths.FullPath.StartsWith(menuItem.FullPath);
// do code
}
Just a word of warning, since each menu item now need code to run in order to determine state, this will make your menu component difficult to cache, resulting caching too many variations or caching per page. You would be better to move this logic into Javascript to set the menu state using the current page URL, this will allow your component to be cached once for all pages.

Is there anyway of returning the options of a GoogleChart after the chart has been edited using the ChartEditor class?

I want to store the configuration of multiple GoogleCharts in a database and use them to create a dashboard of charts.
I currently store the options I supply for each chart in the database and have my dashboard working, displaying multiple charts.
I want to use the ChartEditor class to allow a user to amend a chart and then save the changes back to my database, so that the next time the dashboard is created, the changes are persisted.
Hence, when a user clicks on the OK button on the ChartEditor dialog, is there a way of accessing the changes to these options?
After crawling around, inspecting the ChartEditor object....
$.parseJSON(chartEditor.getChartSpecification())['options']
...returns what I'm looking for.
Just to add to Flippsie's answer, you can recreate the saved chart from the json returned from chartEditor.getChartSpecification()
var json = chartEditor.getChartSpecification(); // Or saved JSON value
var spec = JSON.parse(json);
// Get the chart details from the saved spec
var data = new google.visualization.DataTable(spec.dataTable);
var options = spec.options;
var chartType = spec.chartType || "BarChart";
// Instantiate and draw our chart, passing in some options.
window.chart = new google.visualization[chartType](document.getElementById('chart_div'));
chart.draw(data, options);

How to programmatically create/build up a CTabCtrl?

Without using the "Graphic Resources" how can I create and build up a CTabCtrl?
What I have so far creates it, but I don't know the MESSAGE_MAP for it. Also how to create different views for each "tab" as apposed to displaying/hiding controls depending upon what tab was selected?
thx
CTabCtrl *tabMain = new CTabCtrl();
tabMain->Create(WS_CHILD|WS_VISIBLE|TCS_TABS|TCS_SINGLELINE,CRect(700,100,1000,600),this,5);
TC_ITEM ti;
ti.mask = TCIF_TEXT;
ti.pszText = _T("Tab0");
tabMain->InsertItem(0,&ti);
ti.pszText = _T("Tab1");
tabMain->InsertItem(1,&ti);
ti.pszText = _T("Tab2");
tabMain->InsertItem(2,&ti);
The last parameter you pass to the Create function is the Id which you should use in the MESSAGE_MAP .
For eg:
ON_NOTIFY(TCN_SELCHANGE, 5 , OnSelchangeTab)

How to get a reference to the currently edited item when inside a custom field in Sitecore

In Sitecore I have created a custom field (via this recipe: http://sdn.sitecore.net/Articles/API/Creating%20a%20Composite%20Custom%20Field/Adding%20a%20Custom%20Field%20to%20Sitecore%20Client.aspx)
The field is for use in the content editor.
The custom field has a menuitem attached (the little textbutton rendered just above the field)
The custom field work as expected and the menuitem hooks into code in the custom field class as it should. However, the logic I need to implement for the menuitem requires that I get a reference to the item that is currently being edited by the user in the content editor.
However, to my surprise this doesn't work:
Sitecore.Context.Item
This does not give me the item that the user is currently editing, but instead the "content editor" item, which is always the same.
I would think there would simply be a property of some object in the API, but I can't find it.
If you are following this article then you will have defined a property on your control..
public string ItemID { get; set;}
.. this will be populated with the ID for the item you are editing. You should be able resolve the Item object from this ID using something like:
Sitecore.Data.Database.GetDatabase("master").GetItem(ItemID)
.. if you are just looking just for the value of the field you are editing you can use the base.Value field.
The best place to ask this would be on the developer forum, you should get a good response on there.
Though, taking a look through the Sitecore code, it looks like this might be what you want. Try reading it from the ViewState:
public string ItemID
{
get
{
return base.GetViewStateString("ItemID");
}
set
{
Assert.ArgumentNotNullOrEmpty(value, "value");
base.SetViewStateString("ItemID", value);
}
}
Stephen Pope is right, though there are more properties that you can 'automagiacally' retrieve from Sitecore. Some properties, just like ItemID are put on the field via reflection. There's also the ItemVersion and Source that can be useful for your custom controls.
If you're intereseted, take a peek inside the class Sitecore.Shell.Applications.ContentEditor.EditorFormatter, and especially its method SetProperties:
ReflectionUtil.SetProperty(editor, "ItemID", field.ItemField.Item.ID.ToString());
ReflectionUtil.SetProperty(editor, "ItemVersion", field.ItemField.Item.Version.ToString());