Exemple #1
0
StringData* StringData::reserve(size_t cap) {
  assert(!isImmutable() && !hasMultipleRefs());
  assert(isFlat());

  if (cap <= capacity()) return this;

  cap = std::min(cap + cap / 4, size_t(MaxSize) + 1);

  auto const allocRet = allocFlatForLen(cap);
  auto const sd       = allocRet.first;
  auto const cc       = allocRet.second;
  auto const data     = reinterpret_cast<char*>(sd + 1);

  sd->m_data          = data;
  sd->m_hdr.init(cc, HeaderKind::String, 1);
  // request-allocated StringData are always aligned at 16 bytes, thus it is
  // safe to copy in 16-byte groups. This copies m_lenAndHash (8 bytes), the
  // characters (m_len bytes), add the trailing zero (1 byte).
  memcpy16_inline(&sd->m_lenAndHash, &m_lenAndHash,
                  (m_len + 8 + 1 + 15) & ~0xF);
  assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) + 8 ==
          reinterpret_cast<uintptr_t>(m_data));
  assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) % 16 == 0);

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #2
0
StringData* StringData::reserve(size_t cap) {
    assert(!isImmutable() && !hasMultipleRefs());
    assert(isFlat());

    if (cap <= capacity()) return this;

    cap = std::min(cap + cap / 4, size_t(MaxSize));
    auto const sd = allocFlatForLenSmall(cap);

    // Request-allocated StringData are always aligned at 16 bytes, thus it is
    // safe to copy in 16-byte groups.
#ifdef NO_M_DATA
    // layout: [m_lenAndHash][header][...data]
    sd->m_lenAndHash = m_lenAndHash;
    // This copies the characters (m_len bytes), and the trailing zero (1 byte)
    memcpy16_inline(sd+1, this+1, (m_len + 1 + 15) & ~0xF);
    assertx(reinterpret_cast<uintptr_t>(this+1) % 16 == 0);
#else
    // layout: [m_data][header][m_lenAndHash][...data]
    // This copies m_lenAndHash (8 bytes), the characters (m_len bytes),
    // and the trailing zero (1 byte).
    memcpy16_inline(&sd->m_lenAndHash, &m_lenAndHash,
                    (m_len + 8 + 1 + 15) & ~0xF);
    assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) + 8 ==
            reinterpret_cast<uintptr_t>(m_data));
    assertx(reinterpret_cast<uintptr_t>(&m_lenAndHash) % 16 == 0);
