void Button::placeButton()
{
    QTableView* table = qobject_cast<QTableView*>(this->parent());
    if (!table)
    {
        setVisible(false);
        return ;
    }

    if (_point.isNull())
    {
        QSize s = table->viewport()->size();
        //qDebug() << s;
        _point = QPoint(s.width(),s.height());
    }

    QAbstractItemModel* model = table->model();
    if (!model)
        return;

    int n,m,bsize1,bsize2,offset1,offset2,point1,point2;
    getSizes(table,model,&m,&n,&bsize1,&bsize2,&point1,&point2,&offset1,&offset2);

    int coord1;
    int coord2 = 0;

    int sizes[m];
    if (_orientation == Qt::Horizontal)
    {
        for (int i=0;i<m;i++)
            sizes[i] = table->columnWidth(i);
        for (int i=0;i<n;i++)
            coord2 += table->rowHeight(i);
    }
    else
    {
        for (int i=0;i<m;i++)
            sizes[i] = table->rowHeight(i);
        for (int i=0;i<n;i++)
            coord2 += table->columnWidth(i);
    }

    if (_type == InsertRemove::Insert)
        nearestBorder(_policy,point1+offset1,sizes,m,&_modelIndex,&coord1);
    else // _type == InsertRemove::Remove
        nearestMiddle(_policy,point1+offset1,sizes,m,&_modelIndex,&coord1);


    coord1 -= bsize1 / 2;

    QSize vp = usefulWidgetSize(table);
    QPoint sh = table->viewport()->mapToParent(QPoint(0,0)); //насколько viewport меньше table

    if (_orientation == Qt::Horizontal)
    {
        if (coord2 - offset2 + bsize2 + sh.y() > vp.height())
            coord2 = vp.height() - bsize2 + offset2 - sh.y();
    }
    else
    {
        if (coord2 - offset2 + bsize2 + sh.x() > vp.width())
            coord2 = vp.width() - bsize2 + offset2 - sh.x();
    }

    if (_orientation == Qt::Horizontal)
    {
        QPoint p = table->viewport()->mapToParent(QPoint(coord1 - offset1,coord2 - offset2));
        setGeometry(QRect(p,size()));
    }
    else
    {
        QPoint p = table->viewport()->mapToParent(QPoint(coord2 - offset2,coord1 - offset1));
        setGeometry(QRect(p,size()));
    }

    if (_type == InsertRemove::Insert)
    {
        setVisible(_modelIndex>=0);
    }
    else
    {
        setVisible((_policy & InsertRemove::RemoveAllowed) && (_modelIndex>-1));
    }

}