/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the Qt Designer of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** ** ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef ABSTRACTFORMBUILDER_H #define ABSTRACTFORMBUILDER_H #include #include #include #include #include #include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE #if 0 // pragma for syncqt, don't remove. #pragma qt_class(QAbstractFormBuilder) #endif class QAction; class QButtonGroup; class QActionGroup; class QComboBox; class QIODevice; class QIcon; class QLayout; class QLayoutItem; class QListWidget; class QObject; class QSpacerItem; class QTreeWidget; class QTableWidget; class QVariant; class QWidget; class QAbstractButton; class QAbstractItemView; #ifdef QFORMINTERNAL_NAMESPACE namespace QFormInternal { #endif class DomAction; class DomActionGroup; class DomButtonGroup; class DomButtonGroups; class DomActionRef; class DomBrush; class DomColorGroup; class DomConnections; class DomCustomWidgets; class DomLayout; class DomLayoutItem; class DomProperty; class DomResources; class DomSpacer; class DomString; class DomTabStops; class DomUI; class DomWidget; class DomResourcePixmap; class QResourceBuilder; class QTextBuilder; #ifndef QT_FORMBUILDER_NO_SCRIPT class QFormScriptRunner; #endif class QDESIGNER_UILIB_EXPORT QAbstractFormBuilder { public: QAbstractFormBuilder(); virtual ~QAbstractFormBuilder(); QDir workingDirectory() const; void setWorkingDirectory(const QDir &directory); virtual QWidget *load(QIODevice *dev, QWidget *parentWidget=0); virtual void save(QIODevice *dev, QWidget *widget); void setScriptingEnabled(bool enabled); bool isScriptingEnabled() const; protected: // // load // virtual void loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget); virtual QWidget *create(DomUI *ui, QWidget *parentWidget); virtual QWidget *create(DomWidget *ui_widget, QWidget *parentWidget); virtual QLayout *create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget); virtual QLayoutItem *create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget); virtual QAction *create(DomAction *ui_action, QObject *parent); virtual QActionGroup *create(DomActionGroup *ui_action_group, QObject *parent); virtual void addMenuAction(QAction *action); virtual void applyProperties(QObject *o, const QList &properties); bool applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value); virtual void applyTabStops(QWidget *widget, DomTabStops *tabStops); virtual QWidget *createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name); virtual QLayout *createLayout(const QString &layoutName, QObject *parent, const QString &name); virtual QAction *createAction(QObject *parent, const QString &name); virtual QActionGroup *createActionGroup(QObject *parent, const QString &name); virtual void createCustomWidgets(DomCustomWidgets *) {} virtual void createConnections(DomConnections *, QWidget *) {} virtual void createResources(DomResources*) {} virtual bool addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout); virtual bool addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget); // // save // virtual void saveExtraInfo(QWidget *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget); virtual void saveDom(DomUI *ui, QWidget *widget); virtual DomActionRef *createActionRefDom(QAction *action); virtual DomWidget *createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive = true); virtual DomLayout *createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget); virtual DomLayoutItem *createDom(QLayoutItem *item, DomLayout *ui_parentLayout, DomWidget *ui_parentWidget); virtual DomSpacer *createDom(QSpacerItem *spacer, DomLayout *ui_parentLayout, DomWidget *ui_parentWidget); virtual DomAction *createDom(QAction *action); virtual DomActionGroup *createDom(QActionGroup *actionGroup); DomButtonGroup *createDom(QButtonGroup *buttonGroup); virtual DomConnections *saveConnections(); virtual DomCustomWidgets *saveCustomWidgets(); virtual DomTabStops *saveTabStops(); virtual DomResources *saveResources(); DomButtonGroups *saveButtonGroups(const QWidget *mainContainer); virtual QList computeProperties(QObject *obj); virtual bool checkProperty(QObject *obj, const QString &prop) const; virtual DomProperty *createProperty(QObject *object, const QString &propertyName, const QVariant &value); virtual void layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing); virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath); virtual QString iconToFilePath(const QIcon &pm) const; virtual QString iconToQrcPath(const QIcon &pm) const; virtual QPixmap nameToPixmap(const QString &filePath, const QString &qrcPath); virtual QString pixmapToFilePath(const QPixmap &pm) const; virtual QString pixmapToQrcPath(const QPixmap &pm) const; void loadListWidgetExtraInfo(DomWidget *ui_widget, QListWidget *listWidget, QWidget *parentWidget); void loadTreeWidgetExtraInfo(DomWidget *ui_widget, QTreeWidget *treeWidget, QWidget *parentWidget); void loadTableWidgetExtraInfo(DomWidget *ui_widget, QTableWidget *tableWidget, QWidget *parentWidget); void loadComboBoxExtraInfo(DomWidget *ui_widget, QComboBox *comboBox, QWidget *parentWidget); void loadButtonExtraInfo(const DomWidget *ui_widget, QAbstractButton *button, QWidget *parentWidget); void loadItemViewExtraInfo(DomWidget *ui_widget, QAbstractItemView *itemView, QWidget *parentWidget); void saveListWidgetExtraInfo(QListWidget *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget); void saveTreeWidgetExtraInfo(QTreeWidget *treeWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget); void saveTableWidgetExtraInfo(QTableWidget *tablWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget); void saveComboBoxExtraInfo(QComboBox *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget); void saveButtonExtraInfo(const QAbstractButton *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget); void saveItemViewExtraInfo(const QAbstractItemView *itemView, DomWidget *ui_widget, DomWidget *ui_parentWidget); void setResourceBuilder(QResourceBuilder *builder); QResourceBuilder *resourceBuilder() const; DomProperty *saveResource(const QVariant &v) const; void setTextBuilder(QTextBuilder *builder); QTextBuilder *textBuilder() const; DomProperty *saveText(const QString &attributeName, const QVariant &v) const; // // utils // QVariant toVariant(const QMetaObject *meta, DomProperty *property); static QString toString(const DomString *str); typedef QHash DomPropertyHash; static DomPropertyHash propertyMap(const QList &properties); void setupColorGroup(QPalette &palette, QPalette::ColorGroup colorGroup, DomColorGroup *group); DomColorGroup *saveColorGroup(const QPalette &palette); QBrush setupBrush(DomBrush *brush); DomBrush *saveBrush(const QBrush &brush); void reset(); void initialize(const DomUI *ui); #ifndef QT_FORMBUILDER_NO_SCRIPT QFormScriptRunner *formScriptRunner() const; #endif // // utils // static QMetaEnum toolBarAreaMetaEnum(); // // Icon/pixmap stuff // // A Pair of icon path/qrc path. typedef QPair IconPaths; IconPaths iconPaths(const QIcon &) const; IconPaths pixmapPaths(const QPixmap &) const; void setIconProperty(DomProperty &, const IconPaths &) const; void setPixmapProperty(DomProperty &, const IconPaths &) const; DomProperty* iconToDomProperty(const QIcon &) const; static const DomResourcePixmap *domPixmap(const DomProperty* p); QIcon domPropertyToIcon(const DomResourcePixmap *); QIcon domPropertyToIcon(const DomProperty* p); QPixmap domPropertyToPixmap(const DomResourcePixmap* p); QPixmap domPropertyToPixmap(const DomProperty* p); QHash m_laidout; QHash m_actions; QHash m_actionGroups; int m_defaultMargin; int m_defaultSpacing; QDir m_workingDirectory; private: // // utils // static Qt::ToolBarArea toolbarAreaFromDOMAttributes(const DomPropertyHash &attributeMap); QAbstractFormBuilder(const QAbstractFormBuilder &other); void operator = (const QAbstractFormBuilder &other); friend QDESIGNER_UILIB_EXPORT DomProperty *variantToDomProperty(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const QString &propertyName, const QVariant &value); friend QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(QAbstractFormBuilder *abstractFormBuilder,const QMetaObject *meta, const DomProperty *property); }; #ifdef QFORMINTERNAL_NAMESPACE } #endif QT_END_NAMESPACE QT_END_HEADER #endif // ABSTRACTFORMBUILDER_H 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2015 Stephen Kelly <steveire@gmail.com>

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#ifndef cmAlgorithms_h
#define cmAlgorithms_h