#endif

    assert(sd->hasExactlyOneRef());
    assert(sd->isFlat());
    assert(sd->checkSane());
    return sd;
}
QStyleOptionButton OrientationButton::getStyleOption() const
{
    QStyleOptionButton opt;
    opt.initFrom(this);
    if (orientation_ == Qt::Vertical)
    {
        QSize size = opt.rect.size();
        size.transpose();
        opt.rect.setSize(size);
    }
    opt.features = QStyleOptionButton::None;
    if (isFlat())
        opt.features |= QStyleOptionButton::Flat;
    if (menu())
        opt.features |= QStyleOptionButton::HasMenu;
    if (autoDefault() || isDefault())
        opt.features |= QStyleOptionButton::AutoDefaultButton;
    if (isDefault())
        opt.features |= QStyleOptionButton::DefaultButton;
    if (isDown() || (menu() && menu()->isVisible()))
        opt.state |= QStyle::State_Sunken;
    if (isChecked())
        opt.state |= QStyle::State_On;
    if (!isFlat() && !isDown())
        opt.state |= QStyle::State_Raised;
    opt.text = text();
    opt.icon = icon();
    opt.iconSize = iconSize();
    return opt;
}
Exemple #4
0
void StringData::release() noexcept {
  assert(checkSane());
  if (auto const sizeClass = m_hdr.smallSizeClass) {
    assert(isFlat());
    MM().freeSmallIndex(this, sizeClass,
                        MemoryManager::smallIndex2Size(sizeClass));
  } else {
    // We know that the string is request local.  A `smallSizeClass' of 0 in
    // its header indicates that the StringData is either not flat, or too big
    // to fit in a small size class.
    if (!isFlat()) return releaseDataSlowPath();
    auto const size = capacity() + kCapOverhead;
    assertx(size > kMaxSmallSize);
    MM().freeBigSize(this, size);
  }
}
Exemple #5
0
/*! \internal */
QModelIndex KDPropertyModel::indexOf( KDPropertyInterface* property, int column ) const
{
  //qDebug() << "indexOf( " << property << ", " << column <<" )";

    if( isFlat() && property->isStandalone() ) {
    bool found = false;
    int c = d->dfsIndex( d->rootproperty, property, &found );
    if( found ) {
      Q_ASSERT(c>=0);
      //if( c < 0 ) return QModelIndex();
      return createIndex( c, column, property );
    } else {
      return QModelIndex();
    }
  }
  if( property == d->rootproperty)
    return createIndex(0, column, d->rootproperty);

  KDPropertyInterface *parent = d->parentOf(property);
  if( !parent || !parent->isContainer() )
    return QModelIndex();

  int row = static_cast<KDPropertyGroupInterface*>(parent)->indexOf(property);
  Q_ASSERT(row>=0);
  return createIndex(row, column, property);
}
Exemple #6
0
StringData* StringData::Make(const APCString* shared) {
  // No need to check if len > MaxSize, because if it were we'd never
  // have made the StringData in the APCVariant without throwing.
  assert(size_t(shared->getStringData()->size()) <= size_t(MaxSize));

  auto const data = shared->getStringData();
  auto const len = data->size();
  if (UNLIKELY(len > SmallStringReserve)) {
    return MakeAPCSlowPath(shared);
  }

  // small-string path: make a flat copy.
  static_assert(SmallStringReserve + kCapOverhead <= CapCode::Threshold, "");
  static_assert(SmallStringReserve + kCapOverhead == 64, "");
  auto const sd = allocFlatSmallImpl(SmallStringReserve);
  sd->m_lenAndHash = data->m_lenAndHash;

  auto const psrc = data->data();
  auto const pdst = reinterpret_cast<char*>(sd + 1);
  auto const mcret = memcpy(pdst, psrc, len + 1); // also copy the tailing 0
  auto const ret = reinterpret_cast<StringData*>(mcret) - 1;
  // Recalculating ret from mcret avoids a spill.

  assert(ret == sd);
  assert(ret->m_len == len);
  assert(ret->hasExactlyOneRef());
  assert(ret->m_hash == data->m_hash);
  assert(ret->isFlat());
  assert(ret->checkSane());
  return ret;
}
Exemple #7
0
QStyleOptionButton TCircleButton::styleOption() const
{
    QStyleOptionButton opt;
    opt.init(this);

    if (isEnabled())
        opt.state |= QStyle::State_Enabled;

    if (hasFocus())
        opt.state |= QStyle::State_HasFocus;

    if (isDown())
        opt.state |= QStyle::State_Sunken;

    if (! isFlat() && ! isDown())
        opt.state |= QStyle::State_Raised;

    opt.features = isDefault() ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None;
    opt.text = text();
    opt.icon = icon();
    opt.iconSize = QSize(m_diameter,m_diameter);

    QRect r = rect();

    opt.rect = QRect(r.x(),r.y(), m_diameter, m_diameter);
    
    return opt;
}
Exemple #8
0
 IteratorVisible& operator--()
 {
     Iterator& it = *this;
     it = isFlat() ? m_pRootTree->getPrevLeaf( it ) :
                     m_pRootTree->getPrevVisibleItem( it );
     return *this;
 }
