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
380  { return qVariantValue<T>(property(name, qVariantFromValue<T>(def))); }
385  void setProperty(const char *name, const QVariant &value);
386  QList<QByteArray> dynamicPropertyNames() const;
387 protected:
388 #ifndef Q_QDOC
389  friend class DataItemPrivate;
390  QSharedDataPointer<DataItemPrivate> d;
391 #endif
392 };
393 
394 
396 {
397 public:
398  ReadOnlyDataItem(const LocalizedString &title, const QStringList &data);
399  ReadOnlyDataItem(const LocalizedString &title, const LocalizedStringList &data);
400  ReadOnlyDataItem(const LocalizedString &title, bool data);
401  ReadOnlyDataItem(const LocalizedString &title, const QDate &data);
402  ReadOnlyDataItem(const LocalizedString &title, const QDateTime &data);
403  ReadOnlyDataItem(const LocalizedString &title, int data);
404  ReadOnlyDataItem(const LocalizedString &title, uint data);
405  ReadOnlyDataItem(const LocalizedString &title, double data);
406  ReadOnlyDataItem(const LocalizedString &title, const QIcon &data);
407  ReadOnlyDataItem(const LocalizedString &title, const QImage &data);
408  ReadOnlyDataItem(const LocalizedString &title, const QPixmap &data);
409  ReadOnlyDataItem(const LocalizedString &title, const QString &data);
410  ReadOnlyDataItem(const LocalizedString &title, const LocalizedString &data);
411 };
412 
414 {
415 public:
416  StringListDataItem(const QString &name, const LocalizedString &title,
417  const QStringList &data = QStringList(),
418  int maxStringsCount = -1);
419  StringListDataItem(const QString &name, const LocalizedString &title,
421  int maxStringsCount = -1);
422 };
423 
425 {
426 public:
427  IntDataItem(const QString &name, const LocalizedString &title, int data,
428  int minValue = 0, int maxValue = 100);
429 };
430 
432 {
433 public:
434  DoubleDataItem(const QString &name, const LocalizedString &title, double data,
435  double minValue = 0, double maxValue = 100);
436 };
437 
439 {
440 public:
441  IconDataItem(const QString &name, const LocalizedString &title,
442  const QIcon &data = QIcon(),
443  const QSize &imageSize = QSize(32, 32),
444  const QList<QIcon> &alternatives = QList<QIcon>());
445 };
446 
448 {
449 public:
450  ImageDataItem(const QString &name, const LocalizedString &title,
451  const QImage &data = QImage(),
452  const QSize &imageSize = QSize(32, 32),
453  const QList<QImage> &alternatives = QList<QImage>());
454 };
455 
457 {
458 public:
459  PixmapDataItem(const QString &name, const LocalizedString &title,
460  const QPixmap &data = QPixmap(),
461  const QSize &imageSize = QSize(128, 128),
462  const QList<QPixmap> &alternatives = QList<QPixmap>());
463 };
464 
466 {
467 public:
468  StringChooserDataItem(const QString &name, const LocalizedString &title,
469  const QStringList &alternatives, const QString &data = QString(),
470  bool editable = false, QValidator *validator = 0);
471  StringChooserDataItem(const QString &name, const LocalizedString &title,
472  const QStringList &alternatives, const QString &data,
473  bool editable, QRegExp validator);
474  StringChooserDataItem(const QString &name, const LocalizedString &title,
475  const LocalizedStringList &alternatives,
476  const LocalizedString &data,
477  bool editable = false, QValidator *validator = 0);
478  StringChooserDataItem(const QString &name, const LocalizedString &title,
479  const LocalizedStringList &alternatives,
480  const LocalizedString &data,
481  bool editable, QRegExp validator);
482 };
483 
485 {
486 public:
487  MultiLineStringDataItem(const QString &name, const LocalizedString &title,
488  const QString &data = QString());
489  MultiLineStringDataItem(const QString &name, const LocalizedString &title,
490  const LocalizedString &data);
491 };
492 
494 {
495 public:
496  StringDataItem(const QString &name, const LocalizedString &title,
497  const QString &data = QString(),
498  QValidator *validator = 0, bool password = false);
499  StringDataItem(const QString &name, const LocalizedString &title,
500  const QString &data, QRegExp validator,
501  bool password = false);
502  StringDataItem(const QString &name, const LocalizedString &title,
503  const LocalizedString &data, QValidator *validator = 0,
504  bool password = false);
505  StringDataItem(const QString &name, const LocalizedString &title,
506  const LocalizedString &data, QRegExp validator,
507  bool password = false);
508 };
509 
510 class LIBQUTIM_EXPORT AbstractDataForm : public QWidget
511 {
512  Q_OBJECT
513 public:
514  enum ButtonRole {
515  InvalidRole = -1,
525 
526  NRoles
527  };
528  Q_DECLARE_FLAGS(ButtonRoles, ButtonRole)
530  NoButton = 0x00000000,
531  Ok = 0x00000400,
532  Save = 0x00000800,
533  SaveAll = 0x00001000,
534  Open = 0x00002000,
535  Yes = 0x00004000,
536  YesToAll = 0x00008000,
537  No = 0x00010000,
538  NoToAll = 0x00020000,
539  Abort = 0x00040000,
540  Retry = 0x00080000,
541  Ignore = 0x00100000,
542  Close = 0x00200000,
543  Cancel = 0x00400000,
544  Discard = 0x00800000,
545  Help = 0x01000000,
546  Apply = 0x02000000,
547  Reset = 0x04000000,
548  RestoreDefaults = 0x08000000
549  };
550  Q_DECLARE_FLAGS(StandardButtons, StandardButton)
551  struct Button
552  {
555  };
556  typedef QList<Button> Buttons;
557 public:
558  virtual DataItem item() const = 0;
565  virtual bool isChanged() const = 0;
573  virtual bool isComplete() const = 0;
577  virtual void clearState() = 0;
584  virtual void setData(const QString &fieldName, const QVariant &data) = 0;
585  static AbstractDataForm *get(const DataItem &item,
586  StandardButtons standartButtons = NoButton,
587  const Buttons &buttons = Buttons());
588 public slots:
589  void accept();
590  void reject();
591 signals:
592  void accepted();
593  void rejected();
594  void helpRequested();
595  void clicked(int buttonIndex);
596  void clicked(qutim_sdk_0_3::AbstractDataForm::StandardButton standartButton);
601  void changed();
608  void completeChanged(bool complete);
609 protected:
610  virtual void virtual_hook(int id, void *data);
611 };
612 
613 class LIBQUTIM_EXPORT DataFormsBackend : public QObject
614 {
615  Q_OBJECT
616 public:
617  virtual AbstractDataForm *get(const DataItem &item,
618  AbstractDataForm::StandardButtons standartButtons = AbstractDataForm::NoButton,
620  static DataFormsBackend *instance();
621 };
622 
623 template<typename T>
624 T DataItem::data(const T &def) const
625 {
626  QVariant d = data();
627  return d.canConvert<T>() ? d.value<T>() : def;
628 }
629 
630 #ifndef Q_QDOC
631 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDataForm::ButtonRoles)
632 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDataForm::StandardButtons)
633 #endif
634 }
635 
636 #ifndef Q_QDOC
638 Q_DECLARE_METATYPE(QList<qutim_sdk_0_3::DataItem>)
639 #endif
640 
641 #endif // DATAFORMS_H
642 

Generated by Doxygen