#include "cmStandardIncludes.h"

inline bool cmHasLiteralPrefixImpl(const std::string &str1,
                                 const char *str2,
                                 size_t N)
{
  return strncmp(str1.c_str(), str2, N) == 0;
}

inline bool cmHasLiteralPrefixImpl(const char* str1,
                                 const char *str2,
                                 size_t N)
{
  return strncmp(str1, str2, N) == 0;
}

inline bool cmHasLiteralSuffixImpl(const std::string &str1,
                                   const char *str2,
                                   size_t N)
{
  size_t len = str1.size();
  return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
}

inline bool cmHasLiteralSuffixImpl(const char* str1,
                                   const char* str2,
                                   size_t N)
{
  size_t len = strlen(str1);
  return len >= N && strcmp(str1 + len - N, str2) == 0;
}

template<typename T, size_t N>
const T* cmArrayBegin(const T (&a)[N]) { return a; }
template<typename T, size_t N>
const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
template<typename T, size_t N>
size_t cmArraySize(const T (&)[N]) { return N; }

template<typename T, size_t N>
bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
{
  return cmHasLiteralPrefixImpl(str1, str2, N - 1);
}

template<typename T, size_t N>
bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
{
  return cmHasLiteralSuffixImpl(str1, str2, N - 1);
}