Exemple #9
0
void
ToolButton_Impl::paintEvent(QPaintEvent *event)
{
	QIcon icon = this->icon();
	
	if ((isFlat()) && (!icon.isNull())) {
		QPainter painter(this);
		QIcon::Mode mode;
		
		if (!isEnabled())
			mode = QIcon::Disabled;
		else if ((isDown()) || (isChecked()))
			mode = QIcon::Selected;
		else if (underMouse())
			mode = QIcon::Active;
		else
			mode = QIcon::Normal;
		
		QPixmap pixmap = icon.pixmap(size(), mode, QIcon::Off);
		painter.drawPixmap((size().width() - pixmap.size().width()) / 2, (size().height() - pixmap.size().height()) / 2, pixmap);
	}
	else {
		QToolButton::paintEvent(event);
	}
}
Exemple #10
0
void Chord::setText(const QString &chordText)
{
    this->chordText = chordText.trimmed();
    int indexOfInversionBar = this->chordText.indexOf("/");
    if (indexOfInversionBar > 0)
        bassInversion = this->chordText.right(this->chordText.size() - 1 - indexOfInversionBar);
    hasLettersAfterChordRoot = false;// min, maj, m, dim, add letters after chord root?
    int lettersBegin = (isFlat() || isSharp()) ? 2 : 1;
    int limit = hasBassInversion() ? indexOfInversionBar : this->chordText.length();
    int endOfLetters = lettersBegin;
    bool diminishedSymbol = chordText.size() > endOfLetters && chordText.at(endOfLetters) == QChar(
        0xc2b0);
    while (endOfLetters < limit
           && !(chordText.at(endOfLetters).isDigit() || diminishedSymbol
                || chordText.at(endOfLetters) == '(')) {
        endOfLetters++;
        hasLettersAfterChordRoot = true;
    }

    if (hasLettersAfterChordRoot)
        lettersAfterRoot = this->chordText.mid(lettersBegin, endOfLetters - lettersBegin);

    if (endOfLetters < limit) {
        int finalIndex = hasBassInversion() ? indexOfInversionBar : this->chordText.length();
        lastPart = this->chordText.mid(endOfLetters, finalIndex - endOfLetters);
    }
}
Exemple #11
0
// Create either a static or an uncounted string.
// Diffrence between static and uncounted is in the lifetime
// of the string. Static are alive for the lifetime of the process.
// Uncounted are not ref counted but will be deleted at some point.
ALWAYS_INLINE
StringData* StringData::MakeShared(StringSlice sl, bool trueStatic) {
  if (UNLIKELY(sl.len > StringData::MaxSize)) {
    throw_string_too_large(sl.len);
  }

  auto const cc = CapCode::ceil(sl.len);
  auto const need = cc.decode() + kCapOverhead;
  auto const sd = static_cast<StringData*>(
    trueStatic ? low_malloc(need) : malloc(need)
  );
  auto const data = reinterpret_cast<char*>(sd + 1);

  sd->m_data = data;
  auto const count = trueStatic ? StaticValue : UncountedValue;
  sd->m_hdr.init(cc, HeaderKind::String, count);
  sd->m_len = sl.len; // m_hash is computed soon.

  data[sl.len] = 0;
  auto const mcret = memcpy(data, sl.ptr, sl.len);
  auto const ret = reinterpret_cast<StringData*>(mcret) - 1;
  // Recalculating ret from mcret avoids a spill.
  ret->preCompute();                    // get m_hash right

  assert(ret == sd);
  assert(ret->isFlat());
  assert(trueStatic ? ret->isStatic() : ret->isUncounted());
  assert(ret->checkSane());
  return ret;
}
Exemple #12
0
 IteratorVisible& operator++()
 {
     Iterator& it = *this;
     assert( it != end() );
     it = isFlat() ? m_pRootTree->getNextLeaf( it ) :
                     m_pRootTree->getNextVisibleItem( it );
     return *this;
 }
