libqutim  0.3.1.0
dataforms.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 #ifndef DATAFORMS_H
26 #define DATAFORMS_H
27 
28 #include "localizedstring.h"
29 #include <QSharedPointer>
30 #include <QVariant>
31 #include <QFrame>
32 #include <QDateTime>
33 #include <QDate>
34 #include <QPixmap>
35 #include <QImage>
36 #include <QIcon>
37 
38 class QValidator;
39 
40 namespace qutim_sdk_0_3
41 {
42 
43 class DataItemPrivate;
44 
217 {
218 public:
223  DataItem();
227  DataItem(const QString &name, const LocalizedString &title, const QVariant &data);
231  DataItem(const LocalizedString &title, const QVariant &data = QVariant());
239  DataItem(const DataItem &other);
243  ~DataItem();
247  DataItem &operator=(const DataItem &other);
252  QString name() const;
257  void setName(const QString &itemName);
262  LocalizedString title() const;
267  void setTitle(const LocalizedString &itemTitle);
271  QVariant data() const;
276  template<typename T>
277  T data(const T &def = T()) const;
281  void setData(const QVariant &itemData);
285  bool isNull() const;
290  QList<DataItem> subitems() const;
294  void setSubitems(const QList<DataItem> &newSubitems);
298  DataItem subitem(const QString &name, bool recursive = false) const;
299 
300  int removeSubitems(const QString &name, bool recursive = false);
301  bool removeSubitem(const QString &name, bool recursive = false);
302  DataItem takeSubitem(const QString &name, bool recursive = false);
307  void addSubitem(const DataItem &subitem);
311  bool hasSubitems() const;
318  void allowModifySubitems(const DataItem &defaultSubitem, int maxSubitemsCount = -1);
323  bool isAllowedModifySubitems() const;
329  int maxSubitemsCount() const;
334  DataItem defaultSubitem() const;
339  bool isReadOnly() const;
344  void setReadOnly(bool readOnly = true);
353  void setDataChangedHandler(QObject *receiver, const char *method);
357  QObject *dataChangedReceiver() const;
361  const char *dataChangedMethod() const;
366  DataItem &operator<<(const DataItem &subitem);
372  QVariant property(const char *name, const QVariant &def = QVariant()) const;
378  template<typename T>
379  T property(const char *name, const T &def = T()) const;
384  void setProperty(const char *name, const QVariant &value);
385  QList<QByteArray> dynamicPropertyNames() const;
386 protected:
387 #ifndef Q_QDOC
388  friend class DataItemPrivate;
389  QSharedDataPointer<DataItemPrivate> d;
390 #endif
391 };
392 
393 template<typename T>
394 T DataItem::property(const char *name, const T &def) const
395 {
396  QVariant var = property(name, QVariant::fromValue<T>(def));
397  return var.value<T>();
398 }
399 
401 {
402 public:
403  ReadOnlyDataItem(const LocalizedString &title, const QStringList &data);
404  ReadOnlyDataItem(const LocalizedString &title, const LocalizedStringList &data);
405  ReadOnlyDataItem(const LocalizedString &title, bool data);
406  ReadOnlyDataItem(const LocalizedString &title, const QDate &data);
407  ReadOnlyDataItem(const LocalizedString &title, const QDateTime &data);
408  ReadOnlyDataItem(const LocalizedString &title, int data);
409  ReadOnlyDataItem(const LocalizedString &title, uint data);
410  ReadOnlyDataItem(const LocalizedString &title, double data);
411  ReadOnlyDataItem(const LocalizedString &title, const QIcon &data);
412  ReadOnlyDataItem(const LocalizedString &title, const QImage &data);
413  ReadOnlyDataItem(const LocalizedString &title, const QPixmap &data);
414  ReadOnlyDataItem(const LocalizedString &title, const QString &data);
415  ReadOnlyDataItem(const LocalizedString &title, const LocalizedString &data);
416 };
417 
419 {
420 public:
421  StringListDataItem(const QString &name, const LocalizedString &title,
422  const QStringList &data = QStringList(),
423  int maxStringsCount = -1);
424  StringListDataItem(const QString &name, const LocalizedString &title,
426  int maxStringsCount = -1);
427 };
428 
430 {
431 public:
432  IntDataItem(const QString &name, const LocalizedString &title, int data,
433  int minValue = 0, int maxValue = 100);
434 };
435 
437 {
438 public:
439  DoubleDataItem(const QString &name, const LocalizedString &title, double data,
440  double minValue = 0, double maxValue = 100);
441 };
442 
444 {
445 public:
446  IconDataItem(const QString &name, const LocalizedString &title,
447  const QIcon &data = QIcon(),
448  const QSize &imageSize = QSize(32, 32),
449  const QList<QIcon> &alternatives = QList<QIcon>());
450 };
451 
453 {
454 public:
455  ImageDataItem(const QString &name, const LocalizedString &title,
456  const QImage &data = QImage(),
457  const QSize &imageSize = QSize(32, 32),
458  const QList<QImage> &alternatives = QList<QImage>());
459 };
460 
462 {
463 public:
464  PixmapDataItem(const QString &name, const LocalizedString &title,
465  const QPixmap &data = QPixmap(),
466  const QSize &imageSize = QSize(128, 128),
467  const QList<QPixmap> &alternatives = QList<QPixmap>());
468 };
469 
471 {
472 public:
473  StringChooserDataItem(const QString &name, const LocalizedString &title,
474  const QStringList &alternatives, const QString &data = QString(),
475  bool editable = false, QValidator *validator = 0);
476  StringChooserDataItem(const QString &name, const LocalizedString &title,
477  const QStringList &alternatives, const QString &data,
478  bool editable, QRegExp validator);
479  StringChooserDataItem(const QString &name, const LocalizedString &title,
480  const LocalizedStringList &alternatives,
481  const LocalizedString &data,
482  bool editable = false, QValidator *validator = 0);
483  StringChooserDataItem(const QString &name, const LocalizedString &title,
484  const LocalizedStringList &alternatives,
485  const LocalizedString &data,
486  bool editable, QRegExp validator);
487 };
488 
490 {
491 public:
492  MultiLineStringDataItem(const QString &name, const LocalizedString &title,
493  const QString &data = QString());
494  MultiLineStringDataItem(const QString &name, const LocalizedString &title,
495  const LocalizedString &data);
496 };
497 
499 {
500 public:
501  StringDataItem(const QString &name, const LocalizedString &title,
502  const QString &data = QString(),
503  QValidator *validator = 0, bool password = false);
504  StringDataItem(const QString &name, const LocalizedString &title,
505  const QString &data, QRegExp validator,
506  bool password = false);
507  StringDataItem(const QString &name, const LocalizedString &title,
508  const LocalizedString &data, QValidator *validator = 0,
509  bool password = false);
510  StringDataItem(const QString &name, const LocalizedString &title,
511  const LocalizedString &data, QRegExp validator,
512  bool password = false);
513 };
514 
515 class LIBQUTIM_EXPORT AbstractDataForm : public QWidget
516 {
517  Q_OBJECT
518 public:
519  enum ButtonRole {
520  InvalidRole = -1,
530 
531  NRoles
532  };
533  Q_DECLARE_FLAGS(ButtonRoles, ButtonRole)
535  NoButton = 0x00000000,
536  Ok = 0x00000400,
537  Save = 0x00000800,
538  SaveAll = 0x00001000,
539  Open = 0x00002000,
540  Yes = 0x00004000,
541  YesToAll = 0x00008000,
542  No = 0x00010000,
543  NoToAll = 0x00020000,
544  Abort = 0x00040000,
545  Retry = 0x00080000,
546  Ignore = 0x00100000,
547  Close = 0x00200000,
548  Cancel = 0x00400000,
549  Discard = 0x00800000,
550  Help = 0x01000000,
551  Apply = 0x02000000,
552  Reset = 0x04000000,
553  RestoreDefaults = 0x08000000
554  };
555  Q_DECLARE_FLAGS(StandardButtons, StandardButton)
556  struct Button
557  {
560  };
561  typedef QList<Button> Buttons;
562 public:
563  virtual DataItem item() const = 0;
570  virtual bool isChanged() const = 0;
578  virtual bool isComplete() const = 0;
582  virtual void clearState() = 0;
589  virtual void setData(const QString &fieldName, const QVariant &data) = 0;
590  static AbstractDataForm *get(const DataItem &item,
591  StandardButtons standartButtons = NoButton,
592  const Buttons &buttons = Buttons());
593 public slots:
594  void accept();
595  void reject();
596 signals:
597  void accepted();
598  void rejected();
599  void helpRequested();
600  void clicked(int buttonIndex);
601  void clicked(qutim_sdk_0_3::AbstractDataForm::StandardButton standartButton);
606  void changed();
613  void completeChanged(bool complete);
614 protected:
615  virtual void virtual_hook(int id, void *data);
616 };
617 
618 class LIBQUTIM_EXPORT DataFormsBackend : public QObject
619 {
620  Q_OBJECT
621 public:
622  virtual AbstractDataForm *get(const DataItem &item,
623  AbstractDataForm::StandardButtons standartButtons = AbstractDataForm::NoButton,
625  static DataFormsBackend *instance();
626 };
627 
628 template<typename T>
629 T DataItem::data(const T &def) const
630 {
631  QVariant d = data();
632  return d.canConvert<T>() ? d.value<T>() : def;
633 }
634 
635 #ifndef Q_QDOC
636 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDataForm::ButtonRoles)
637 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDataForm::StandardButtons)
638 #endif
639 }
640 
641 #ifndef Q_QDOC
643 Q_DECLARE_METATYPE(QList<qutim_sdk_0_3::DataItem>)
644 #endif
645 
646 #endif // DATAFORMS_H
647 

Generated by Doxygen