struct cmStrCmp {
  cmStrCmp(const char *test) : m_test(test) {}
  cmStrCmp(const std::string &test) : m_test(test) {}

  bool operator()(const std::string& input) const
  {
    return m_test == input;
  }

  bool operator()(const char * input) const
  {
    return strcmp(input, m_test.c_str()) == 0;
  }

private:
  const std::string m_test;
};

template<typename FwdIt>
FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last)
{
  const typename std::iterator_traits<FwdIt>::difference_type dist =
      std::distance(middle, last);
  std::rotate(first, middle, last);
  std::advance(first, dist);
  return first;
}

namespace ContainerAlgorithms {

template<typename T>
struct cmIsPair
{
  enum { value = false };
};

template<typename K, typename V>
struct cmIsPair<std::pair<K, V> >
{
  enum { value = true };
};

template<typename Range,
    bool valueTypeIsPair = cmIsPair<typename Range::value_type>::value>
struct DefaultDeleter
{
  void operator()(typename Range::value_type value) const {
    delete value;
  }
};

template<typename Range>
struct DefaultDeleter<Range, /* valueTypeIsPair = */ true>
{
  void operator()(typename Range::value_type value) const {
    delete value.second;
  }
};

template<typename const_iterator_>
struct Range
{
  typedef const_iterator_ const_iterator;
  typedef typename std::iterator_traits<const_iterator>::value_type value_type;
  typedef typename std::iterator_traits<const_iterator>::difference_type
    difference_type;
  Range(const_iterator begin_, const_iterator end_)
    : Begin(begin_), End(end_) {}
  const_iterator begin() const { return Begin; }
  const_iterator end() const { return End; }
  bool empty() const { return std::distance(Begin, End) == 0; }
  difference_type size() const { return std::distance(Begin, End); }
  Range& advance(cmIML_INT_intptr_t amount)
  {
    std::advance(Begin, amount);
    return *this;
  }

  Range& retreat(cmIML_INT_intptr_t amount)
  {
    std::advance(End, -amount);
    return *this;
  }
private:
  const_iterator Begin;
  const_iterator End;
};

template<typename FwdIt>
FwdIt RemoveN(FwdIt i1, FwdIt i2, size_t n)
{
  FwdIt m = i1;
  std::advance(m, n);
  return cmRotate(i1, m, i2);
}

template<typename Range>
struct BinarySearcher
{
  typedef typename Range::value_type argument_type;
  BinarySearcher(Range const& r)
    : m_range(r)
  {
  }

  bool operator()(argument_type const& item) const
  {
    return std::binary_search(m_range.begin(), m_range.end(), item);
  }
private:
  Range const& m_range;
};

}

