View Issue Details

IDProjectCategoryView StatusLast Update
0016172ScribusInternalpublic2020-07-20 13:05
Reporterale Assigned To 
PrioritynormalSeverityminorReproducibilityN/A
Status newResolutionopen 
Summary0016172: provide a an abstraction to check if a specific type of frame is selected
Descriptioncurrently, if i want to make sure that one text frame is selected i need to do:

    if (!HaveDoc)
        return;
    if (doc->m_Selection->count() != 1)
        return;
    if (doc->masterPageMode())
        return;
    if (doc->appMode != modeEdit)
        return;

    PageItem* currItem = doc->m_Selection->itemAt(0);
    if (!currItem->isTextFrame())
        return;


it would be nice to have the high level function:

    item = doc->getSingleTextFrame()
    if (!item)
        return


they will return nullptr if the conditions in the name of the function are not met. (it would be even better if it could return a "NoItem" object)

another function would be

    item = doc->getSingleTextFrameFromPage()

which would exclude items from master pages.

for this to work, we should have a special doc that is a NoDoc (doc should never be a nullptr)

the goal is to avoid functions like ScribusMainWindow::insertMark(MarkType mType) that hide what a dialog really does, because of the boilerplate.
TagsNo tags attached.
PatchNo

Activities

ale

2020-07-20 13:05

manager   ~0047858

after PageItem* ScribusDoc::getItemFromName() :

    /** @brief return the currently selected item from the page or master page */
    PageItem* getSinglePageItem() const;
    /** @brief return the currently selected item on the page */
    PageItem* getSinglePageItemFromPage() const;
    /** @brief return the currently selected text frame on the page or master page*/
    PageItem_TextFrame* getSingleTextFrame() const;
    /** @brief return the currently selected text frame on the page */
    PageItem_TextFrame* getSingleTextFrameFromPage() const;


PageItem* ScribusDoc::getSinglePageItem() const
{
    if (m_Selection->count() != 1)
        return nullptr;
    return m_Selection->itemAt(0);
}

PageItem* ScribusDoc::getSinglePageItemFromPage() const
{
    if (masterPageMode())
        return nullptr;
    return getSinglePageItem();
}

PageItem_TextFrame* ScribusDoc::getSingleTextFrame() const
{
    auto currItem = getSinglePageItem();
    if (!currItem)
        return nullptr;
    if (!currItem->isTextFrame())
        return nullptr;
    return currItem->asTextFrame();
}

PageItem_TextFrame* ScribusDoc::getSingleTextFrameFromPage() const
{
    if (masterPageMode())
        return nullptr;
    return getSingleTextFrame();
}

Issue History

Date Modified Username Field Change
2020-07-19 10:24 ale New Issue
2020-07-20 13:05 ale Note Added: 0047858