Пример #1
0
void CanvasBase::validateSelection()
{
    register Sheet * const sheet = activeSheet();
    if (!sheet)
        return;
#if 0
XXX TODO
    if (selection()->isSingular()) {
        const Cell cell = Cell(sheet, selection()->marker()).masterCell();
        Validity validity = cell.validity();
        if (validity.displayValidationInformation()) {
            const QString title = validity.titleInfo();
            QString message = validity.messageInfo();
            if (title.isEmpty() && message.isEmpty())
                return;

            if (!d->validationInfo) {
                d->validationInfo = new QLabel(this);
                QPalette palette = d->validationInfo->palette();
                palette.setBrush(QPalette::Window, palette.toolTipBase());
                palette.setBrush(QPalette::WindowText, palette.toolTipText());
                d->validationInfo->setPalette(palette);
//                 d->validationInfo->setWindowFlags(Qt::ToolTip);
                d->validationInfo->setFrameShape(QFrame::Box);
                d->validationInfo->setAlignment(Qt::AlignVCenter);
                d->validationInfo->setTextFormat(Qt::RichText);
            }

            QString resultText("<html><body>");
            if (!title.isEmpty()) {
                resultText += "<h2>" + title + "</h2>";
            }
            if (!message.isEmpty()) {
                message.replace(QChar('\n'), QString("<br>"));
                resultText += "<p>" + message + "</p>";
            }
            resultText += "</body></html>";
            d->validationInfo->setText(resultText);

            const double xpos = sheet->columnPosition(cell.column()) + cell.width();
            const double ypos = sheet->rowPosition(cell.row()) + cell.height();
            const QPointF position = QPointF(xpos, ypos) - offset();
            const QPoint viewPosition = viewConverter()->documentToView(position).toPoint();
            d->validationInfo->move(/*mapToGlobal*/(viewPosition)); // Qt::ToolTip!
            d->validationInfo->show();
        } else {
            delete d->validationInfo;
            d->validationInfo = 0;
        }
    } else {
        delete d->validationInfo;
        d->validationInfo = 0;
    }
#endif
}
Пример #2
0
void ValidityDialog::init()
{
    const Map *const map = m_selection->activeSheet()->map();
    const CalculationSettings *settings = map->calculationSettings();
    const KLocale* locale = settings->locale();
    Validity validity = Cell(m_selection->activeSheet(), m_selection->marker()).validity();
    if (!validity.isEmpty()) {
        message->setPlainText(validity.message());
        title->setText(validity.title());
        QString tmp;
        switch (validity.restriction()) {
        case Validity::None:
            chooseType->setCurrentIndex(0);
            break;
        case Validity::Number:
            chooseType->setCurrentIndex(1);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::Integer:
            chooseType->setCurrentIndex(2);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::TextLength:
            chooseType->setCurrentIndex(6);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::Text:
            chooseType->setCurrentIndex(3);
            break;
        case Validity::Date:
            chooseType->setCurrentIndex(4);
            val_min->setText(locale->formatDate(validity.minimumValue().asDate(settings), KLocale::ShortDate));
            if (validity.condition() >= 5)
                val_max->setText(locale->formatDate(validity.maximumValue().asDate(settings), KLocale::ShortDate));
            break;
        case Validity::Time:
            chooseType->setCurrentIndex(5);
            val_min->setText(locale->formatTime(validity.minimumValue().asTime(settings), true));
            if (validity.condition() >= 5)
                val_max->setText(locale->formatTime(validity.maximumValue().asTime(settings), true));
            break;
        case Validity::List: {
            chooseType->setCurrentIndex(7);
            const QStringList lst = validity.validityList();
            QString tmp;
            for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
                tmp += (*it) + '\n';
            }
            validityList->setText(tmp);
        }
        break;
        default :
            chooseType->setCurrentIndex(0);
            break;
        }
        chooseAction->setCurrentIndex(chooseAction->findData(QVariant::fromValue(validity.action())));
        choose->setCurrentIndex(choose->findData(QVariant::fromValue(validity.condition())));
        displayMessage->setChecked(validity.displayMessage());
        allowEmptyCell->setChecked(validity.allowEmptyCell());
        titleHelp->setText(validity.titleInfo());
        messageHelp->setPlainText(validity.messageInfo());
        displayHelp->setChecked(validity.displayValidationInformation());
    }
    changeIndexType(chooseType->currentIndex()) ;
    changeIndexCond(choose->currentIndex()) ;
}