I am working with Qt and came across class hierarchies where a base class (sometimes an abstract class) contains Q_PROPERTY macros; will a derived class inherit each Q_PROPERTY from its base class?
Yes, it will. You can easily check this in your debugger: just set a breakpoint after the view / scene is there and inspeckt one of your QObject-instances. You can access the meta-data and the private data for your object and from your base class.
Related
How do you set a custom class on a UI component in Interface Builder, so say I have a class in my project that extends UITableView how do I associate a component in Interface Builder to use that custom class? I type the class name into the custom class placeholder but it replaces that with UITableView...
Any Ideas?
Thanks
Make sure you have this mode active (the right hand side pane), your view selected and the third pane selected like this:
http://tirania.org/s/f6111a1a.png
Then just set the name of the class there. When you save the file and switch back to MonoDevelop, it will automatically stub the class for you if you are using Storyboards.
In order to make the class usable from Interface Builder (and Objective-C), you need to register it using an explicit name, for example
[Register ("MyTableView")]
public class MyTableView : UITableView
{
//...
}
Then MonoDevelop will be able to synchronize the class out to Xcode and it will be visible in Interface Builder.
Classes in project and xib/storyboard templates are already registered in this way, though the attribute may be in the partial designer class.
I am having trouble wrapping my head around the spark skin class in relation to it's host component. Basically, from what I've seen with most every skin that comes in the Flex 4 framework they don't directly expose the properties that are dynamically being set in the host component. Instead, they define states that get exposed to the skin class to define when a component should look different. This is all fine and dandy when you have a very simple component with a standard set of states, but when you have twenty different properties (hypothetically) to set in your host component that should change how the skin looks it could get very complicated very fast.
The way that I've seen that they have used to get around this is by overriding the commitproperties and invalidate functions in the skin class, grabbing the values for the properties they want from there, and then setting them to a locally instantiated variable inside the skin class. This is fine, but I feel like that is just a patch workaround to it which makes things a lot more complicated than it needs to be.
HERE'S MY QUESTION:
Is there any way to directly expose a bindable property from the host component class so when you define your skin class it is directly ready to be read from? Let's say you have custom button with a boolean property of 'selected'. In the skin class, you want to add in a get and set function for the property 'selected' so you can perform some action upon your skin whenever it's set. How do you tell the skin class that this is an available property for you to work with from the host component?
This question exists at a very theoretical level. I'm not clear what you're trying to accomplish, nor what sort of properties you're setting on your component class. I suspect, there is an architecture problem if you have 20 properties and each one needs to correlate to a different skin states somehow.
However, I can try to answer your specific questions.
Is there any way to directly expose a bindable property from the
host component class so when you define your skin class it is directly
ready to be read from?
When building Flex MobileSkins, they recommend creating a property named hostComponent which gives the skin class a reference to the component class. MXML skins already have a similar property. If you're using a custom skin, this property is created automatically using the HostComponent metadata. Therefore from the skin class you can access properties on the component class using the hostComponent property.
Let's say you have custom button with a boolean property of
'selected'. In the skin class, you want to add in a get and set
function for the property 'selected' so you can perform some action
upon your skin whenever it's set.
I'm not envisioning the situation where you would want to do this. Generally you would not define any properties on the skin class which you intend to explicitly change on the instance of the skin class.
You could dispatch an event from the component class when the property changes. [This is very common]. Then listen for that event in the skin class using the hostComponent property and change things there.
There is also a way to access the skin class instance from within the component class. So you could change properties directly on the skin class using the skin property.
I wouldn't follow either approach without thinking it through. Ideally the component class and skin class should be encapsulated from each other; and each approach would provide dependencies.
When you affect a skin to a component, you can use metatags to store a reference to the skin part you actually use :
[SkinPart(required="false")]
public var resizeHandle:UIComponent;
Then, when overriding the partAdded and partRemoved methods, you will be able to set or unset whatever you want in these skin parts, from the basic properties to event listeners.
override protected function partAdded( partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (instance == resizeHandle) {
resizeHandle.addEventListener(MouseEvent.MOUSE_DOWN, resizeHandle_mouseDownHandler);
}
}
override protected function partRemoved(partName:String, instance:Object):void
{
if (instance == resizeHandle) {
resizeHandle.removeEventListener(MouseEvent.MOUSE_DOWN, esizeHandle_mouseDownHandler);
}
super.partRemoved(partName, instance);
}
Furthermore, since you have stored a reference to your skin parts, you can still access it whenever you want in your host component and update it. Am I clear ? :-)
I want to extend or copy the PopUpManager class to add the ability to keep track of the number of windows.
I just want to add a simple windowCount++ when a window is added and windoCount-- when it's removed.
the problem is PopUpManager is a Singleton class... I wasn't able to make it work properly by extending it. And now I have tried to copy the code from the PopUpManager.as file and just add my variable to the end of its functions. It doesn't seem to be working though since it says my properties are undefined even though they are declared above the constructor.
I am thinking I would have to make a copy of the PopUpManagerImpl.as since that's wehre it seems much of the business resides (PopUpManagerImpl extends EventDispatcher implements IPopUpManager) would that allow me to have access to the variable? and should I ignore the manager and just put it in the implementation class?
here is a link about Using the Flex Singleton register, which helped me out when finding myself in the same situation.
I hope you can inspire from that too.
You likely didn't declare yours properties as static. The PopUpManager uses all static methods - this is why working with it you use syntax like:
PopUpManager.createPopUp(...
instead of
var popUpManager:PopUpManager = new PopUpManager();
popUpManager.createPopUp(...
This means that any variables declared in the PopUpManager need to also be static so as to be accessible at the class level.
public static var windowCount:int
I want to inherit more than one class is there any method?
For instance in login.aspx page:
<%# page language="c#" codefile="nishant.aspx.cs" autowireup="true" inherit="nishant"%>
now code behind file
nishant.aspx.cs:
class nishant
{
//code...
}
class bill
{
//code.....
}
Now, I want to inherit bill class then how I will ?
.NET does not support multiple inheritance, this includes asp.net, so no, this is not possible.
You can have your nishant class inherit from the bill class or the other way around, if you want to share functionality. You page can then inherit from the inheriting class and access the functionality of both.
Another option is to inherit from one class and implement an interface (or several interfaces), but the fact that you can implement more than one interface is not the same as multiple inheritance.
There are other things that can be done, depending on what exactly you are trying to achieve (I am primarily thinking about composition versus inheritance).
Multiple inheritance is not allowed. The only way is:
public class Bill : Page
{ }
public class Nishant : Bill
{ }
But rather you should think about your design. Such approach is usually not needed.
No. By nature, .Net allows only single inheritance. At best you could implement an interface, but you will still have to have the code in your nishant class or extract the functionality into your bill class and make function calls.
Although in the case you mention, this is not actually multiple inheritance. Your nishant class must be of type System.Web.UI.Page. So if you create a library with a "bill class", you can then inherit it.
public class bill : System.Web.UI.Page
{
// Your custom code
}
///
public class nishant : bill
{
}
.NET does not support multiple inheritance (one class that inherit from two or more classes).
However you can have as many parent class as you want. Have a look at the decorator pattern.
Or use interfaces, you can have more than one.
In short: implement interfaces and use extension methods
Implementing interfaces might be the way to go, really depends on the functionality you want to inherit.
You can read about inheritance and interfaces here: http://msdn.microsoft.com/en-us/library/ms973861.aspx
When you implement interfaces, but don't want to duplicate the same code into every class that implements a certain interface, you can also write extension methods for the interfaces. Read more about extension methods here: http://msdn.microsoft.com/en-us/library/bb384936.aspx
I have defined a UI (let's call it myUI) using the Qt designer, and using it in my applications. I need to access all the sub-widgets (QToolButtons) in myUI. I want to get all the subwidgets as a QObjectList.
Is there any way to do this?
The QObject::children() doesn't work here because the Qt UI Compiler, when converting the .ui file to a C++ class, doesn't define the ui_myUI class as a subclass of any QObject derived class. Is there any way to force it to do this, and then use the children() function?
Thanks.
Call children() on the top level widget instance.
Assuming your top level widget is called 'tlWidget':
myUI->tlWidget->children()
Usually what happens is that you either inherit from the UI class or you have it as a member and invoke it's setupUi method, sending this as the parameter. The default in Qt Creator/Designer is to have it as a member, named ui.
You can use this member to access any widgets defined in your form.
You might find this interesting:
Designer: Using a .ui file in your application
How do you use your UI ?
(a) something like:
class MyWidget: public QWidget, protected myUI
{
//...
};
(b) or rather something like:
class MyWidget: public QWidget
{
protected:
myUI ui;
};
The Solution is similar for both cases, assumed that you call setupUi(this) or ui.setupUi(this) in the constructor of MyWidget
setupUi(QWidget* p) registers every widget of the UI as children of QWidget p,
so you can easily access them by calling the children() function of p:
this->children(); //"this" refers to an object of MyWidget