Wexus2 0.20
wexus2.src/wexus/Widgets.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_WIDGETS_H__
00009 #define __INCLUDED_WEXUS_WIDGETS_H__
00010 
00011 #include <wexus/HTMLString.h>
00012 #include <wexus/MemberFunction.h>
00013 
00014 #include <QVariant>
00015 
00016 namespace wexus
00017 {
00018   class IDAble;//fwd
00019 
00020   /**
00021    * Comptes the a url to this location.
00022    *
00023    * @author Aleksander Demko
00024    */
00025   QString pathTo(void);
00026 
00027   // internal function for linkTo
00028   // throws on errors
00029   // returns a raw url
00030   QString memberFunctionToUrl(const QString controllertype, const MemberFunction &mfn, const QVariant *_params, wexus::IDAble *idRec, wexus::IDAble *pidRec);
00031 
00032   /**
00033    * pathTo returns a rawurl (suitable for linkTo ro redirectTo)
00034    * for the given member function (which must be a registered action
00035    * of a regisitered controller.
00036    * 
00037    * _params are optional params, while the ActiveRecords maybe be used
00038    * to provide id and pid.
00039    *
00040    * @author Aleksander Demko
00041    */ 
00042 
00043   template <class CONTROLLER>
00044     QString pathTo(void (CONTROLLER::*mfn)(void)) {
00045       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), 0, 0, 0);
00046     }
00047   template <class CONTROLLER>
00048     QString pathTo(void (CONTROLLER::*mfn)(void), const QVariant &_params) {
00049       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), &_params, 0, 0);
00050     }
00051   template <class CONTROLLER>
00052     QString pathTo(void (CONTROLLER::*mfn)(void), IDAble &idRec) {
00053       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), 0, &idRec, 0);
00054     }
00055   template <class CONTROLLER>
00056     QString pathTo(void (CONTROLLER::*mfn)(void), IDAble &idRec, const QVariant &_params) {
00057       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), &_params, &idRec, 0);
00058     }
00059 
00060   template <class CONTROLLER>
00061     QString pathTo(IDAble &pidRec, void (CONTROLLER::*mfn)(void)) {
00062       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), 0, 0, &pidRec);
00063     }
00064   template <class CONTROLLER>
00065     QString pathTo(IDAble &pidRec, void (CONTROLLER::*mfn)(void), const QVariant &_params) {
00066       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), &_params, 0, &pidRec);
00067     }
00068   template <class CONTROLLER>
00069     QString pathTo(IDAble &pidRec, void (CONTROLLER::*mfn)(void), IDAble &idRec) {
00070       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), 0, &idRec, &pidRec);
00071     }
00072   template <class CONTROLLER>
00073     QString pathTo(IDAble &pidRec, void (CONTROLLER::*mfn)(void), IDAble &idRec, const QVariant &_params) {
00074       return memberFunctionToUrl(typeToString<CONTROLLER>(), MemberFunction(mfn), &_params, &idRec, &pidRec);
00075     }
00076 
00077 
00078   /**
00079    * Returns the HTML code for a link to rawurl with the given
00080    * description.
00081    *
00082    * @author Aleksander Demko
00083    */ 
00084   wexus::HTMLString linkTo(const QString &desc, const QString &rawurl);
00085 
00086   /**
00087    * Returns the HTML code for a link to rawurl with the given
00088    * description.
00089    *
00090    * HTMLString description version.
00091    *
00092    * @author Aleksander Demko
00093    */ 
00094   wexus::HTMLString linkTo(const HTMLString &desc, const QString &rawurl);
00095 
00096   /**
00097    * Redirectst the user to the given url.
00098    * This must be called before any output, etc.
00099    *
00100    * An empty string (the default) redirects to self. This is a bonus
00101    * feature to this function that is not in HTTPReply::redirectTo().
00102    *
00103    * @author Aleksander Demko
00104    */ 
00105   void redirectTo(const QString &rawurl = QString());
00106 
00107   /**
00108    * Renders any errors.
00109    * Returns true if there are any errors.
00110    *
00111    * @author Aleksander Demko
00112    */ 
00113   void renderErrors(void);
00114 
00115   /**
00116    * Renders flash["notice"]
00117    *
00118    * @author Aleksander Demko
00119    */ 
00120   void renderNotice(void);
00121 }
00122 
00123 #endif
00124 
 All Classes Namespaces Functions Variables Enumerations Enumerator