template<typename Iter1, typename Iter2>
ContainerAlgorithms::Range<Iter1> cmRange(Iter1 begin, Iter2 end)
{
  return ContainerAlgorithms::Range<Iter1>(begin, end);
}

template<typename Range>
ContainerAlgorithms::Range<typename Range::const_iterator>
cmRange(Range const& range)
{
  return ContainerAlgorithms::Range<typename Range::const_iterator>(
      range.begin(), range.end());
}

template<typename Range>
void cmDeleteAll(Range const& r)
{
  std::for_each(r.begin(), r.end(),
                ContainerAlgorithms::DefaultDeleter<Range>());
}

template<typename Range>
std::string cmJoin(Range const& r, const char* delimiter)
{
  if (r.empty())
    {
    return std::string();
    }
  std::ostringstream os;
  typedef typename Range::value_type ValueType;
  typedef typename Range::const_iterator InputIt;
  const InputIt first = r.begin();
  InputIt last = r.end();
  --last;
  std::copy(first, last,
      std::ostream_iterator<ValueType>(os, delimiter));

  os << *last;

  return os.str();
}

template<typename Range>
std::string cmJoin(Range const& r, std::string delimiter)
{
  return cmJoin(r, delimiter.c_str());
};

template<typename Range>
typename Range::const_iterator cmRemoveN(Range& r, size_t n)
{
  return ContainerAlgorithms::RemoveN(r.begin(), r.end(), n);
}

template<typename Range, typename InputRange>
typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
{
  typename InputRange::const_iterator remIt = rem.begin();
  typename InputRange::const_iterator remEnd = rem.end();
  const typename Range::iterator rangeEnd = r.end();
  if (remIt == remEnd)
    {
    return rangeEnd;
    }

  typename Range::iterator writer = r.begin();
  std::advance(writer, *remIt);
  typename Range::iterator pivot = writer;
  typename InputRange::value_type prevRem = *remIt;
  ++remIt;
  size_t count = 1;
  for ( ; writer != rangeEnd && remIt != remEnd; ++count, ++remIt)
    {
    std::advance(pivot, *remIt - prevRem);
    prevRem = *remIt;
    writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
    }
  return ContainerAlgorithms::RemoveN(writer, rangeEnd, count);
}

template<typename Range, typename MatchRange>
typename Range::const_iterator cmRemoveMatching(Range &r, MatchRange const& m)
{
  return std::remove_if(r.begin(), r.end(),
                        ContainerAlgorithms::BinarySearcher<MatchRange>(m));
}

template<typename Range>
typename Range::const_iterator cmRemoveDuplicates(Range& r)
{
  typedef std::vector<typename Range::value_type> UniqueVector;
  UniqueVector unique;
  unique.reserve(r.size());
  std::vector<size_t> indices;
  size_t count = 0;
  const typename Range::const_iterator end = r.end();
  for(typename Range::const_iterator it = r.begin();
      it != end; ++it, ++count)
    {
    const typename UniqueVector::iterator low =
        std::lower_bound(unique.begin(), unique.end(), *it);
    if (low == unique.end() || *low != *it)
      {
      unique.insert(low, *it);
      }
    else
      {
      indices.push_back(count);
      }
    }
  if (indices.empty())
    {
    return end;
    }
  return cmRemoveIndices(r, indices);
}

template<typename Range>
std::string cmWrap(std::string prefix, Range const& r, std::string suffix,
                   std::string sep)
{
  if (r.empty())
    {
    return std::string();
    }
  return prefix + cmJoin(r, (suffix + sep + prefix).c_str()) + suffix;
}

template<typename Range>
std::string cmWrap(char prefix, Range const& r, char suffix, std::string sep)
{
  return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep);
}

template<typename Range, typename T>
typename Range::const_iterator cmFindNot(Range const& r, T const& t)
{
  return std::find_if(r.begin(), r.end(),
                      std::bind1st(std::not_equal_to<T>(), t));
}

template<typename Range>
ContainerAlgorithms::Range<typename Range::const_reverse_iterator>
cmReverseRange(Range const& range)
{
  return ContainerAlgorithms::Range<typename Range::const_reverse_iterator>(
      range.rbegin(), range.rend());
}

#endif