//! [0]
void MyGroupBoxWidget::initStyleOption(QStyleOption *option) const
{
    QGraphicsWidget::initStyleOption(option);
    if (QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox *>(option)) {
        // Add group box specific state.
        box->flat = isFlat();
        ...
    }
Exemple #14
0
void ColorButton::paintEvent(QPaintEvent *ev)
{
	QPushButton::paintEvent(ev);
	QPainter p(this);

	// Get contents rectangle
	QStyleOptionButton opt;
	initStyleOption(&opt);
	QRect cRect;
	if(isFlat()) {
		// Fill the entire widget area
		cRect = rect();
	} else {
		// Only fill the contents area
		cRect =
			style()->subElementRect(QStyle::SE_PushButtonContents, &opt, this);
	}
	cRect.adjust(1, 1, -1, -1); // A little larger padding please

	// Colour fill
	if(m_color.alpha() == 255)
		p.fillRect(cRect, m_color);
	else {
		// Separate left and right rectangles
		QRect lRect = cRect;
		lRect.setWidth(lRect.width() / 2 + 1);
		QRect rRect = cRect;
		rRect.setLeft(lRect.right());

		// Fill the left with the solid colour
		p.fillRect(
			lRect, QColor(m_color.red(), m_color.green(), m_color.blue()));

		// Fill the right with the transparent colour on a checkerboard
		drawCheckerboard(p, rRect, 5, Qt::white, QColor(0xCC, 0xCC, 0xCC));
		p.fillRect(rRect, m_color);
	}

	// Sunken frame
	QStyleOptionFrame fOpt;
	fOpt.initFrom(this);
	fOpt.rect = cRect;
	fOpt.features = QStyleOptionFrame::None;
	fOpt.frameShape = QFrame::Panel;
	fOpt.lineWidth = 1;
	fOpt.midLineWidth = 0;
	fOpt.state |= QStyle::State_Sunken;
	style()->drawControl(QStyle::CE_ShapedFrame, &fOpt, &p, this);

	// Fade out when disabled
	if(!isEnabled()) {
		QBrush brush = palette().base();
		QColor col = brush.color();
		col.setAlpha(127); // 50% transparency
		brush.setColor(col);
		p.fillRect(cRect, brush);
	}
}
Exemple #15
0
StringData* StringData::Make(size_t reserveLen) {
  auto const sd = allocFlatForLenSmall(reserveLen);
  sd->setSize(0);

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #16
0
NEVER_INLINE
void StringData::releaseDataSlowPath() {
  assert(!isFlat());
  assert(isShared());
  assert(checkSane());

  sharedPayload()->shared->getHandle()->unreference();
  delist();
  MM().freeSmallSize(this, sizeof(StringData) + sizeof(SharedPayload));
}
Exemple #17
0
bool QcButton::hitButton( const QPoint & pos ) const
{
  // FIXME: This is a workaround for Qt Bug 15936:
  // incorrect QPushButton hit area.

  QMacStyle *macStyle = qobject_cast<QMacStyle *>(style());

  if( !macStyle || isFlat() )
    return QAbstractButton::hitButton(pos);
  else
    return QPushButton::hitButton(pos);
}
Exemple #18
0
/*! \internal */
QModelIndex KDPropertyModel::parent(const QModelIndex& index) const
{
  //qDebug() << "parent( " <<index<<" )";
  if(!index.isValid() || privateData(index) == d->rootproperty || d->parentOf(privateData(index)) == d->rootproperty )
    return QModelIndex();

  Q_ASSERT(privateData(index));

  /* Only sub-properties can have parents in flat mode */
  if( isFlat() && privateData(index)->isStandalone() ) return QModelIndex();

  return indexOf(d->parentOf(privateData(index)));
}
Exemple #19
0
// State transition from Mode::Shared to Mode::Flat.
StringData* StringData::escalate(size_t cap) {
  assert(isShared() && !isStatic() && cap >= m_len);

  auto const sd = allocFlatForLenSmall(cap);
  sd->m_lenAndHash = m_lenAndHash;
  auto const data = reinterpret_cast<char*>(sd + 1);
  *memcpy8(data, m_data, m_len) = 0;

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #20
0
StringData* StringData::shrinkImpl(size_t len) {
  assert(!isImmutable() && !hasMultipleRefs());
  assert(isFlat());
  assert(len <= capacity());

  auto const sd = allocFlatForLenSmall(len);
  sd->m_lenAndHash = len;
  auto const src = static_cast<void*>(this + 1);
  auto const dst = static_cast<void*>(sd + 1);
  *memcpy8(dst, src, len) = 0;

  assert(sd->checkSane());
  return sd;
}
Exemple #21
0
StringData* StringData::shrinkImpl(size_t len) {
  assert(!isImmutable() && !hasMultipleRefs());
  assert(isFlat());
  assert(len <= capacity());

  auto const sd = Make(len);
  sd->m_len = len;
  auto const src = slice();
  auto const dst = sd->mutableData();
  *memcpy8(dst, src.ptr, len) = 0;

  assert(sd->checkSane());
  return sd;
}
Exemple #22
0
StringData* StringData::Make(size_t reserveLen) {
  auto const allocRet = allocFlatForLen(reserveLen);
  auto const sd       = allocRet.first;
  auto const capCode  = allocRet.second;
  auto const data     = reinterpret_cast<char*>(sd + 1);

  data[0] = 0;
  sd->m_data        = data;
  sd->m_capAndCount = HeaderKind::String << 24 | capCode; // count=0
  sd->m_lenAndHash  = 0; // len=hash=0

  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #23
0
StringData* StringData::Make(StringSlice r1, StringSlice r2) {
  auto const len = r1.len + r2.len;
  auto const sd = allocFlatForLenSmall(len);
  sd->m_lenAndHash = len; // hash=0

  auto const data = reinterpret_cast<char*>(sd + 1);
  memcpy(data, r1.ptr, r1.len);
  memcpy(data + r1.len, r2.ptr, r2.len);
  data[len] = 0;

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #24
0
StringData* StringData::Make(folly::StringPiece r1, folly::StringPiece r2) {
  auto const len = r1.size() + r2.size();
  auto const sd = allocFlatForLenSmall(len);
  sd->m_lenAndHash = len; // hash=0

  auto const data = reinterpret_cast<char*>(sd + 1);
  memcpy(data,             r1.data(), r1.size());
  memcpy(data + r1.size(), r2.data(), r2.size());
  data[len] = 0;

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #25
0
StringData* StringData::Make(size_t reserveLen) {
  auto const allocRet = allocFlatForLen(reserveLen);
  auto const sd       = allocRet.first;
  auto const cc       = allocRet.second;
  auto const data     = reinterpret_cast<char*>(sd + 1);

  data[0] = 0;
  sd->m_data        = data;
  sd->m_hdr.init(cc, HeaderKind::String, 1);
  sd->m_lenAndHash  = 0; // len=hash=0

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #26
0
StringData* StringData::Make(const StringData* s1, const StringData* s2) {
  auto const len = s1->m_len + s2->m_len;
  // `memcpy8()' could overrun the buffer by at most 7 bytes, so we allocate 6
  // more bytes here, which (together with the trailing 0) makes it safe.
  auto const sd = allocFlatForLenSmall(len + 6);
  sd->m_lenAndHash = len; // hash=0

  auto const data = reinterpret_cast<char*>(sd + 1);
  auto const next = memcpy8(data, s1->m_data, s1->m_len);
  *memcpy8(next, s2->m_data, s2->m_len) = 0;

  assert(sd->getCount() == 1);
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
/*! \reimp */
bool QPushButton::hitButton(const QPoint &pos) const
{
    // This is only required if we are using the native style, so check that first.
        QMacStyle *macStyle = qobject_cast<QMacStyle *>(style());
    // If this is a flat button we just bail out.
    if(isFlat() || (0 == macStyle))
        return QAbstractButton::hitButton(pos);
    // Now that we know we are using the native style, let's proceed.
    Q_D(const QPushButton);
    QPushButtonPrivate *nonConst = const_cast<QPushButtonPrivate *>(d);
    // In OSX buttons are round, which causes the hit method to be special.
    // We cannot simply relay on detecting if something is inside the rect or not,
    // we need to check if it is inside the "rounded area" or not. A point might
    // be inside the rect but not inside the rounded area.
    // Notice this method is only reimplemented for OSX.
    return nonConst->hitButton(pos);
}
Exemple #28
0
/*! \internal */
int KDPropertyModel::rowCount(const QModelIndex& parent) const
{
  if (!parent.isValid()) {
    if( isFlat() ) return d->countAll(d->rootproperty);
    else return d->rootproperty->propertyCount();
  }

  if (KDPropertyInterface *p = privateData(parent)) {
    return (p->isContainer())
      ? static_cast<KDPropertyGroupInterface*>(p)->propertyCount()
      : 0;
  }

  return (d->rootproperty->isContainer() )
    ? static_cast<KDPropertyGroupInterface*>(d->rootproperty)->propertyCount()
    : 0;
}
Exemple #29
0
StringData* StringData::Make(StringSlice r1, StringSlice r2,
                             StringSlice r3) {
  auto const len = r1.len + r2.len + r3.len;
  auto const sd = allocFlatForLenSmall(len);
  sd->m_lenAndHash  = len; // hash=0

  char* p = reinterpret_cast<char*>(sd + 1);
  p = static_cast<char*>(memcpy(p, r1.ptr, r1.len));
  p = static_cast<char*>(memcpy(p + r1.len, r2.ptr, r2.len));
  p = static_cast<char*>(memcpy(p + r2.len, r3.ptr, r3.len));
  p[r3.len] = 0;

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}
Exemple #30
0
StringData* StringData::Make(folly::StringPiece r1, folly::StringPiece r2,
                             folly::StringPiece r3) {
  auto const len = r1.size() + r2.size() + r3.size();
  auto const sd = allocFlatForLenSmall(len);
  sd->m_lenAndHash  = len; // hash=0

  auto p = reinterpret_cast<char*>(sd + 1);
  p = static_cast<char*>(memcpy(p,             r1.data(), r1.size()));
  p = static_cast<char*>(memcpy(p + r1.size(), r2.data(), r2.size()));
  p = static_cast<char*>(memcpy(p + r2.size(), r3.data(), r3.size()));
  p[r3.size()] = 0;

  assert(sd->hasExactlyOneRef());
  assert(sd->isFlat());
  assert(sd->checkSane());
  return sd;
}